3 ms·
> misconception that Lisp macros are mostly used to 'delay' evaluation. It was in the examples. No generalization to all of LISP was made or intended, though
by mpweiher 8y ago
> misconception that Lisp macros are mostly used to 'delay' evaluation.
It was in the examples. No generalization to all of LISP was made or intended, though it would be interesting to make a survey study of actual macro usage by developers.
It is also clear that you actually need the delay-evaluation mechanism in order to get something like "if" out of the language and into the library.
> what Smalltalk calls 'blocks' are just (anonymous) functions in Lisp
"but blocks/anonymous functions seem quite different from alternate argument-passing mechanisms."
I think the history also explains why Smalltalk blocks were a bit odd as anonymous functions go: they did not start out as a "function" mechanism, they started out as just a delayed evaluation mechanism, and Smalltalk has no ordinary functions, just the anonymous kind. Which is also odd.
The Smalltalk developers were well aware of LISP, cite it as a major source of inspiration in fact. They initially had a more macro-ish mechanism (the unevaluated token-stream), then moved to a pure delayed-evaluation mechanism which then turned into blocks. They never added a macro mechanism again. I think that's interesting. YMMV.
- lispm 8y ago> It is also clear that you actually need the delay-evaluation mechanism in order to get something like "if" out of the language and into the library. In a functional programming language one can just use functions. (defun l-true (a b) a) (defun l-false (a b) b) (defun l-if (f a b) (funcall f a b)) True is a function, false is a function and if is a function. Now we can do conditional execution: CL-USER 57 > (l-if #'l-true 1 2) 1 CL-USER 58 > (l-if #'l-false 1 2) 2 CL-USER 59 > (funcall (l-if #'l-true (lambda () (print 'true-case) nil) (lambda () (print 'false-case) nil))) TRUE-CASE NIL But Lisp doesn't do that. It provides one conditional as a primitive.
- mpweiher 8y ago>> need delay-evaluation [for "if" in lib] > one can just use functions Yes. Obviously. Of course. That's how Smalltalk does it, though it doesn't have general functions, it only has anonymous functions aka (roughly) blocks. Any other language that can pass functions or some sort of equivalent as arguments can obviously also do this. Heck, you can even do this, horribly, in C: #include <stdio.h> void a() { printf("true\n"); } void b() { printf("false\n"); } typedef void (*fnfn) (); void fnif(int cond, fnfn trueCase, fnfn falseCase ) { fnfn switcher[2]={ falseCase, trueCase }; switcher[cond](); } int main(int argc, char *argv[] ) { fnif( 0, a,b ); } (A little surprised that this compiled on the first try. More surprised that clang didn't show any warnings, even with -Wpedantic. Shows you how well I understand C/C compilers ¯\_(ツ)_/¯ ). And function definitions, lambdas, blocks etc. all delay the evaluation of their bodies.
- chriswarbo 8y ago`if` has two distinguishing features: - It selects between two possibilities - The non-selected possibility isn't evaluated/executed (i.e. the evaluation of the possibilities is delayed until after one has been selected) This is very important for imperative languages, since executing both branches would have observable effects even if we only returned one result. This is also true in functional programming languages, even pure ones, since it's needed to e.g. terminate recursive calls. For example, if we define factorial by branching on whether the argument is 0 (base case) or not (recursive case), then evaluating both branches before selecting one would cause an infinite recursion for all arguments. In the case of your Lisp code, we couldn't implement a recursive function like factorial unless we delay the evaluation e.g. by using macros to do the selection, or by switching from Lisp's default evaluation order (call-by-value) to something non-eager like call-by-name or call-by-need.
- EdwardCoffin 8y ago> they did not start out as a "function" mechanism, they started out as just a delayed evaluation mechanism Do you have a citation for this? Not disputing it, I'd just like to see whether there's something in Smalltalk's history I have overlooked, or didn't notice on my first reading.
- mpweiher 8y agoThat was what the article was about. The scans link to the source material Smalltalk-80: Bits of History, Words of Advice, one to the book on Amazon, the other to a PDF scan. Quite frankly, I was a bit surprised so much of the discussion has been about LISP features that are neither in dispute nor subject of the article.
- EdwardCoffin 8y ago> they did not start out as a "function" mechanism, they started out as just a delayed evaluation mechanism I still don't see where you are getting this from. The scans you provide [1] don't make this claim. For instance, look at page 17 of Technical Characteristics of Smalltalk-76 [2]: > heights _ students transform each to each height The document seems to have some OCR problems - I'm pretty sure that underscore is meant to be a left arrow, or := in more modern Smalltalks. I understand this to be the equivalent of Smalltalk-80's > heights := students collect: [:each | each height]. which is clearly a mechanism for mapping a function over a collection, not just a delayed evaluation mechanism. [1] You might add to your article a footnote specifying that the citations from Bits of History, Words of Advice are from pages 14-15 [2] http://xeroxalto.computerhistory.org/Filene/Smalltalk-76/.syntax.press!1.pdf http://xeroxalto.computerhistory.org/Filene/Smalltalk-76/.sy...
- EdwardCoffin 8y ago> Quite frankly, I was a bit surprised so much of the discussion has been about LISP features that are neither in dispute nor subject of the article. It's because Lisp macros and their motivations were described inaccurately, and some people want to make sure that these inaccuracies are not perpetuated.