all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: phillip.lord@russet.org.uk (Phillip Lord)
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Quick pcase question
Date: Wed, 02 Mar 2016 17:25:30 +0000	[thread overview]
Message-ID: <874mcovlkl.fsf@russet.org.uk> (raw)
In-Reply-To: <87bn6xvzdj.fsf@web.de> (Michael Heerdegen's message of "Wed, 2 Mar 2016 13:27:20 +0100")

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	other threads:[~2016-03-02 17:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-02 10:12 Quick pcase question Eric Abrahamsen
2016-03-02 11:02 ` Michael Heerdegen
2016-03-02 11:18   ` Eric Abrahamsen
2016-03-02 11:38     ` Michael Heerdegen
2016-03-02 11:56       ` Eric Abrahamsen
2016-03-02 12:27         ` Michael Heerdegen
2016-03-02 17:25           ` Phillip Lord [this message]
2016-03-03  1:13             ` Eric Abrahamsen
2016-03-03  3:47             ` Stefan Monnier
2016-03-02 17:18     ` Phillip Lord
2016-03-03  1:08       ` Eric Abrahamsen
2016-03-03 12:08         ` Phillip Lord
2016-03-02 12:40 ` Phillip Lord

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=874mcovlkl.fsf@russet.org.uk \
    --to=phillip.lord@russet.org.uk \
    --cc=help-gnu-emacs@gnu.org \
    --cc=michael_heerdegen@web.de \
    /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.