In 'The Scheme Programming Language' what is this strange 'let' form in '(reverse)'?

45 views Asked by At

From The Scheme Programming Language, written by R. Kent Dybvig, I see this definition of reverse:

procedure: (reverse list)
returns: a new list containing the elements of list in reverse order
libraries: (rnrs base), (rnrs)

reverse may be defined without error checks as follows.

(define reverse
  (lambda (ls)
    (let rev ([ls ls] [new '()])
      (if (null? ls)
          new
          (rev (cdr ls) (cons (car ls) new))))))

(reverse '()) <graphic> ()
(reverse '(a b c)) <graphic> (c b a)

What is going on with rev in this line?

(let rev ([ls ls] [new '()])

My understanding from the definition of let indicates that there can be no gap between the keyword let and the list of local bindings. So what is rev doing here between let and the bindings list?

1

There are 1 answers

0
durandaltheta On

Hmm, I repent of my hastiness, looks like there's a link in there to a form called named let. Carry on everyone, crisis averted.