[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if-let/if-let*/and-let/..

From: Michael Heerdegen
Subject: Re: if-let/if-let*/and-let/..
Date: Thu, 22 Feb 2018 02:08:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.91 (gnu/linux)

Stefan Monnier <address@hidden> writes:

> >  (if-let* (x (y 1) (z 2)) "dogs" "cats") => "cats"
> Same as the first case above, we could/should detect this case during
> macro-expansion since this is not of the form (VAR EXP) but (VAR EXP
> EXP).

I understand now what the problem is.

Mark had implemented and-let* as in srfi-2:


(scroll to "Specification")

which interprets a (bound) symbol in the binding spec as a boolean.

Noam then had asked for making if-let's binding SPEC compatible with
that of the new and-let* - but the single-binding case of those was
incompatible with that, so foo-let* were born breaking with the single
binding case, and at that time we wanted to introduce these names
anyway.  foo-let were then reimplemented based on foo-let* but made
still supporting the single-binding case for backward compatibility as
special case, and also marked obsolete to not have two versions of the
very same thing.

That treatment of a single SYMBOL in the SPEC is redundant AFAIK (in the
SRFI2 and in master) since it can also be written as (SYMBOL).  If we
sacrifice the absolute rigid compatibility with SRFI2, we can treat the
binding SPEC, as Stefan suggested, like

#+begin_src emacs-lisp
(pcase spec
    (`(,(pred symbolp) . ,rest)
     (pcase rest
       (`(,_) (cl-callf list spec)) ;the single binding syntax
       (_     (signal 'error (list "if-let: Bad binding spec" spec))))))

being slightly backward incompatible since

| 4612b2a2b37026bef5a9b8e92878a15dabb9b261
| Parent:     c87331a1c0 Merge branch 'master' of 
| Merged:     emacs-25
| Containing: emacs-26 master
| Follows:    emacs-25.1 (130022)
| Implement and-let*


reply via email to

[Prev in Thread] Current Thread [Next in Thread]