This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

A fundamental syntax confusion

3 posts · 2003 views

(defparameter *test-symbol*
  ((lambda (x) (format t "x: ~a~&" x) x)
   (lambda (y) (format t "y: ~a~&" y) y)))
I've come across a similar construct in someone else's code. It works, but I'm struggling to understand what does it do, and no luck so far :) Can someone, please, explain what is being saved into *test-symbol*? I could only figure so far that it is callable and what gets executed is the (lambda (y) ...), but what (lambda (x) ...) does and why it gets called when the entire construct is being defined is beyond me. Lastly, no matter what first lambda returns, the construct seem to generate no problems, however, if I replace the first lambda by it's return value, of course I get an error.

Thanks!

Re: A fundamental syntax confusion

There is a special evaluation for lambda (see the Notes in its specification). For instance:
((lambda (x) (+ x 3))
 5)
is the same as
(funcall #'(lambda (x) (+ x 3))
 5)
or
(let ((x 5))
  (+ x 3))
Your code is equivalent to
(defparameter *test-symbol*
  (let ((x (lambda (y) (format t "y: ~a~&" y) y)))
    (format t "x: ~a~&" x)
    x))

Re: A fundamental syntax confusion

Aha, thank you, that makes sense now!