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

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

bug#16238: 24.3.50; pcase docs (and possibly pcase) wrong


From: Tassilo Horn
Subject: bug#16238: 24.3.50; pcase docs (and possibly pcase) wrong
Date: Tue, 24 Dec 2013 10:37:06 +0100
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux)

Tassilo Horn <tsdh@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





reply via email to

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