* bug#22812: 24.5: elisp manual about pcase
@ 2016-02-26 2:08 Zhaohui Li
2016-02-26 13:01 ` Michael Heerdegen
0 siblings, 1 reply; 5+ messages in thread
From: Zhaohui Li @ 2016-02-26 2:08 UTC (permalink / raw)
To: 22812
[-- Attachment #1: Type: text/plain, Size: 1343 bytes --]
The "10.2.1: Pattern matching case statement" in Emacs Lisp Referrence
Manual has a problem.
The second example in manual is:
> (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))))
>
The problem is about the third case: `(fn , arg ,body).
I test this function with:
> (evaluate '(call
> (fn x (add 1 x))
> 2)
> nil)
>
emcas eval it with throw errors.
I think the correct of this function should be:
> (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))))
>
Thanks~
[-- Attachment #2: Type: text/html, Size: 2234 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#22812: 24.5: elisp manual about pcase
2016-02-26 2:08 bug#22812: 24.5: elisp manual about pcase Zhaohui Li
@ 2016-02-26 13:01 ` Michael Heerdegen
2016-02-26 15:43 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2016-02-26 13:01 UTC (permalink / raw)
To: Zhaohui Li; +Cc: 22812
Zhaohui Li <lizhaohui1991@gmail.com> writes:
> The "10.2.1: Pattern matching case statement" in Emacs Lisp Referrence
> Manual has a problem. The second example in manual is:
>
>
> (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))))
>
>
> The problem is about the third case: `(fn , arg ,body).
> I test this function with:
>
>
> (evaluate '(call
> (fn x (add 1 x))
> 2)
> nil)
>
>
> emcas eval it with throw errors.
Works for me. Did you enable lexical binding when testing?
Regards,
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#22812: 24.5: elisp manual about pcase
2016-02-26 13:01 ` Michael Heerdegen
@ 2016-02-26 15:43 ` Eli Zaretskii
2016-02-26 16:30 ` Michael Heerdegen
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2016-02-26 15:43 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: 22812, lizhaohui1991
> From: Michael Heerdegen <michael_heerdegen@web.de>
> Date: Fri, 26 Feb 2016 14:01:10 +0100
> Cc: 22812@debbugs.gnu.org
>
> > (evaluate '(call
> > (fn x (add 1 x))
> > 2)
> > nil)
> >
> >
> > emcas eval it with throw errors.
>
> Works for me. Did you enable lexical binding when testing?
Should we add a comment to the manual with this caveat?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-27 19:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-26 2:08 bug#22812: 24.5: elisp manual about pcase Zhaohui Li
2016-02-26 13:01 ` Michael Heerdegen
2016-02-26 15:43 ` Eli Zaretskii
2016-02-26 16:30 ` Michael Heerdegen
[not found] ` <CAATu+k-O1b87=9hKh_6y3kGTGJSh+Ox3kkBXK7RH_OvYU55xdw@mail.gmail.com>
2016-02-27 19:40 ` Michael Heerdegen
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).