schemeracket

Anonymous lambdas directly referring to themselves


Does Scheme or do any dialects of scheme have a kind of "self" operator so that anonymous lambdas can recur on themselves without doing something like a Y-combinator or being named in a letrec etc.

Something like:

(lambda (n)
   (cond
     ((= n 0) 1)
     (else (* n (self (- n 1)))))))

Solution

  • No. The trouble with the "current lambda" approach is that Scheme has many hidden lambdas. For example:

    To require the programmer to know what the innermost lambda is would break encapsulation, in that you'd have to know where all the hidden lambdas are, and macro writers can no longer use lambdas as a way to create a new scope.

    All-round lose, if you ask me.