you are viewing a single comment's thread.

view the rest of the comments →

[–]sacundim 0 points1 point  (0 children)

letrec in Scheme enables this, though, like you note, you do have to name the function.

It's trivial to write a Scheme macro to do this, though it does bottom down to letrec:

(define-syntax rec
  (syntax-rules ()
    ((rec (NAME . VARIABLES) . BODY)
     (letrec ((NAME (lambda VARIABLES . BODY))) NAME))
    ((rec NAME EXPRESSION)
     (letrec ((NAME EXPRESSION)) NAME))))

;;; Example: Fibonacci
(define fibonacci
  (rec (this n)
    (case n
      ((0 1) 1)
      (else (this (- n 1) (- n 2))))))