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? Wolfgang Corcoran-Mathe 06 Aug 2026 01:23 UTC

Artyom,

On 2026-08-06 04:46 +0400, Artyom Bologov wrote:
> Thanks for the recommendations, these are all valid approaches and I no
> longer feel the necessity for an uh… unnecessary SRFI!

There may still be room for improvement here.  ‘rec’ does the job, but
its purpose is to define recursive procedures.  Thus the name given
with ‘rec’ is bound in the body of the procedure, which is irrelevant
if all you want is a name for error-reporting purposes.

I notice that some Schemes extract names from ‘let’ bindings for error
reporting, e.g. chibi:

    > (let ((foo (lambda (x)
        (/ 4 x))))
    ERROR in foo on line 1: divide by zero

In this case, of course, the procedure has a name that isn’t bound in
its body.  It seems you can abuse chibi’s behavior to create named,
non-recursive procedures:

    (define-syntax named
      (syntax-rules ()
        ((named name proc)
         (let ((name proc)) name))))

    > ((named foo (lambda (x) (/ 4 x))) 0)
    ERROR in foo on line 5: divide by zero

Obviously this is implementation-dependent.  Something like Peter’s
procedure-property solution seems much better.

--
Wolfgang Corcoran-Mathe  <xxxxxx@sigwinch.xyz>