2

Why do some use #'(lambda instead of just (lambda in Common Lisp? Are there performance benefits or something?

Because, as Peter Siebel and others explain, in CL, "the following LAMBDA expression: (lambda () 42) expands into the following when it occurs in a context where it evaluated: (function (lambda () 42))".

NeuronQ
  • 7,527
  • 9
  • 42
  • 60
  • @RainerJoswig yeah, but there's really no "why" answer to that question! I understand how things work and the historical significance of it, but my questions was simply: is there still a legit reason so use `#'` lambda in modern CL? will other CL programmers look weird at my code if I just forget about this historical artifact? – NeuronQ Apr 13 '13 at 08:41
  • 1
    My answer to that other question touched that topic. Stackoverflow is not so much about discussing language feature usage. If you have an actual programming problem, post it. – Rainer Joswig Apr 13 '13 at 08:51
  • @RainerJoswig ok, thanks. since the question you linked answers the "what happens" part implied in my question and the "why" part is too philosophical for SO, then it should be marked as a duplicate of that question. – NeuronQ Apr 13 '13 at 08:55

1 Answers1

0

There is not performance benefits except few milliseconds of compile time vs few millisecods of read time :)

I think real reason is consistency. If one writes (mapcar #'myfunc ...) (not just (mapcar myfunc ...)), it is natural to write (mapcar #'(lambda ...) ...) too.

monoid
  • 1,661
  • 11
  • 16
  • uhm... it may look "consistent", but conceptually it's obvious that `#'myfunc` gives me the function object for the function names "myfunc" while `(lambda ...)` just gives me a function object. when I read `#'(lambda...)` I have to think of "getting the function object for the function with a name returned by lambda that I cannot actually ever see", which would actually be the semantic of it... and it just makes one's brain hurt! – NeuronQ Apr 13 '13 at 08:47
  • You don't have to think so :) – monoid Apr 13 '13 at 08:53
  • ...but this the only way I can think of `#'(lambda...)` without running into a contradiction, that's how my mind works :) otoh, anyone can jus think of plain `lambda` as something that returns the "function object", not a name that has to go thorugh `#'` or god knows what else. and as a bonus, it 2 less chars to type, on top of sparing me of the mental gimnastics :) – NeuronQ Apr 13 '13 at 09:00