4 ms·
> Obviously not having macros is a given in anything but Lisp At least these languages (that I know of) have macros: http://boo.codehaus.org http://ne
by bad_user 16y ago
> Obviously not having macros is a given in anything but Lisp
At least these languages (that I know of) have macros:
http://boo.codehaus.org
http://nemerle.org
http://www.perl6.org
- poet 16y agoIf your language doesn't have Lisp syntax (or more precisely, a lack of syntax entirely) writing macros will be very unpleasant. How are you going to logically think about manipulating the structure of a program that looks like C# or Perl? Macros are already difficult enough to get right as is, without introducing the problem of syntax. Those languages don't have macros any more than Python has a lambda.
- chromatic 16y agoHow are you going to logically think about manipulating the structure of a program that looks like C# or Perl? In Perl 6, you extend the active grammar within a delimited scope.
- poet 16y agoMy point still holds, just replace manipulating the structure of a program with manipulating the structure of a grammar. In no way is that comparable to manipulating raw parse trees.
- bad_user 16y agoBut you are manipulating parse trees: surely you have to add new grammar rules to the parser, but then the macro itself does just that. Furthermore, when adding syntax you are not limited to a Lisp-style grammar.
- draegtun 16y agoFurthermore, when adding syntax you are not limited to a Lisp-style grammar And this is a very good point because you can add things like XML grammar to Perl6: http://github.com/krunen/xml http://github.com/krunen/xml
- poet 16y agoFurthermore, when adding syntax you are not limited to a Lisp-style grammar. You aren't limited to Lisp-style grammar in Lisp either. You can write reader macros if you have to. The point is, that on a basic level manipulating s-expressions is far easier to think about than manipulating the syntax of whatever the flavor of the day language is. You're essentially trying to invent reasons why macros in other languages are the same as Lisp macros and it's simply not true.
- sedachv 16y agoLisp macros manipulate Lisp code once it has been read (parsed and tokenized into lists) and sometime before it is executed. That has nothing to do with grammars. Common Lisp also offers a facility to augment or replace the parsing and tokenizing mechanism in an unrestricted fashion.
- drcode 16y agoTrue, but the syntax for all three of these is pretty hairy. Lisps might not be the only languages with macros, but they're the only ones with elegant and easy to use macro systems. You could argue of course this is a moot point, since even Lispers only write macros infrequently. So who cares if it's hard to write one on the rare occasion you need to?
- poet 16y agoYou could argue of course this is a moot point, since even Lispers only write macros infrequently. This simply isn't true. In fact it's so far from the truth it hurts my brain. Well written Lisp applications are in large part (and sometimes mostly) macros. PG once mentioned that the ITA guys said over half of their codebase is (was?) macros.
- drcode 16y agoCan you find the quote? I'd be surprised to learn that. For my own code, it consists of maybe 10% macros. I would say the same is true for PG's code (for the hacker news app- The arc core libraries have more macros but are a special case.) Unless, of course, if you mean _calling_ macros- I would agree that Lisp code often has 50% of its calls be macro calls instead of function calls.
- technomancy 16y ago50% code by volume being macros sounds terrifying. Macros are like 2nd-amendment rights. You hope you never have to use them, but when you do you'd be in a world of hurt without them.
- technomancy 16y agoFactor supposedly has macros; from my cursory knowledge of the language I could see them being as convenient as Lisp.
- silentbicycle 16y ago