GNU bug report logs -
#16238
24.3.50; pcase docs (and possibly pcase) wrong
Previous Next
Reported by: Tassilo Horn <tsdh <at> gnu.org>
Date: Tue, 24 Dec 2013 09:15:02 UTC
Severity: minor
Found in version 24.3.50
Done: Tassilo Horn <tsdh <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Tassilo Horn <tsdh <at> 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
This bug report was last modified 11 years and 155 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.