help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Quick pcase question


From: Phillip Lord
Subject: Re: Quick pcase question
Date: Wed, 02 Mar 2016 17:25:30 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> But the fact is that pcase is (very complex and very useful) syntax
>> sugar. I just wrote a pcase clause that looks like:
>>
>> `((,(and f-string (pred stringp)) . ,(and class (pred symbolp)))
>> . ,(and regexp (pred stringp)))
>>
>> And that's kind of awful. The whole point of pcase should be concision,
>> but that looks pretty terrible.
>
> :-P
>
> Maybe separate the testing and the binding operations, like:

What about this?

(pcase tst
  ((and
    `(symbolla . ,x)
    (guard (stringp x)))
   (message "cdr is a string: %s" x)))

It separates out the list destructure and the guard. It seems cleaner to
be because only the list appears to be backticked and then unquoted.


A nice addition to pcase would perhaps be automatic "and". So having a
list like so

(pcase tst
  (`(symbolla . ,x)
   (guard (stringp x)))
  (message "cdr is a string: %s" x))

would automatically be interpreted as "and". Not sure if this works
syntactically, though.

Phil



reply via email to

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