* bug#14935: 24.3.50; pcase (or) UPAT fails?
@ 2013-07-23 11:30 Vitalie Spinu
2013-07-23 12:08 ` Andreas Schwab
2013-07-23 13:44 ` Stefan Monnier
0 siblings, 2 replies; 6+ messages in thread
From: Vitalie Spinu @ 2013-07-23 11:30 UTC (permalink / raw)
To: 14935
Is this a bug?
This works:
(pcase (list 23 nil "%")
(`(,scale nil "%") (message "%s" scale))
(_ (message "failed")))
This doesn't:
(pcase (list 23 nil "%")
(`(,scale nil (or "^" "%")) (message "%s" scale))
(_ (message "failed")))
Thanks,
Vitalie
In GNU Emacs 24.3.50.7 (i686-pc-linux-gnu, X toolkit, Xaw scroll bars)
of 2013-07-19 on vitoshka-OptiPlex-745
Windowing system distributor `The X.Org Foundation', version 11.0.11303000
System Description: Ubuntu 13.04
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#14935: 24.3.50; pcase (or) UPAT fails?
2013-07-23 11:30 bug#14935: 24.3.50; pcase (or) UPAT fails? Vitalie Spinu
@ 2013-07-23 12:08 ` Andreas Schwab
2013-07-23 13:44 ` Stefan Monnier
1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2013-07-23 12:08 UTC (permalink / raw)
To: Vitalie Spinu; +Cc: 14935
Vitalie Spinu <spinuvit@gmail.com> writes:
> (pcase (list 23 nil "%")
> (`(,scale nil (or "^" "%")) (message "%s" scale))
> (_ (message "failed")))
If you want to embed a UPattern in a QPattern you have to prefix it with
a comma, like you did with `scale'.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#14935: 24.3.50; pcase (or) UPAT fails?
2013-07-23 11:30 bug#14935: 24.3.50; pcase (or) UPAT fails? Vitalie Spinu
2013-07-23 12:08 ` Andreas Schwab
@ 2013-07-23 13:44 ` Stefan Monnier
2013-07-23 21:00 ` Vitalie Spinu
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-07-23 13:44 UTC (permalink / raw)
To: Vitalie Spinu; +Cc: 14935-done
> This doesn't:
> (pcase (list 23 nil "%")
> (`(,scale nil (or "^" "%")) (message "%s" scale))
> (_ (message "failed")))
> Is this a bug?
No, it's normal. The third pattern matches a list of 3 elements (the
first being the symbol `or'). You probably meant to do
(pcase (list 23 nil "%")
(`(,scale nil ,(or `"^" `"%")) (message "%s" scale))
(_ (message "failed")))
-- Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#14935: 24.3.50; pcase (or) UPAT fails?
2013-07-23 13:44 ` Stefan Monnier
@ 2013-07-23 21:00 ` Vitalie Spinu
2013-07-24 5:14 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Vitalie Spinu @ 2013-07-23 21:00 UTC (permalink / raw)
To: 14935
Thanks Andreas and Stephen,
I actually tried unquoting with comma before reporting. But it never
occurred to me that strings should be backticked. Strings are selfquoted
and, in my understanding, the following should have worked:
(pcase "^"
((or "^" "%") (message "here")))
The documentation says that strings are UPATs so
(pcase "^"
("^" (message "here")))
works. Then docs also say that (or UPAT UPAT) is also an UPAT so (or "^"
"%") should also work. Do I miss anything?
Thanks,
Vitalie
>> Stefan Monnier <monnier@iro.umontreal.ca>
>> on Tue, 23 Jul 2013 09:44:49 -0400 wrote:
>> This doesn't:
>> (pcase (list 23 nil "%")
>> (`(,scale nil (or "^" "%")) (message "%s" scale))
>> (_ (message "failed")))
>> Is this a bug?
> No, it's normal. The third pattern matches a list of 3 elements (the
> first being the symbol `or'). You probably meant to do
> (pcase (list 23 nil "%")
> (`(,scale nil ,(or `"^" `"%")) (message "%s" scale))
> (_ (message "failed")))
> -- Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#14935: 24.3.50; pcase (or) UPAT fails?
2013-07-23 21:00 ` Vitalie Spinu
@ 2013-07-24 5:14 ` Stefan Monnier
2013-07-24 7:19 ` Vitalie Spinu
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-07-24 5:14 UTC (permalink / raw)
To: Vitalie Spinu; +Cc: 14935-done
> (pcase "^"
> ((or "^" "%") (message "here")))
Yes, this should work, but it incorrectly used `memq' whereas the (or
`"^" `"%") pattern correctly leads to the use of `member'.
I installed the patch below which should fix it,
Stefan
=== modified file 'lisp/emacs-lisp/pcase.el'
--- lisp/emacs-lisp/pcase.el 2013-07-08 21:54:54 +0000
+++ lisp/emacs-lisp/pcase.el 2013-07-24 05:10:31 +0000
@@ -659,7 +659,11 @@
(memq-fine t))
(when all
(dolist (alt (cdr upat))
- (unless (or (pcase--self-quoting-p alt)
+ (unless (if (pcase--self-quoting-p alt)
+ (progn
+ (unless (or (symbolp alt) (integerp alt))
+ (setq memq-fine nil))
+ t)
(and (eq (car-safe alt) '\`)
(or (symbolp (cadr alt)) (integerp (cadr alt))
(setq memq-fine nil)
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#14935: 24.3.50; pcase (or) UPAT fails?
2013-07-24 5:14 ` Stefan Monnier
@ 2013-07-24 7:19 ` Vitalie Spinu
0 siblings, 0 replies; 6+ messages in thread
From: Vitalie Spinu @ 2013-07-24 7:19 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 14935-done
Thanks, it works. And more complex patterns are also fine now:
(pcase (list 23 nil "%")
(`(,x nil ,(or "^" "%")) (message "%s" x)))
>> Stefan Monnier <monnier@iro.umontreal.ca>
>> on Wed, 24 Jul 2013 01:14:10 -0400 wrote:
>> (pcase "^"
>> ((or "^" "%") (message "here")))
> Yes, this should work, but it incorrectly used `memq' whereas the (or
> `"^" `"%") pattern correctly leads to the use of `member'.
> I installed the patch below which should fix it,
> Stefan
> === modified file 'lisp/emacs-lisp/pcase.el'
> --- lisp/emacs-lisp/pcase.el 2013-07-08 21:54:54 +0000
> +++ lisp/emacs-lisp/pcase.el 2013-07-24 05:10:31 +0000
> @@ -659,7 +659,11 @@
> (memq-fine t))
> (when all
> (dolist (alt (cdr upat))
> - (unless (or (pcase--self-quoting-p alt)
> + (unless (if (pcase--self-quoting-p alt)
> + (progn
> + (unless (or (symbolp alt) (integerp alt))
> + (setq memq-fine nil))
> + t)
> (and (eq (car-safe alt) '\`)
> (or (symbolp (cadr alt)) (integerp (cadr alt))
> (setq memq-fine nil)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-07-24 7:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-23 11:30 bug#14935: 24.3.50; pcase (or) UPAT fails? Vitalie Spinu
2013-07-23 12:08 ` Andreas Schwab
2013-07-23 13:44 ` Stefan Monnier
2013-07-23 21:00 ` Vitalie Spinu
2013-07-24 5:14 ` Stefan Monnier
2013-07-24 7:19 ` Vitalie Spinu
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).