6 ms·
Can a language have Lisp's powerful macros without the parentheses?
- BrandonM 20y agoIn a few of Paul Graham's essays and in some of my own experiences, I have found that Lisp is a very powerful language for hard programming problems, largely due to its powerful macro facilities. These macros give the programmer the power to create entirely new, domain-specific languages without too much difficulty. I am currently a Master's student and I hope to eventually be a founder, and my question is the title of this submission. I can understand why some people would shy away from Lisp, but I also see how many upcoming programmers appreciate the power of Python and Ruby. I believe, then, that the next big language will be one that combines the macros of Lisp with the ease of use of Python. I think that such a language would be perfect for startups. I am a glutton for punishment, so my graduate interests lie in programming languages. Here at Ohio State University, there is a language called RESOLVE that a lot of students don't like too much (it's built on top of C++ and is much too wordy), but it does have some interesting concepts built-in that I would like to put in a language of my own. In creating a new language, one of the things that would be first and foremost in my mind would be to ensure it had powerful macro capabilities, so I am interesting to hear your feedback on the viability of a language with powerful macros but fewer parentheses.
- richcollins 20y agoSee the Io programming language: "Io is a small, prototype-based programming language. The ideas in Io are mostly inspired by Smalltalk (all values are objects), Self (prototype-based), NewtonScript (differential inheritance), Act1 (actors and futures for concurrency), LISP (code is a runtime inspectable/modifiable tree) and Lua (small, embeddable)."
- inklesspen 20y agoYes, it can. http://www.livelogix.net/logix/intro.html http://www.livelogix.net/logix/intro.html Logix is built on Python and compiles down to Python bytecode, so you can use it with Python modules, but it has macros that I think are probably as powerful as Lisp's. It's meant for DSLs.
- mattculbreth 20y agoThanks for posting that. We're building a DSL for our users and this will get put on the stack of things to look into. We're Python hackers so it's a good find.
- BrandonM 20y agoI agree, thanks for the link. Unfortunately, I find the complete lack of syntax to make it even harder to read than Lisp macros (which I don't personally find difficult, but some do). Additionally, having to use numbers to indicate operator precedence seems a bit strange. Of course, Lisp solves this by always using parentheses, but I would be curious to see if there is a more elegant way of handling this than the numeric approach (or even the approach suggested in their proposed changes to Logix).
- raju 20y agoI agree with you. The lack of parentheses makes that hard to read. I am trying to get head wrapped around lisp (maybe thats it, I am _looking_ for the parentheses :)).
- brlewis 20y agoCould you give an example that's more powerful? From the 60-second intro you linked to, these look no more powerful than C's macros. http://en.wikipedia.org/wiki/C_preprocessor#Macro_definition_and_expansion http://en.wikipedia.org/wiki/C_preprocessor#Macro_definition_and_expansion
- inklesspen 20y agoI don't use it myself; I just had it in my bookmarks. I am also not very familiar with Lisp's macros. You may find something of interest in the more complete documentation. Sorry.
- pg 20y agoIt would have to have some notation for parse trees, and if that wasn't s-expressions, it would probably be something less convenient, not more.
- brlewis 20y agoThat's definitely true in terms of defmacro and syntax-case. However, I do think with some effort the scripting-language community could come up with something almost as powerful as syntax-rules from R5RS, thus catching up to where the Scheme community was in 1991. With syntax-rules the person writing the macro does not have to explicitly deal with the parse tree.
- Benja 20y agoBut, of course, you don't have to have code files full of parens in order to have s-expressions. Alternative syntaxes have never taken hold in the Lisp world, which may mean they just offer nothing to an experienced Lisp hacker, but they're certainly not impossible. You can have user-definable infix operators; Haskell has them and uses them to good effect. (The way Haskell does it, you can't have identifiers composed of both letters and operator characters, which Lisp people like to do, but I think we can safely treat that as a matter of taste.) You pick a symbol, say ~, and assign it a precedence and left- or right-associativity: infixr 3 ~ infixl 7 .!. Now (x ~ y .!. z) is parsed as ((~) x ((.!.) y z)), where (~) is the Haskell way of making the ~ operator as a prefix function. Haskell also lets you use a prefix function as an infix operator, by putting backquotes around it. If you want to apply this in Lisp, there is the issue that (foo) means something else than foo; I would like to allow (foo x + bar y) to mean ((+) (foo x) (bar y)), but I wouldn't want (x + y) to mean ((+) (x) (y)). My solution would be that a single value is parsed as just a value, but multiple values next to each other is a function call: (foo x + y) is ((+) (foo x) y), to call y without parameters you have to write (foo x + (y)). This leaves you with the parantheses for control structures and the like. If you like layout-based languages, you can adopt the rule that "expression + colon + newline + indented expression 1 + indented expression 2 + ..." is parsed as "expression (indented expression 1) (indented expression 2) ...". Some examples of code from On Lisp formatted like this: http://himalia.it.jyu.fi/~benja/2007/layoutedlisp.txt http://himalia.it.jyu.fi/~benja/2007/layoutedlisp.txt Of course, it still looks like Lisp, with less parens.
- dfranke 20y agoI've never understood why this is such a popular question. Remember this remark from The Matrix? "After a while you don't even see the code. All you see is blonde, redhead..." Well, after a while you don't even see the parens. All you see is closure, continuation... Seriously, just start reading On Lisp and by the time you're half-way through it you'll be at this point.
- BrandonM 20y agoOh, I totally get that. The "problem" is that of building languages on top of Lisp, which is really half of the point. The languages that can be trivially built on top of Lisp generally look like Lisp. I would like to be able to use a language with Lisp's capabilities to build a new language which looks completely different. I'm not really asking for an answer here; this is really just a thought exercise on my part that I thought I'd share.
- monty 20y agoMy favorite approach was detailed here: "Growing Languages with Metamorphic Syntax Macros" http://www.brics.dk/RS/00/24/ http://www.brics.dk/RS/00/24/ Monty
- richcollins 20y agoIn the io programming language you can generate code (message trees) at runtime and then eval them in any context that you want to. You can also pass messages trees (code) to a method without evaling it, and then modify it however you want beforing evaling it within whatever context you want.