GNU bug report logs - #59786
Allowing arbitrary expressions in cl-labels

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Fri, 2 Dec 2022 19:45:01 UTC

Severity: wishlist

Tags: patch

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 59786 <at> debbugs.gnu.org
Subject: bug#59786: Allowing arbitrary expressions in cl-labels
Date: Tue, 29 Oct 2024 10:51:26 -0400
>> -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





This bug report was last modified 246 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.