all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: 16238@debbugs.gnu.org
Subject: bug#16238: 24.3.50; pcase docs (and possibly pcase) wrong
Date: Tue, 24 Dec 2013 10:37:06 +0100	[thread overview]
Message-ID: <87ha9yvbct.fsf@thinkpad.tsdh.org> (raw)
In-Reply-To: <87ob46vcfl.fsf@thinkpad.tsdh.org> (Tassilo Horn's message of "Tue, 24 Dec 2013 10:13:50 +0100")

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	other threads:[~2013-12-24  9:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-24  9:13 bug#16238: 24.3.50; pcase docs (and possibly pcase) wrong Tassilo Horn
2013-12-24  9:37 ` Tassilo Horn [this message]
2013-12-24  9:55 ` Michael Heerdegen
2013-12-24 14:53 ` Stefan Monnier
2013-12-24 15:34   ` Tassilo Horn
2013-12-24 20:13     ` Glenn Morris
2013-12-25  9:15       ` Tassilo Horn
2013-12-25 20:04         ` Tassilo Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ha9yvbct.fsf@thinkpad.tsdh.org \
    --to=tsdh@gnu.org \
    --cc=16238@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.