* Scheme to elisp
@ 2007-05-16 12:56 weber
2007-05-16 15:58 ` Joost Kremers
0 siblings, 1 reply; 3+ messages in thread
From: weber @ 2007-05-16 12:56 UTC (permalink / raw)
To: help-gnu-emacs
Hi everyone...
I started reading the sample chapter of the Friedman's books, but got
stuck trying to rewrite this scheme function in elisp:
(define intersect
(lambda (set1 set2)
(letrec
((I (lambda (set)
(cond
((null? set) (quote ()))
((member? (cat set1) set2)
(cons (car set)
(I (cdr set))))
(else (I (cdr set)))))))
(I set1))))
Or in a simplified form, my problem is : why the snippet below does
not work?
(defun f (n)
(let ((g (lambda (x) (+ 5 x))))
(g (+ n 1))))
(f 1) -> void-function g
Thanks in advance,
-weber
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Scheme to elisp
2007-05-16 12:56 Scheme to elisp weber
@ 2007-05-16 15:58 ` Joost Kremers
2007-05-16 17:18 ` weber
0 siblings, 1 reply; 3+ messages in thread
From: Joost Kremers @ 2007-05-16 15:58 UTC (permalink / raw)
To: help-gnu-emacs
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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Scheme to elisp
2007-05-16 15:58 ` Joost Kremers
@ 2007-05-16 17:18 ` weber
0 siblings, 0 replies; 3+ messages in thread
From: weber @ 2007-05-16 17:18 UTC (permalink / raw)
To: help-gnu-emacs
On 16 maio, 12:58, Joost Kremers <joostkrem...@yahoo.com> wrote:
> 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 joostkrem...@yahoo.com
> Selbst in die Unterwelt dringt durch Spalten Licht
> EN:SiS(9)
Thank you very much for the explanation...
It did helped!
-weber
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-05-16 17:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-16 12:56 Scheme to elisp weber
2007-05-16 15:58 ` Joost Kremers
2007-05-16 17:18 ` weber
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).