From: Joost Kremers <joostkremers@yahoo.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Scheme to elisp
Date: 16 May 2007 15:58:07 GMT [thread overview]
Message-ID: <slrnf4maeu.1qg.joostkremers@j.kremers4.news.arnhem.chello.nl> (raw)
In-Reply-To: 1179320194.826658.32840@p77g2000hsh.googlegroups.com
weber wrote:
> Or in a simplified form, my problem is : why the snippet below does
> not work?
[note: the original indentation was confusing:]
> (defun f (n)
> (let ((g (lambda (x) (+ 5 x))))
> (g (+ n 1))))
>
> (f 1) -> void-function g
well, elisp is a lisp2, rather than a lisp1 (as scheme is), so a symbol can
have both a value as a variable *and* a function definition. with let, you
assign g a value *as a variable*, it does not affect the *function*
definition of the symbol g.
it is possible to assign an anonymous function as the variable value of a
symbol. if you do this, you can use either funcall or apply (they have
different uses) to call the (anonymous) function stored in the variable,
like this:
(defun f (n)
(let ((g (lambda (x) (+ 5 x))))
(funcall g (+ n 1))))
alternatively, if you use the common-lisp compatibility package, you can
use either flet or labels to create function bindings:
(defun f (n)
(flet ((g (x) (+ 5 x)))
(g (+ n 1))))
note that with flet, you don't use anonymous functions. the syntax is:
(flet ((<function_name> <arg_list> . <function_body>))
(<flet_body>)
...)
HTH
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
next prev parent reply other threads:[~2007-05-16 15:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-16 12:56 Scheme to elisp weber
2007-05-16 15:58 ` Joost Kremers [this message]
2007-05-16 17:18 ` weber
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=slrnf4maeu.1qg.joostkremers@j.kremers4.news.arnhem.chello.nl \
--to=joostkremers@yahoo.com \
--cc=help-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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).