emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#22812: closed (24.5: elisp manual about pcase)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#22812: closed (24.5: elisp manual about pcase)
Date: Sat, 27 Feb 2016 19:41:01 +0000

Your message dated Sat, 27 Feb 2016 20:40:12 +0100
with message-id <address@hidden>
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
address@hidden)


-- 
22812: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22812
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: 24.5: elisp manual about pcase Date: Fri, 26 Feb 2016 10:08:09 +0800
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~

--- End Message ---
--- Begin Message --- Subject: Re: bug#22812: 24.5: elisp manual about pcase Date: Sat, 27 Feb 2016 20:40:12 +0100 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (gnu/linux)
Ok, the example runs fine with lexical-binding enabled; thanks
nevertheless.  Closing.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]