4 ms·
He writes a seductive argument, but it isn't very satisfying to conclude "this language is so powerful that it defeats itself". Likely there are other, more mun
by roenxi 9y ago
He writes a seductive argument, but it isn't very satisfying to conclude "this language is so powerful that it defeats itself". Likely there are other, more mundane reasons why the theoretical purity of the lisps isn't useful in practice.
For example, the endless (bracketing). My understanding is that the power of lisp macros comes from this questionable, but distinctively lispy, syntax. And I say questionable compared to natural human scripts - none of them work from inside to out. I've seen left to right (eg, English), right to left and up to down (eg, Chinese). If there were some better known examples of what lisp macros were good for then maybe it would get better traction. But lisp macros don't seem to have an example of why they are worth that trade.
Also, in the early days, C was a pretty close mirror to the underlying code execution - there was probably less mental overhead to squeezing out better performance.
- sbmassey 9y agoLisp is no more 'inside to out' than any other programming language, it just uses the same syntax for each subclause where other languages randomly choose different syntaxes for different kinds of expressions, so C if (a == 0) { printf("color %s", b[i]); } might be lispified (if (= a 0) (format t "color ~A" (aref b i)))
- FrozenVoid 9y agoA better example: #include <stdio.h> #include <stdlib.h> #define ifl(op,a,b, ctrue,cfalse) if(a op b){ctrue ;}else{cfalse ;} #define strtolong(x) strtol(x,NULL,10) int main(int argc,char**argv){ if(argc<3){ puts("2 args req"); exit(1);} ifl(>,strtolong(argv[1]),strtolong(argv[2]),puts("Arg1: > Arg2:"),puts("Arg1: <= Arg2:")); ;}
- coldtea 9y ago>For example, the endless (bracketing). My understanding is that the power of lisp macros comes from this questionable, but distinctively lispy, syntax. The endless bracketing is nothing more scary than the endless {} and () in a C, Java, C++, JS etc program.
- very_mediocre 9y ago> why the theoretical purity of the lisps isn't useful in practice. Saying it's useless may be too strong. People use it. You and I are using it right now to comment on HN. > But lisp macros don't seem to have an example of why they are worth that trade. This may be the core of your argument. Ok. Who has some examples to share?
- flavio81 9y agoLet me give you a simple example of the usefulness of macros. Consider _any_ boilerplate code that gets repeated on your application. You know how boilerplate code is not only tedious to write, but also creates a maintenance headache whenever you need to modify 'the boilerplate' and thus go copy-paste again through a lot of the code. Macros totally destroy boilerplate. They reduce boilerplate to exactly zero. The other usefulness is that, since they manipulate source code, they are more powerful than functions. That is, the macro can be seen as defining an ultra-powerful version of the function. This enables you to create functions (actually, macros) that do more than functions in other languages. Here is a simple example from Conrad Barski, who has a tutorial where one creates a text-only adventure. This code defines a specific action the user can perform. In this case, to "weld" a "chain" to a "bucket". (defparameter *bucket-filled* nil) (defun weld (subject object) (cond ((and (eq *location* 'attic) (eq subject 'chain) (eq object 'bucket) (have 'chain) (have 'bucket) (not *chain-welded*)) (setf *chain-welded* 't) '(the chain is now securely welded to the bucket.)) (t '(you cannot weld like that.)))) The code defines action "weld" for a subject and an object, but just specifically, for the subject that is "chain" and the object that is "bucket", at the location "attic". As you may infer, each time a new "action" needs to be defined (for a subject, object, in a specific location), a new function will have to be defined and this function will look pretty similar to the above. So after four or five actions you define, you will have lots of unnecesary boilerplate code. Enter macros. The programmer understands there is a "pattern" there, and creates a macro "game-action": (defmacro game-action (&key command subj obj place code) `(defmacro ,command (subject object) `(cond ((and (eq *location* ',',place) (eq ',subject ',',subj) (eq ',object ',',obj) (have ',',subj)) ,@',code) ;; expand the rest of the code (t '(i cant ,',command like that.))))) What this macro does is abstract this repetitive boilerplate and formalizes it. So now one can define the same "weld" game action like this: (game-action :command weld :subj chain :obj bucket :place attic :code (cond ((and (have 'bucket) (setf *chain-welded* t)) '("the chain is now securely welded to the bucket.")) (t '("you do not have a bucket.")))) As you can see, now: a. the definition of a game-action is much more easier to understand, b. boilerplate is reduced (it can be reduced even further in fact) c. and thus you can define more game actions in a more brief way. d. The code that verifies if the subject and object do exist, and if the place is correct, is abstracted away, so you can switch to different data structures in the future, yet your game-action definitions will need no change. Unlike the 'boilerplate' version which will need manual edition of all the game-action definitions. You can apply macros over macros, so there is no limit on the power of them.
- shakna 9y ago> that the power of lisp macros comes from this questionable, but distinctively lispy, syntax No. It comes from homoiconicity. In this case, everything is a list. Because Lisp has great support for modifying lists, you can do some wonderful things with it. Wisp [1] comes without parentheses, but still has the same macro system, and the same power. > If there were some better known examples of what lisp macros were good for When the language gets in your way. That's it. Everything else can be a lambda. Lisp macros only start to seem pointless, because Lisp itself is a flexible language. But, some real world macro examples? Mutating functions. (setf and the like.) Compile-time contracts. [0] You have a key-value list that you dynamically constructed, and want to bind it. Let can't just take a list, but a macro can handle it. Killing boilerplate, that involves bound values. (This one spoils you. Other languages become infuriatingly inflexible about it.) [0] Can't find the paper right now, but it relied on compile-time macros to validate types at compile time in a (large) subset of Common Lisp. [1] http://dustycloud.org/blog/wisp-lisp-alternative/ http://dustycloud.org/blog/wisp-lisp-alternative/
- TeMPOraL 9y ago> And I say questionable compared to natural human scripts - none of them work from inside to out. That's irrelevant. A better comparison would be to other programming languages, and in this case you'd notice that all popular languages are "inside-out". Consider, what's the order of evaluation in the following Java code? System.out.println(Frob.frobify(a + b, foo(), bar(baz())));
- qohen 9y agoIf there were some better known examples of what lisp macros were good for then maybe it would get better traction. But lisp macros don't seem to have an example of why they are worth that trade. FYI, Paul Graham's book, "On Lisp" covers macros in detail and is available as a free download here, if you are interested in the topic: http://www.paulgraham.com/onlisptext.html http://www.paulgraham.com/onlisptext.html The book's description [0]: On Lisp is a comprehensive study of advanced Lisp techniques, with bottom-up programming as the unifying theme. It gives the first complete description of macros and macro applications. The book also covers important subjects related to bottom-up programming, including functional programming, rapid prototyping, interactive development, and embedded languages. The final chapter takes a deeper look at object-oriented programming than previous Lisp books, showing the step-by-step construction of a working model of the Common Lisp Object System (CLOS). As well as an indispensable reference, On Lisp is a source of software. Its examples form a library of functions and macros that readers will be able to use in their own Lisp programs. [0] http://www.paulgraham.com/onlisp.html http://www.paulgraham.com/onlisp.html
- kazinator 9y ago> If there were some better known examples of what lisp macros were good for If there were better examples of what oscilloscopes are good for, every home would have one. Macros are a tools for programming the programming language, which makes them somewhat specialized. Good examples of macros are the ones which already exist; they are there for anyone to study: for instance the macros of the Common Lisp object system, the Common Lisp LOOP macro and such. > questionable compared to natural human scripts No successful, mainstream programming language follows human scripts. Even though human scripts appear linear, just laying words down in order, the underlying syntax is anything but linear. The syntax is very difficult and full of ambiguities that need a great deal of advanced semantic context to unravel. It is a poor model for designing programming languages. Programming languages designed to imitate natural language and scripts have been failures at best, and programmer laughing stocks at worst. > none of them work from inside to out. Most common, mainstream programming languages have expressions that work from inside out and so does math notation. C: { memcpy(get_address(x, y), z, get_size(x, y)); } Shell: FOO=$(basename "$(command x y)")/bar GNU Make: $(foreach F,$(SOURCES),$(addprefix foo/,$(F))) XML: <foo><bar>datum</bar></foo> > eg, Chinese Chinese characters, though, are built from radicals and components in a process that can is basically basically inside out. The elements can stack left-right or up-down, or be fully or partially enclosed, in what amounts to de facto a recursive generative process. See this famous, fairly complicated character: https://en.wikipedia.org/wiki/File:Bi%C3%A1ng.svg https://en.wikipedia.org/wiki/File:Bi%C3%A1ng.svg