Warning: This is the manual of the legacy Guile 2.2 series. You may want to read the manual of the current stable series instead.

Next: , Previous: , Up: SRFI Support   [Contents][Index]


7.5.22 SRFI-31 - A special form ‘rec’ for recursive evaluation

SRFI-31 defines a special form that can be used to create self-referential expressions more conveniently. The syntax is as follows:

<rec expression> --> (rec <variable> <expression>)
<rec expression> --> (rec (<variable>+) <body>)

The first syntax can be used to create self-referential expressions, for example:

  guile> (define tmp (rec ones (cons 1 (delay ones))))

The second syntax can be used to create anonymous recursive functions:

  guile> (define tmp (rec (display-n item n)
                       (if (positive? n)
                           (begin (display n) (display-n (- n 1))))))
  guile> (tmp 42 3)
  424242
  guile>