From: Trent Buck <trentbuck@gmail.com>
To: bug-gnu-emacs@gnu.org
Subject: Re: About function parameters, is it a bug of elisp interpreter?
Date: Tue, 22 May 2007 12:47:01 +1000 [thread overview]
Message-ID: <87abvxmv6i.fsf@baal.lan> (raw)
In-Reply-To: 8f62e1cd0705211122p2b920a9ag8092de66c0c0751a@mail.gmail.com
"Lee David" <live4thee@gmail.com> writes:
> When porting some Scheme functions to Elisp, I encountered a strange
> (to me) problem as listed below.
>
> (defun sum (term beg next b)
> (defun iter (beg result)
> (if (> beg b)
> result
> (iter (funcall next beg) (+ result (funcall term beg)))))
>
> (iter beg 0))
Elisp does not have Scheme-style block structure. DEFUN always
changes the global procedure definition. This can be demonstrated
trivially:
;; in Emacs
ELISP> (defun f ()
(defun g ()
2)
(g))
f
ELISP> (f)
2
ELISP> (fboundp 'g)
t
;; in Scheme
#;1> (define (f)
(define (g)
2)
(g))
#;2> (f)
2
#;3> g
Error: unbound variable: g
Similarly, R5RS Scheme always uses lexical scoping, whereas elisp is
dynamically scoped (by default).
;; in Emacs
ELISP> (defvar x 2)
x
ELISP> (defun f ()
x)
f
ELISP> (let ((x 3))
(f))
3
;; in Scheme
#;1> (define x 2)
#;2> (define (f)
x)
#;3> (let ((x 3))
(f))
2
These are not so much bugs as simply different semantics. You will
need to understand them in order to correctly translate code between
Scheme and elisp.
--
Trent Buck
next prev parent reply other threads:[~2007-05-22 2:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-21 18:22 About function parameters, is it a bug of elisp interpreter? Lee David
2007-05-22 2:47 ` Trent Buck [this message]
2007-05-22 6:03 ` Lee David
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=87abvxmv6i.fsf@baal.lan \
--to=trentbuck@gmail.com \
--cc=bug-gnu-emacs@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.