all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: jwiegley@gmail.com, emacs-devel@gnu.org
Subject: Re: pcase docs
Date: Sat, 23 Jan 2016 13:05:22 +0100	[thread overview]
Message-ID: <87mvrwzekd.fsf@web.de> (raw)
In-Reply-To: <83fuxo5xo4.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 23 Jan 2016 13:43:07 +0200")

Eli Zaretskii <eliz@gnu.org> writes:

> Sorry, I don't understand: how can knowing what 'defmacro' does help
> to know what 'pcase-defmacro' does?

It works extremely analogous.

>  At the very least, one needs to know which patterns will be possible
> after using 'pcase-defmacro', don't you agree?
>
> Btw, this macro also has "issues".  The doc string is less than
> helpful:
>
>     "Define a new kind of pcase PATTERN, by macro expansion.
>   Patterns of the form (NAME ...) will be expanded according
>   to this macro."
>
> It says nothing about ARGS, and the "by macro expansion" part sounds
> strange -- what useful information does it supply here?

I agree that it's quite vague.

> And if you turn to the users of this macro, in the hope of gaining
> some understanding, you will see, for example, that map.el defines a
> pattern whose NAME is "map":
>
>   (pcase-defmacro map (&rest args)
>     "Build a `pcase' pattern matching map elements.
>
>   The `pcase' pattern will match each element of PATTERN against
>   the corresponding elements of the map.

> (btw: what PATTERN?),

the pattern that is gotten by expanding.

> but then uses it like this:
>
>   (pcase type
>     (`list (map-pairs map))
>     (`hash-table (map--into-hash-table map))
>     (_ (error "Not a map type name: %S" type))))

(why does my definition look like

`(and (pred mapp)
        ,@(map--make-pcase-bindings args))

?)

> IOW, it actually uses sub-classes of 'map' as patterns.  Hmm...

> As an aside, when I look at such doc strings, I always become
> frustrated, because I must be extremely stupid to ask all these
> questions, when no one else evidently cares, which must mean they all
> understand this stuff, and only I alone don't, right?

Surely not!  I just had the time to read the code, carefully (I had to,
to be able to write my el-search.el thing).  Most others don't care
because they just don't care, I think.

Actually `pcase-defmacro' is easy to understand if you understood
`defmacro': You define a pattern by its name and by the arguments it
will accept.

When the pcase "compiler" finds a pattern that is defined as a macro, it
substitutes the "call" with the "code" returned by evaluating the macro
definition with the given arguments.  Exactly like Lisp macros are
expanded by the lisp compiler.  Just that we have pcase "code" (i.e.,
another pattern again) in this case.  This is done recursively, i.e. the
returned pattern can be a pcase macro, a include pcase macros, again,
etc.

Try to understand the definition of ` - it's a challenge, but if you
succeed, you will see that things are much easier than you had expected.


Michael.



  reply	other threads:[~2016-01-23 12:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14 19:47 pcase docs Eli Zaretskii
2016-01-22 18:07 ` John Wiegley
2016-01-22 19:46   ` Michael Heerdegen
2016-01-22 19:58     ` Michael Heerdegen
2016-01-22 21:30       ` Eli Zaretskii
2016-01-23 10:16         ` Michael Heerdegen
2016-01-23 11:43           ` Eli Zaretskii
2016-01-23 12:05             ` Michael Heerdegen [this message]
2016-01-23 13:35               ` Eli Zaretskii
2016-01-23 14:22                 ` Michael Heerdegen
2016-01-23 14:50                   ` Eli Zaretskii
2016-01-23 15:18                     ` Michael Heerdegen
2016-01-24  8:50                       ` Nicolas Petton
2016-01-23 15:51                 ` Michael Heerdegen
2016-01-23 12:28             ` Alan Mackenzie
2016-01-23 13:13               ` Eli Zaretskii
2016-01-23 20:48               ` Drew Adams
2016-01-24  5:07             ` Stefan Monnier
2016-01-22 21:28     ` Eli Zaretskii

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=87mvrwzekd.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=jwiegley@gmail.com \
    /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.