GNU bug report logs - #22812
24.5: elisp manual about pcase

Previous Next

Package: emacs;

Reported by: Zhaohui Li <lizhaohui1991 <at> gmail.com>

Date: Fri, 26 Feb 2016 02:35:02 UTC

Severity: minor

Found in version 24.5

Done: Michael Heerdegen <michael_heerdegen <at> web.de>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#22812: closed (24.5: elisp manual about pcase)
Date: Sat, 27 Feb 2016 19:41:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sat, 27 Feb 2016 20:40:12 +0100
with message-id <87wppqkkmb.fsf <at> web.de>
and subject line Re: bug#22812: 24.5: elisp manual about pcase
has caused the debbugs.gnu.org bug report #22812,
regarding 24.5: elisp manual about pcase
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
22812: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22812
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Zhaohui Li <lizhaohui1991 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.5: elisp manual about pcase
Date: Fri, 26 Feb 2016 10:08:09 +0800
[Message part 3 (text/plain, inline)]
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~
[Message part 4 (text/html, inline)]
[Message part 5 (message/rfc822, inline)]
From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Zhaohui Li <lizhaohui1991 <at> gmail.com>
Cc: 22812-done <at> debbugs.gnu.org
Subject: Re: bug#22812: 24.5: elisp manual about pcase
Date: Sat, 27 Feb 2016 20:40:12 +0100
Ok, the example runs fine with lexical-binding enabled; thanks
nevertheless.  Closing.


This bug report was last modified 9 years and 88 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.