define -- r7rs Definition syntax;
Syntax keywords:
variable: identifier;argument: identifier;argument-rest: identifier;expression: expression;Syntax variants:
(_ variable expression)(_ (variable) expression |...|)(_ (variable argument |...|) expression |...|)(_ (variable argument |...| . argument-rest) expression |...|)(_ (variable . argument-rest) expression |...|)scheme:base -- (scheme base);scheme -- (scheme);(define <variable> <expression>) (define (<variable> <formals>) <body>)Variable definitions
A variable definition binds one or more identifiers and specifies an initial value for each of them. The simplest kind of variable definition takes one of the following forms:
(define <variable> <expression>)
(define (<variable> <formals>) <body>)
<Formals>are either a sequence of zero or more variables, or a sequence of one or more variables followed by a space-delimited period and another variable (as in a lambda expression). This form is equivalent to(define <variable> (lambda (<formals>) <body>))
(define (<variable> . <formal>) <body>)
<Formal>is a single variable. This form is equivalent to(define <variable> (lambda <formal> <body>))Top level definitions
At the outermost level of a program, a definition
(define <variable> <expression>)has essentially the same effect as the assignment expression
(set! <variable> <expression>)if
<variable>is bound to a non-syntax value. However, if<variable>is not bound, or is a syntactic keyword, then the definition will bind<variable>to a new location before performing the assignment, whereas it would be an error to perform aset!on an unbound variable.(define add3 (lambda (x) (+ x 3))) (add3 3) ===> 6 (define first car) (first '(1 2)) ===> 1
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.