From: Tassilo Horn <tsdh@gnu.org>
To: 16238@debbugs.gnu.org
Subject: bug#16238: 24.3.50; pcase docs (and possibly pcase) wrong
Date: Tue, 24 Dec 2013 10:13:50 +0100 [thread overview]
Message-ID: <87ob46vcfl.fsf@thinkpad.tsdh.org> (raw)
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@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
next reply other threads:[~2013-12-24 9:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-24 9:13 Tassilo Horn [this message]
2013-12-24 9:37 ` bug#16238: 24.3.50; pcase docs (and possibly pcase) wrong Tassilo Horn
2013-12-24 9:55 ` Michael Heerdegen
2013-12-24 14:53 ` Stefan Monnier
2013-12-24 15:34 ` Tassilo Horn
2013-12-24 20:13 ` Glenn Morris
2013-12-25 9:15 ` Tassilo Horn
2013-12-25 20:04 ` Tassilo Horn
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=87ob46vcfl.fsf@thinkpad.tsdh.org \
--to=tsdh@gnu.org \
--cc=16238@debbugs.gnu.org \
/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.