apply(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… apply(3scm) β€” call a procedure with a list of arguments

okay bestie, welcome to apply(3scm), straight out of the Scheme Programmer's Manual ✨. This one's lowkey iconic β€” it's the "I have my args in a list, don't @ me" procedure. Let's get into it 🫢


πŸ¦‹ LIBRARY

import it from whichever flavour of Scheme you're living in, queen:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

🌸 SYNOPSIS

(apply procedure obj ... pair)

that's the whole vibe. no notes πŸ’…

πŸ’– DESCRIPTION

so apply calls procedure β€” but instead of you handing it arguments one by one like a peasant, it takes the elements of this list:

(append (list obj ...) pair)

and feeds those in as the actual arguments. that's it. that's the whole procedure. obj ... is however many objects you wanna front-load, and pair is the list that gets tacked on the end πŸŽ€

⭐ RETURN VALUES

apply hands you back exactly the values that procedure returned when it got called in the manner above. no extra seasoning, no middleman nonsense β€” just whatever came out πŸ”₯

πŸŽ€ EXAMPLES

(nothing here in the original, bestie β€” the EXAMPLES section is empty. the real examples live down in APPLICATION USAGE, keep scrolling πŸ‘‡)

✨ APPLICATION USAGE

okay so when do you actually reach for this? main character use case: you need to call a procedure but the set of arguments you're giving it isn't known ahead of time β€” so you can't just type them out. that's apply's whole moment πŸ™Œ

it can also do a cute lil "fold" over a list of items, but only if procedure can take an arbitrary number of arguments. like this:

(apply + (list 1 2 3 4)) => 10

ate. no cap. πŸ’€

πŸ’œ RATIONALE

(empty in the original! a mysterious queen. nothing to report πŸ•΅οΈβ€β™€οΈ)

🌈 COMPATIBILITY

(also empty β€” dry text, this section. we move πŸ’…)

πŸ‘‘ ERRORS

this procedure can raise exceptions with these condition types, so pay attention:

  • &assertion (R6RS) β€” the wrong number of arguments got passed, or an argument was outside its domain. basically: you fumbled the args 😭
  • R7RS β€” the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. yes, catastrophically. not a drill πŸ’€πŸ”₯

🧚 SEE ALSO

(empty in the original β€” nothing to point you at, sadly πŸ₯²)

🌸 STANDARDS

it's standing on business across all of these: R4RS, IEEE Scheme, R5RS, R6RS, R7RS. five for five, periodt πŸ‘‘

πŸ“ HISTORY

(empty β€” the lore is lost to time πŸ™ˆ)

🫢 AUTHORS

this page is part of the scheme-manpages project! it includes materials from the RnRS documents. more info lives at https://github.com/schemedoc/manpages/ β€” go show them love πŸ’–


and that's the whole page, bestie πŸ¦‹ this was apply(3scm), dated 2022-02-01, from the Scheme Programmer's Manual β€” mwah, go call some procedures πŸ’…βœ¨

πŸ“¦ where this page comes from