GNU bug report logs -
#16238
24.3.50; pcase docs (and possibly pcase) wrong
Previous Next
Reported by: Tassilo Horn <tsdh <at> gnu.org>
Date: Tue, 24 Dec 2013 09:15:02 UTC
Severity: minor
Found in version 24.3.50
Done: Tassilo Horn <tsdh <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16238 in the body.
You can then email your comments to 16238 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16238
; Package
emacs
.
(Tue, 24 Dec 2013 09:15:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Tassilo Horn <tsdh <at> gnu.org>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 24 Dec 2013 09:15:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
I'm just reading through the `pcase' docs in the info manual. The
simple expression language example has a small bug. The `env' parameter
is missing at the location marked below:
--8<---------------cut here---------------start------------->8---
(defun evaluate (exp env)
(pcase exp
(`(add ,x ,y) (+ (evaluate x env) (evaluate y env)))
(`(call ,fun ,arg) (funcall (evaluate fun) (evaluate arg env)))
`--- HERE!
(`(fn ,arg ,body) (lambda (val)
(evaluate body (cons (cons arg val) env))))
((pred numberp) exp)
((pred symbolp) (cdr (assq exp env)))
(_ (error "Unknown expression %S" exp))))
--8<---------------cut here---------------end--------------->8---
But even then, I can't get `fn' forms working:
ELISP> (evaluate '(fn x (add 1 x)) nil)
(lambda
(val)
(evaluate body
(cons
(cons arg val)
env)))
But shouldn't `arg' be substituted with 'x and `body' with '(add 1 x)?
Now when I call the function, I get a void-variable error whereas I
should get 3:
ELISP> (evaluate '(call (fn x (add 1 x)) 2) nil)
*** Eval error *** Symbol's value as variable is void: body
Strange enough, the `call' pattern which uses the same pattern syntax
seems to work, though:
ELISP> (evaluate '(call foo 2) '((foo . (lambda (x) (+ 1 x)))))
3 (#o3, #x3, ?\C-c)
In any case, it would be good if the docs would contain a sample program
defined in the simple expression language. Getting the syntax right
just from the patterns is not enough. For example, it's not obvious
that `fn' forms take only one symbol as `arg' whereas you'd usually
expect an argument list (which might be restricted to length 1).
In GNU Emacs 24.3.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.8.7)
of 2013-12-22 on thinkpad
Bzr revision: eliz <at> gnu.org-20131222183138-zlzn9zzpz1hwd110
Windowing system distributor `The X.Org Foundation', version 11.0.11499904
System Description: NAME=Gentoo
Configured using:
`configure --prefix=/usr --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --mandir=/usr/share/man
--infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc
--localstatedir=/var/lib --libdir=/usr/lib64 --disable-silent-rules
--disable-dependency-tracking --program-suffix=-emacs-24-vcs
--infodir=/usr/share/info/emacs-24-vcs
--enable-locallisppath=/etc/emacs:/usr/share/emacs/site-lisp
--with-gameuser=games --without-compress-info
--with-file-notification=gfile --disable-acl --with-dbus --with-gnutls
--with-gpm --without-hesiod --without-kerberos --without-kerberos5
--with-xml2 --without-selinux --without-wide-int --with-zlib
--with-sound=alsa --with-x --without-ns --without-gconf
--with-gsettings --with-toolkit-scroll-bars --with-gif --with-jpeg
--with-png --with-rsvg --with-tiff --with-xpm --with-imagemagick
--with-xft --with-libotf --with-m17n-flt --with-x-toolkit=gtk3
GENTOO_PACKAGE=app-editors/emacs-vcs-24.3.9999 EBZR_BRANCH=trunk
EBZR_REVNO=115696 'CFLAGS=-march=native -pipe -g3 -ggdb' CPPFLAGS=
'LDFLAGS=-Wl,-O1 -Wl,--as-needed''
Important settings:
value of $LC_COLLATE: C
value of $LC_MONETARY: de_DE.utf8
value of $LC_NUMERIC: de_DE.utf8
value of $LC_TIME: de_DE.utf8
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
Major mode: Lisp Interaction
Minor modes in effect:
helm-match-plugin-mode: t
helm-occur-match-plugin-mode: t
highlight-parentheses-mode: t
global-company-mode: t
company-mode: t
eldoc-mode: t
shell-dirtrack-mode: t
paredit-mode: t
highlight-symbol-mode: t
global-edit-server-edit-mode: t
outline-minor-mode: t
recentf-mode: t
global-subword-mode: t
subword-mode: t
savehist-mode: t
show-paren-mode: t
icomplete-mode: t
minibuffer-depth-indicate-mode: t
tooltip-mode: t
electric-pair-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
column-number-mode: t
line-number-mode: t
transient-mark-mode: t
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16238
; Package
emacs
.
(Tue, 24 Dec 2013 09:38:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 16238 <at> debbugs.gnu.org (full text, mbox):
Tassilo Horn <tsdh <at> gnu.org> writes:
> ELISP> (evaluate '(fn x (add 1 x)) nil)
> (lambda
> (val)
> (evaluate body
> (cons
> (cons arg val)
> env)))
>
> But shouldn't `arg' be substituted with 'x and `body' with '(add 1 x)?
It seems the `lambda' is the problem that prevents substitution of arg
and body. By doing some kinda strange quoting I can get it right, but
IMHO that shouldn't be needed:
--8<---------------cut here---------------start------------->8---
(defun evaluate (exp env)
(pcase exp
(`(add ,x ,y) (+ (evaluate x env) (evaluate y env)))
(`(call ,fun ,arg) (funcall (evaluate fun env) (evaluate arg env)))
(`(fn ,arg ,body) `(lambda (val)
(evaluate ',body (cons (cons ',arg val) env))))
((pred numberp) exp)
((pred symbolp) (cdr (assq exp env)))
(_ (error "Unknown expression %S" exp))))
--8<---------------cut here---------------end--------------->8---
ELISP> (evaluate '(fn x (add 1 x)) nil)
(lambda
(val)
(evaluate
'(add 1 x)
(cons
(cons 'x val)
env)))
ELISP> (evaluate '(call (fn x (add 1 x)) 3) nil)
4 (#o4, #x4, ?\C-d)
Bye,
Tassilo
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16238
; Package
emacs
.
(Tue, 24 Dec 2013 09:56:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 16238 <at> debbugs.gnu.org (full text, mbox):
Tassilo Horn <tsdh <at> gnu.org> writes:
> But shouldn't `arg' be substituted with 'x and `body' with '(add 1 x)?
> Now when I call the function, I get a void-variable error whereas I
> should get 3:
>
> ELISP> (evaluate '(call (fn x (add 1 x)) 2) nil)
> *** Eval error *** Symbol's value as variable is void: body
I think the example is designed for lexical-binding. That should be
mentioned. It is not so nice anyway, since people will likely C-x C-e
the example and then it won't work.
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16238
; Package
emacs
.
(Tue, 24 Dec 2013 14:54:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 16238 <at> debbugs.gnu.org (full text, mbox):
> (defun evaluate (exp env)
> (pcase exp
> (`(add ,x ,y) (+ (evaluate x env) (evaluate y env)))
> (`(call ,fun ,arg) (funcall (evaluate fun) (evaluate arg env)))
> `--- HERE!
Indeed, feel free to fix it.
> But shouldn't `arg' be substituted with 'x and `body' with '(add 1 x)?
No, the code is meant for lexical-binding.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16238
; Package
emacs
.
(Tue, 24 Dec 2013 15:35:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 16238 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:
>> (defun evaluate (exp env)
>> (pcase exp
>> (`(add ,x ,y) (+ (evaluate x env) (evaluate y env)))
>> (`(call ,fun ,arg) (funcall (evaluate fun) (evaluate arg env)))
>> `--- HERE!
>
> Indeed, feel free to fix it.
Done.
>> But shouldn't `arg' be substituted with 'x and `body' with '(add 1
>> x)?
>
> No, the code is meant for lexical-binding.
Ok, I see. I've also mentioned that in the docs, though I guess you can
refine that comment to be more specific.
Bye,
Tassilo
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16238
; Package
emacs
.
(Tue, 24 Dec 2013 20:14:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 16238 <at> debbugs.gnu.org (full text, mbox):
Tassilo Horn wrote:
>> No, the code is meant for lexical-binding.
>
> Ok, I see. I've also mentioned that in the docs, though I guess you can
> refine that comment to be more specific.
That _example_ assumes lexical binding. _Pcase itself_ does not require
lexical binding. (You've written in the manual that it does.)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16238
; Package
emacs
.
(Wed, 25 Dec 2013 09:16:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 16238 <at> debbugs.gnu.org (full text, mbox):
Glenn Morris <rgm <at> gnu.org> writes:
>>> No, the code is meant for lexical-binding.
>>
>> Ok, I see. I've also mentioned that in the docs, though I guess you
>> can refine that comment to be more specific.
>
> That _example_ assumes lexical binding. _Pcase itself_ does not
> require lexical binding. (You've written in the manual that it does.)
Ah, yes. I'm so used to lexical binding that I can't see a closure when
it's immediately in front of me. I've corrected the sentence and moved
it directly after the `evaluate' code.
Bye,
Tassilo
Reply sent
to
Tassilo Horn <tsdh <at> gnu.org>
:
You have taken responsibility.
(Wed, 25 Dec 2013 20:05:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Tassilo Horn <tsdh <at> gnu.org>
:
bug acknowledged by developer.
(Wed, 25 Dec 2013 20:05:03 GMT)
Full text and
rfc822 format available.
Message #28 received at 16238-done <at> debbugs.gnu.org (full text, mbox):
Closing.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Thu, 23 Jan 2014 12:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 10 years and 116 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.