all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* newbie questions: why doesn't ((lambda (x) (x 2)) (lambda (n) (+ n 3))) work in elisp?
@ 2008-05-30 17:03 Tahsin Alam
  2008-05-31  6:41 ` Thien-Thi Nguyen
       [not found] ` <mailman.12481.1212216300.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Tahsin Alam @ 2008-05-30 17:03 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]


As the subject says - why does the following expression give error when I try
to evaluate it in the *scratch* buffer?

((lambda (x) (x 2)) (lambda (n) (+ n 3)))


---

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.

[-- Attachment #2: Type: text/html, Size: 595 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: newbie questions: why doesn't ((lambda (x) (x 2)) (lambda (n) (+ n 3))) work in elisp?
       [not found] <mailman.12463.1212181801.18990.help-gnu-emacs@gnu.org>
@ 2008-05-30 21:27 ` Joost Diepenmaat
  2008-05-30 21:33   ` Joost Diepenmaat
  0 siblings, 1 reply; 5+ messages in thread
From: Joost Diepenmaat @ 2008-05-30 21:27 UTC (permalink / raw)
  To: help-gnu-emacs

Tahsin Alam <tahsin.alam@db.com> writes:

> As the subject says - why does the following expression give error when I try to evaluate it in the *scratch* buffer?
>
> ((lambda (x) (x 2)) (lambda (n) (+ n 3)))

Because ((some call evaluating to a function)) isn't valid in emacs
lisp, which also means

(lambda (x) (x 2))

has no real meaning in elisp (it does in scheme, but not in elisp or
common lisp, because elisp and cl have separate namespaces for
functions and variables). You want either

(funcall (lambda (x) (funcall x 2)) (lambda (n) (+ n 3)))

or possibly

(list (lambda (x) (list x 2)) (lambda (n) (+ n 3)))

or some permutation of both.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: newbie questions: why doesn't ((lambda (x) (x 2)) (lambda (n) (+ n 3))) work in elisp?
  2008-05-30 21:27 ` Joost Diepenmaat
@ 2008-05-30 21:33   ` Joost Diepenmaat
  0 siblings, 0 replies; 5+ messages in thread
From: Joost Diepenmaat @ 2008-05-30 21:33 UTC (permalink / raw)
  To: help-gnu-emacs


Joost Diepenmaat <joost@zeekat.nl> writes:
> Tahsin Alam <tahsin.alam@db.com> writes:
>
>> As the subject says - why does the following expression give error when I try to evaluate it in the *scratch* buffer?
>>
>> ((lambda (x) (x 2)) (lambda (n) (+ n 3)))
>
> Because ((some call evaluating to a function)) isn't valid in emacs
> lisp, which also means
>
> (lambda (x) (x 2))

unless, of course, you've got a (defun x (y) ...) somewhere...

> has no real meaning in elisp (it does in scheme, but not in elisp or
> common lisp, because elisp and cl have separate namespaces for
> functions and variables). You want either
>
> (funcall (lambda (x) (funcall x 2)) (lambda (n) (+ n 3)))
>
> or possibly
>
> (list (lambda (x) (list x 2)) (lambda (n) (+ n 3)))
>
> or some permutation of both.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: newbie questions: why doesn't ((lambda (x) (x 2)) (lambda (n) (+ n 3))) work in elisp?
  2008-05-30 17:03 newbie questions: why doesn't ((lambda (x) (x 2)) (lambda (n) (+ n 3))) work in elisp? Tahsin Alam
@ 2008-05-31  6:41 ` Thien-Thi Nguyen
       [not found] ` <mailman.12481.1212216300.18990.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2008-05-31  6:41 UTC (permalink / raw)
  To: Tahsin Alam; +Cc: help-gnu-emacs

⎛⎞ Tahsin Alam <tahsin.alam@db.com>
⎝⎠ Fri, 30 May 2008 13:03:49 -0400

   As the subject says - why does the following expression give
   error when I try to evaluate it in the *scratch* buffer?

   ((lambda (x) (x 2)) (lambda (n) (+ n 3)))

One reason is because Emacs Lisp is not Scheme (sigh).
You can try this, instead:

(funcall (lambda (x) (funcall x 2)) (lambda (n) (+ n 3)))

thi




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: newbie questions: why doesn't ((lambda (x) (x 2)) (lambda (n) (+ n 3))) work in elisp?
       [not found] ` <mailman.12481.1212216300.18990.help-gnu-emacs@gnu.org>
@ 2008-05-31  8:58   ` Johan Bockgård
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Bockgård @ 2008-05-31  8:58 UTC (permalink / raw)
  To: help-gnu-emacs

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

> ⎛⎞ Tahsin Alam <tahsin.alam@db.com>
> ⎝⎠ Fri, 30 May 2008 13:03:49 -0400
>
>    As the subject says - why does the following expression give
>    error when I try to evaluate it in the *scratch* buffer?
>
>    ((lambda (x) (x 2)) (lambda (n) (+ n 3)))
>
> One reason is because Emacs Lisp is not Scheme (sigh).
> You can try this, instead:
>
> (funcall (lambda (x) (funcall x 2)) (lambda (n) (+ n 3)))

The first funcall is unnecessary.

-- 
Johan Bockgård


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-05-31  8:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-30 17:03 newbie questions: why doesn't ((lambda (x) (x 2)) (lambda (n) (+ n 3))) work in elisp? Tahsin Alam
2008-05-31  6:41 ` Thien-Thi Nguyen
     [not found] ` <mailman.12481.1212216300.18990.help-gnu-emacs@gnu.org>
2008-05-31  8:58   ` Johan Bockgård
     [not found] <mailman.12463.1212181801.18990.help-gnu-emacs@gnu.org>
2008-05-30 21:27 ` Joost Diepenmaat
2008-05-30 21:33   ` Joost Diepenmaat

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.