9 ms·
> Because a language without macros is a tool: You write application with it. A language with macros is building material: You shape it and grow it into your ap
by gavinpc 12y ago
> Because a language without macros is a tool: You write application with it. A language with macros is building material: You shape it and grow it into your application.
Is this the OP's analogy? It's quite interesting.
- mrottenkolber 12y agoNot really. (Common) Lisp is often referred to as a "Building material". "Growing the language toward your problem" is a common Lisp design pattern.
- nnq 12y agoAlan Kay said about Lisp: "Lisp isn't a language, it's a building material." ...in a positive sense, because he was also quoted describing Lisp as "the greatest single programming language ever designed", though I bet this was not in a Lisp vs. Smalltalk comparison :)
- lispm 12y agoHere is another quote, this time from Alan J. Perlis: > Pascal is for building pyramids imposing, breathtaking, static structures built by armies pushing heavy blocks into place. Lisp is for building organisms imposing, breathtaking, dynamic structures built by squads fitting fluctuating myriads of simpler organisms into place.
- AnimalMuppet 12y agoThis is a standard Lisp idea, but I think it's kind of off base. Lisp has this idea of creating a language in which you can solve your problem. That's fine, but the Lisp people mean something rather different than the rest of us do. When I "create a language to solve a problem" in, say, C++, I create some nouns (objects), some verbs (methods), maybe some adjectives (other objects or flags) and adverbs (more flags). Then I can write my application using that "language", but using normal C/C++ syntax. When Lisp people say "create a language to solve a problem", they mean "write completely different syntax". The article gives some examples. Why would I want to do that? Well, I might want to explore a new paradigm - some new thing like aspect oriented programming, say. I don't have to wait for a language that implements it, I can just do it myself. This is great for academic research projects, but not nearly so great for production code. (Bringing new people up to speed becomes a much longer process, if your code outlives the original developers.) But I might have to create new language features just to get anything done in Lisp. One example is LOOP. It's a macro, because Lisp without macros doesn't have very good looping ability. "It's a building material" partly in this sense: It's not a very good tool. It's not all that usable until you add the parts that, in most other languages, you already get. Now, does LOOP do more than a C-style for or while loop? I doubt it, but perhaps it does it more neatly. But C gives you 90% of what you need without a macro, whereas Lisp gives you 10% without a macro. If you need more in C, you can do it, even if it's a bit clumsy. But in Lisp without macros, it's horribly clumsy all the time. (Yes, I know that there are Lisp and Haskell types who seem to regard writing a for loop over a container as a great waste of programmer time. I think that they are mistaken.) You can do some amazing things with Lisp macros. Paul Graham gives the example of writing an extension language for Viaweb that Lisp macros turned into Lisp code, which was then run on the server. That's really slick (though in the current situation, you have to watch out for security issues unless you validate that file very carefully). But if he had chosen another approach, what would change? The macros have to turn the file syntax into Lisp syntax. If he had written an ordinary parser, he would have had to do the same. The only difference is that, by using macros, he let the Lisp compiler do the grunt work of the parsing. TL;DR: Lisp needs macros to be usable. I'm not convinced that C does.
- ExpiredLink 12y agoDon't you know that it's strictly verboten to even remotely criticize Lisp in this forum?
- AnimalMuppet 12y agoYou can usually get away with it if you have actual thought in your criticism. But then, you have to be prepared for actual thought in the replies. You may have to learn something, or even - horrors - change your mind...
- gjm11 12y ago> But I might have to create new language features just to get anything done in Lisp. One example is LOOP. LOOP is a standard part of Common Lisp, so whatever it is it can't be an example of how Lisp-as-it-comes isn't good enough and you need macros to bring it up to standard. > Now, does LOOP do more than a C-style for or while loop? I doubt it In the sense in which a C-style for or while loop doesn't do more than goto, you're correct. Otherwise, of course you're incorrect; LOOP does a lot more than for and while do. (Random example: (loop for i from 1 to 10 collect (* i i)) makes a list of squares. No instance of C's for or while does anything like this.) > Lisp needs macros to be usable. I'm not convinced that C does. Could you give an example of something that C lets you do "out of the box", that Lisp (let's say specifically Common Lisp) doesn't, but that Lisp could be made to do using macros? I don't think I can think of any; there are things you can do better in C than in Lisp (e.g., close-to-the-metal bit-twiddling, or interfacing with other things written in C) but they don't have anything to do with macros.
- AnimalMuppet 12y agoLOOP is a macro, right? It's a standard macro, sure. But the point isn't standard vs. non-standard, the point is macro vs. non-macro. Without any macros, Lisp can't do loops very well. That's my point - Lisp without macros isn't very useful. >Random example: (loop for i from 1 to 10 collect (* i i)) makes a list of squares. No instance of C's for or while does anything like this. for (int i = 1; i <= 10; i++) list.push_back(i * i); Yeah, it's C++ using STL rather than straight C. (I suppose you could argue that C lacks a list type and therefore isn't very useful... but I could create a linked-list struct and write a push_back function. For that matter, I could just have int list[11]; for (int i = 0; i <= 10; i++) list[i] = i * i; I don't really think that list-vs-array is really relevant to the relative power of the loops in C and Lisp.) > Could you give an example of something that C lets you do "out of the box", that Lisp (let's say specifically Common Lisp) doesn't, but that Lisp could be made to do using macros? Well, macros produce Lisp code, so there is nothing that you can write in a macro that you cannot write in straight Lisp. But in non-macro Lisp, loops are really painful to write - the LOOP macro is part of the standard for a reason.