## Procedures
(lambda
{formals} {body}
)
syntax
(lambda (x) (+ x x)) ==> a procedure
((lambda (x) (+ x x)) 4) ==> 8
(define reverse-subtract
(lambda (x y) (- y x)))
(reverse-subtract 7 10) i ==> 3
(define add4
(let ((x 4))
(lambda (y) (+ x y))))
(add4 6) ==> 10
Formals have one of the following forms: -
`({variable1} ...)` : The procedure takes a fixed number of arguments; when the procedure is called, the arguments will be stored in fresh locations that are bound to the corresponding variables. -
`{variable}` : The procedure takes any number of arguments; when the procedure is called, the sequence of actual arguments is converted into a newly allocated list, and the list is stored in a fresh location that is bound to variable. -
`({variable` : If a space-delimited period precedes the last variable, then the procedure takes_{1}} ... {variable_{n}} . {variable_{n+1}})`n` or more arguments, where`n` is the number of formal arguments before the period (it is an error if there is not at least one). The value stored in the binding of the last variable will be a newly allocated list of the actual arguments left over after all the other actual arguments have been matched up against the other formal arguments.
It is an error for a variable to appear more than once in formals.
((lambda x x) 3 4 5 6) ==> (3 4 5 6)
((lambda (x y . z) z)
3 4 5 6) ==> (5 6)
Each procedure created as the result of evaluating a |

husk-scheme online documentation rev 3.2 (2021.03.04)