racket/collects/scribblings/guide/named-let.scrbl
Matthew Flatt 1477c7ec1b doc work
svn: r6685
2007-06-18 06:34:41 +00:00

40 lines
1.1 KiB
Racket

#reader(lib "docreader.ss" "scribble")
@require[(lib "manual.ss" "scribble")]
@require[(lib "eval.ss" "scribble")]
@require["guide-utils.ss"]
@title{Named @scheme[let]}
A named @scheme[let] is an iteration and recursion form. It uses the
same syntactic keyword @scheme[let] as for local binding, but an
identifier after the @scheme[let] (instead of an immediate open
parenthesis) triggers a different parsing.
@specform[
(let _proc-id ([_arg-id _init-expr] ...)
_body ...+)
]
A named @scheme[let] form is equivalent to
@schemeblock[
(letrec ([_proc-id (lambda (_arg-id ...)
_body ...+)])
(_proc-id _init-expr ...))
]
That is, a named @scheme[let] binds a function identifier that is
visible only in the function's body, and it implicitly calls the
function with the values of some initial expressions.
@defexamples[
(define (duplicate pos lst)
(let dup ([i 0]
[lst lst])
(cond
[(= i pos) (cons (car lst) lst)]
[else (cons (car lst) (dup (+ i 1) (cdr lst)))])))
(duplicate 1 (list "apple" "cheese burger!" "banana"))
]