0

I thought that this is the only way to write self executing lambda expression in Common LISP:

(funcall #'(lambda (x) (format t "~S" x)) 10)

but it seems that this also work in CLISP on GNU/Linux:

((lambda (x) (format t "~S" x)) 10)

which is more like you do this in Scheme. Is this something that is correct according to Common LISP spec? Does other CL implementation also work this way.

2
  • The lambda expressions here are not self executing. The question is more about applying lambda expressions to arguments. You can also go with (#'(lambda ...) argument) Commented Jun 3, 2019 at 21:41
  • @XeroSmith you're right it should be called immediately invoked lambda expression like in IIFE in JavaScript (that also were called self in the years ago before they change the name). Commented Jun 4, 2019 at 6:45

1 Answer 1

6

That's standard Common Lisp syntax.

See lambda forms in Conses as Forms.

Sign up to request clarification or add additional context in comments.

4 Comments

Hyperspec if very confusing, I don't show any examples of stuff it explain.
@jcubic if you look under LAMBDA, there is an example: lispworks.com/documentation/HyperSpec/Body/s_lambda.htm
While it is allowed to have lambda form in operator position it isn't very useful. At best it replaces a let.
@Sylwester: the lambda form is for example used in macros, where it is sometimes less work to generate a LAMBDA form, than a LET form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.