all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 59786@debbugs.gnu.org
Subject: bug#59786: Allowing arbitrary expressions in cl-labels
Date: Tue, 29 Oct 2024 10:51:26 -0400	[thread overview]
Message-ID: <jwvy127x9aq.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <874j4vw0tq.fsf@web.de> (Michael Heerdegen's message of "Tue, 29 Oct 2024 13:28:01 +0100")

>> -forms of the function body.  FUNC is defined in any BODY, as well
>> +forms of the function body.  FUNC is defined in any BODY or EXP, as well
>                                                             ^^^^^^
> This is unfortunately not correct, e.g.
>
> (cl-labels ((even (if (odd 5)
>                       (lambda (x) (if (= x 0) t (odd (1- x))))
>                     #'ignore))
>             (odd  (lambda (x) (if (= x 0) nil (even (1- x))))))
>          (list (even 42) (odd 42)))
>
> ~~> funcall: Symbol's function definition is void: nil

This is normal.  Same happens with

    (letrec ((even (if (funcall odd 5)
                          (lambda (x) (if (= x 0) t (funcall odd (1- x))))
                        #'ignore))
             (odd  (lambda (x) (if (= x 0) nil (funcall even (1- x))))))
      (list (funcall even 42) (funcall odd 42)))

This construct is used for recursive functions, not recursive expressions.
Recursive expressions can't be handled without going for some kind of
lazy evaluation strategy which is quite difficult to pull off in a macro.

> Dunno how useful it is at all that the EXPs can use any of the defined
> functions.

As mentioned (admittedly, a long time ago), the purpose is to *compute*
the recursive functions, e.g.

    (cl-labels ((f1 (if (fboundp 'foo)
                        (lambda (x) ... (f1 ..) ...)
                      (lambda (x) ... (f1 ..) ...))))
      ...)

My original motivation is to define recursive oclosures (for PEG):

    (cl-labels ((f1 (oclosure-lambda ... (f1 ..) ...)))
      ...)


- Stefan






  reply	other threads:[~2024-10-29 14:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 19:44 bug#59786: Allowing arbitrary expressions in cl-labels Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 20:29 ` Drew Adams
2023-01-13 13:47 ` Michael Heerdegen
2024-10-28  3:07   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 12:28     ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-29 14:51       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-10-29 15:49         ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-15 17:11 ` Sean Whitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvy127x9aq.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=59786@debbugs.gnu.org \
    --cc=michael_heerdegen@web.de \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.