Next: , Previous: SRFI-26, Up: SRFI Support


6.4.17 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>