brj
brj

Reputation: 373

What does `rec` mean in Scheme 84

I was reading Friedman and Wand's "Reification: Reflection Without Metaphysics" and it uses the following rec syntax which I do not know:

(define <simple>                            
  (lambda (fun)
    (lambda (e r k)
      ((rec loop ; <--- What is rec here?
            (lambda (e k)
              (if (null? e) (k nil)
                ((denotation (first
                               e))
                 r
                 (lambda (v)
                   (loop
                     (rest e)
                     (lambda (w)
                       (k (cons v w)))))))))
       (lambda (v*) (fun v* k))))))

The paper says they use Scheme 84, but I couldn't find that reference manual on schemers.org (or on google for that matter). Could someone please explain this rec syntax? A few simple examples that use rec would be appreciated as well.

Upvotes: 2

Views: 129

Answers (1)

brj
brj

Reputation: 373

Found what it means on Chez Scheme reference here. It is a macro that expands as follows:

(define-syntax rec
  (syntax-rules ()
    [(_ x e) (letrec ((x e)) x)]))

For example,

(rec last-of (lambda (l)
               (cond
                 [(null? l) (error "List too small")]
                 [(= (length l) 1) (car l)]
                 [else (last-of (cdr l))])))

would return the procedure for finding the last element of a list.

Upvotes: 2

Related Questions