Named lambda? Artyom Bologov (05 Aug 2026 23:36 UTC)
Re: Named lambda? Vladimir Nikishkin (05 Aug 2026 23:49 UTC)
Re: Named lambda? Peter McGoron (06 Aug 2026 00:03 UTC)
Re: Named lambda? Shawn Wagner (06 Aug 2026 00:04 UTC)
Re: Named lambda? Alex Shinn (06 Aug 2026 00:42 UTC)
Re: Named lambda? Artyom Bologov (06 Aug 2026 00:47 UTC)
Re: Named lambda? Wolfgang Corcoran-Mathe (06 Aug 2026 01:23 UTC)

Re: Named lambda? Peter McGoron 06 Aug 2026 00:00 UTC

There is `rec`, which is based off of a form called named-lambda:

https://srfi.schemers.org/srfi-31/srfi-31.html

This doesn't modify the syntax of lambda, it is a new form. It has made
its way into the draft R7RS-Large:

https://r7rs.org/large/fascicles/proc/1/#rec

If one wants to attach a name to a procedure, one can use procedure
properties:

https://srfi.schemers.org/srfi-259/srfi-259.html

This is not in the R7RS-Large yet, but hopefully it will be.

     (import (rename (scheme base) (define %define)) (srfi 259))

     (define-procedure-tag named-procedure named-procedure? procedure-name)

     (define-syntax rec
       (syntax-rules ()
         ((_ (name . formals) body1 body2 ...)
          (letrec
              ((name (named-procedure (quote name)
                                      (lambda formals
                                        body1 body2 ...))))
            name))
         ((_ variable expression)    ; clause not relevant to procedures
          (letrec ((variable expression))
            variable))))

     (define-syntax define
       (syntax-rules ()
         ((_ (name . formals) body1 body2 ...)
          (%define name
            (named-procedure (lambda formals body1 body2 ...))))
         ((_ name expr) (%define name expr))))

     (procedure-name
      (rec (fact n)
        (if (zero? n)
            1
            (* n (fact (- n 1)))))) ⇒ fact

     (define (fact n)
       (if (zero? n)
           1
           (* n (fact (- n 1)))))
     (procedure-name fact) ⇒ fact

-- Peter McGoron