DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(guile.info.gz) Lambda Alternatives

Info Catalog (guile.info.gz) Creating a Procedure (guile.info.gz) About Procedures
 
 14.2.4 Lambda Alternatives
 --------------------------
 
 Since it is so common in Scheme programs to want to create a procedure
 and then store it in a variable, there is an alternative form of the
 `define' syntax that allows you to do just that.
 
    A `define' expression of the form
 
      (define (NAME [ARG1 [ARG2 ...]])
        EXPRESSION ...)
 
 is exactly equivalent to the longer form
 
      (define NAME
        (lambda ([ARG1 [ARG2 ...]])
          EXPRESSION ...))
 
    So, for example, the definition of `make-combined-string' in the
 previous subsection could equally be written:
 
      (define (make-combined-string name address)
        (string-append "Name=" name ":Address=" address))
 
    This kind of procedure definition creates a procedure that requires
 exactly the expected number of arguments.  There are two further forms
 of the `lambda' expression, which create a procedure that can accept a
 variable number of arguments:
 
      (lambda (ARG1 ... . ARGS) EXPRESSION ...)
 
      (lambda ARGS EXPRESSION ...)
 
 The corresponding forms of the alternative `define' syntax are:
 
      (define (NAME ARG1 ... . ARGS) EXPRESSION ...)
 
      (define (NAME . ARGS) EXPRESSION ...)
 
 For details on how these forms work, see  Lambda.
 
    (It could be argued that the alternative `define' forms are rather
 confusing, especially for newcomers to the Scheme language, as they hide
 both the role of `lambda' and the fact that procedures are values that
 are stored in variables in the some way as any other kind of value.  On
 the other hand, they are very convenient, and they are also a good
 example of another of Scheme's powerful features: the ability to specify
 arbitrary syntactic transformations at run time, which can be applied to
 subsequently read input.)
 
Info Catalog (guile.info.gz) Creating a Procedure (guile.info.gz) About Procedures
automatically generated byinfo2html