* Re: [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern
[not found] ` <E1YrVuR-00064X-CK@vcs.savannah.gnu.org>
@ 2015-05-11 4:15 ` Stefan Monnier
2015-05-11 13:42 ` Nicolas Petton
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2015-05-11 4:15 UTC (permalink / raw)
To: emacs-devel; +Cc: Nicolas Petton
> + (pcase-defmacro seq (bindings)
> + `(and ,@(seq--make-pcase-bindings bindings)))
If you put a docstring in there, it will appear in "C-h f pcase RET", so
you can use it to document the particular format you support.
Also I see the following problems:
- You only accept the form (seq <binding>) rather than (seq <binding1>
<binding2> ...), so typical cases will have to use (seq (a b)) instead
(seq a b).
- The above pcase pattern doesn't check that it's indeed a `seq'.
You should add a (pred seq-p). It will automatically be optimized
away in `pcase-let', but is indispensable for the `pcase' situation to
do the right thing.
> +(defun seq--make-pcase-bindings (args &optional bindings nested-indexes)
[...]
> + (seq-doseq (name args)
> + (unless rest-marker
> + (pcase name
> + ((pred seq-p)
IIUC, this means that (pcase-let (((seq a (seq b c)) <obj>)) <body>)
will bind the `seq' variable to the first element of the nested sequence
(and `a' to the second and `b' to the third), whereas I think it should
bind `b' to the first element of the nested sequence (which is what
would happen if you simply removed this branch of this `pcase').
I think removing this case will also remove the need for seq--nested-elt.
> + (push `(app (seq--reverse-args #'seq--nested-elt
> + (reverse (cons ,index ',nested-indexes)))
> + ,name)
This reverse plus seq--reverse-args business seems
hideously inefficient. Why do you need that?
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern
2015-05-11 4:15 ` [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern Stefan Monnier
@ 2015-05-11 13:42 ` Nicolas Petton
2015-05-11 15:06 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Petton @ 2015-05-11 13:42 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Nicolas Petton, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2130 bytes --]
Stefan Monnier writes:
>> + (pcase-defmacro seq (bindings)
>> + `(and ,@(seq--make-pcase-bindings bindings)))
>
> If you put a docstring in there, it will appear in "C-h f pcase RET", so
> you can use it to document the particular format you support.
Great, I'll do that.
> Also I see the following problems:
> - You only accept the form (seq <binding>) rather than (seq <binding1>
> <binding2> ...), so typical cases will have to use (seq (a b)) instead
> (seq a b).
Yes. My idea of it was that you bind a sequence like the following:
(seq [a b [c d]])
Or did you have something else in mind?
> - The above pcase pattern doesn't check that it's indeed a `seq'.
> You should add a (pred seq-p). It will automatically be optimized
> away in `pcase-let', but is indispensable for the `pcase' situation to
> do the right thing.
Ok, I'll do that.
>
>> +(defun seq--make-pcase-bindings (args &optional bindings nested-indexes)
> [...]
>> + (seq-doseq (name args)
>> + (unless rest-marker
>> + (pcase name
>> + ((pred seq-p)
>
> IIUC, this means that (pcase-let (((seq a (seq b c)) <obj>)) <body>)
> will bind the `seq' variable to the first element of the nested sequence
> (and `a' to the second and `b' to the third), whereas I think it should
> bind `b' to the first element of the nested sequence (which is what
> would happen if you simply removed this branch of this `pcase').
> I think removing this case will also remove the need for
> seq--nested-elt.
But then how can I have `seq-let' work the way it did until now? For
instance:
(seq-let [a [b [c]]] my-vector
...)
>> + (push `(app (seq--reverse-args #'seq--nested-elt
>> + (reverse (cons ,index ',nested-indexes)))
>> + ,name)
>
> This reverse plus seq--reverse-args business seems
> hideously inefficient. Why do you need that?
because of the way the `app' pattern works. Or maybe I'm missing
something?
Nico
--
Nicolas Petton
http://nicolas-petton.fr
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern
2015-05-11 13:42 ` Nicolas Petton
@ 2015-05-11 15:06 ` Stefan Monnier
2015-05-11 21:13 ` Nicolas Petton
2015-05-11 21:35 ` Nicolas Petton
0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2015-05-11 15:06 UTC (permalink / raw)
To: Nicolas Petton; +Cc: emacs-devel
> Yes. My idea of it was that you bind a sequence like the following:
> (seq [a b [c d]])
I was thinking of (seq a b (seq c d)).
You could add support for (seq a b [c d]), if you want since that
currently wouldn't collide with any pcase pattern, tho I'm not sure it's
worth the added complexity for the user.
> But then how can I have `seq-let' work the way it did until now? For
> instance:
> (seq-let [a [b [c]]] my-vector
> ...)
You expand [a [b [c]]] to (seq a (seq b (seq c))) before passing it to
pcase-let.
>>> + (push `(app (seq--reverse-args #'seq--nested-elt
>>> + (reverse (cons ,index ',nested-indexes)))
>>> + ,name)
>> This reverse plus seq--reverse-args business seems
>> hideously inefficient. Why do you need that?
> because of the way the `app' pattern works. Or maybe I'm missing
> something?
Why wouldn't
`(app (seq--nested-elt ',(reverse (cons index nested-indexes))) ,name)
work as well? Or, once you get rid of the nested case,
`(app (seq-elt ,index) ,name)
-- Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern
2015-05-11 15:06 ` Stefan Monnier
@ 2015-05-11 21:13 ` Nicolas Petton
2015-05-11 21:35 ` Nicolas Petton
1 sibling, 0 replies; 7+ messages in thread
From: Nicolas Petton @ 2015-05-11 21:13 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Nicolas Petton, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1415 bytes --]
Stefan Monnier writes:
>> Yes. My idea of it was that you bind a sequence like the following:
>> (seq [a b [c d]])
>
> I was thinking of (seq a b (seq c d)).
>
> You could add support for (seq a b [c d]), if you want since that
> currently wouldn't collide with any pcase pattern, tho I'm not sure it's
> worth the added complexity for the user.
>
>> But then how can I have `seq-let' work the way it did until now? For
>> instance:
>> (seq-let [a [b [c]]] my-vector
>> ...)
>
> You expand [a [b [c]]] to (seq a (seq b (seq c))) before passing it to
> pcase-let.
>
>>>> + (push `(app (seq--reverse-args #'seq--nested-elt
>>>> + (reverse (cons ,index ',nested-indexes)))
>>>> + ,name)
>>> This reverse plus seq--reverse-args business seems
>>> hideously inefficient. Why do you need that?
>> because of the way the `app' pattern works. Or maybe I'm missing
>> something?
>
> Why wouldn't
>
> `(app (seq--nested-elt ',(reverse (cons index nested-indexes))) ,name)
>
> work as well? Or, once you get rid of the nested case,
>
> `(app (seq-elt ,index) ,name)
I understand what you meant now. It indeed makes sense, and the pcase
pattern would be much more consistent. I'll push another commit.
Cheers,
Nico
>
>
> -- Stefan
--
Nicolas Petton
http://nicolas-petton.fr
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern
2015-05-11 15:06 ` Stefan Monnier
2015-05-11 21:13 ` Nicolas Petton
@ 2015-05-11 21:35 ` Nicolas Petton
2015-05-12 1:03 ` Stefan Monnier
1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Petton @ 2015-05-11 21:35 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Petton, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
Stefan Monnier writes:
> Why wouldn't
>
> `(app (seq--nested-elt ',(reverse (cons index nested-indexes))) ,name)
>
> work as well? Or, once you get rid of the nested case,
>
> `(app (seq-elt ,index) ,name)
Wouldn't that result in passing the sequence as the second argument of
`seq-elt'? That was the reason why I added this reversed arguments.
Cheers,
Nico
--
Nicolas Petton
http://nicolas-petton.fr
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern
2015-05-11 21:35 ` Nicolas Petton
@ 2015-05-12 1:03 ` Stefan Monnier
2015-05-12 6:51 ` Nicolas Petton
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2015-05-12 1:03 UTC (permalink / raw)
To: Nicolas Petton; +Cc: emacs-devel
> Wouldn't that result in passing the sequence as the second argument of
> `seq-elt'?
Yes. Sorry, I missed that `elt' takes args in the same order as `aref'
rather than `nth'.
> That was the reason why I added this reversed arguments.
Ah, in this case, I guess you could use pcase--flip (or equivalent).
Notice that it's a macro, so the arg-reversal will take place at
compile-time.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern
2015-05-12 1:03 ` Stefan Monnier
@ 2015-05-12 6:51 ` Nicolas Petton
0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Petton @ 2015-05-12 6:51 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Nicolas Petton, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 553 bytes --]
Stefan Monnier writes:
>> Wouldn't that result in passing the sequence as the second argument of
>> `seq-elt'?
>
> Yes. Sorry, I missed that `elt' takes args in the same order as `aref'
> rather than `nth'.
>
>> That was the reason why I added this reversed arguments.
>
> Ah, in this case, I guess you could use pcase--flip (or equivalent).
> Notice that it's a macro, so the arg-reversal will take place at
> compile-time.
Thanks for the tip, I didn't know about pcase--flip.
Nico
--
Nicolas Petton
http://nicolas-petton.fr
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-05-12 6:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20150510182502.23307.63648@vcs.savannah.gnu.org>
[not found] ` <E1YrVuR-00064X-CK@vcs.savannah.gnu.org>
2015-05-11 4:15 ` [Emacs-diffs] master 387e1e1: New version of `seq-let' based on a pcase pattern Stefan Monnier
2015-05-11 13:42 ` Nicolas Petton
2015-05-11 15:06 ` Stefan Monnier
2015-05-11 21:13 ` Nicolas Petton
2015-05-11 21:35 ` Nicolas Petton
2015-05-12 1:03 ` Stefan Monnier
2015-05-12 6:51 ` Nicolas Petton
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).