And of course, this isn't an attack on lisp. If it works for you, cool. But I just don't see how that distinguishes itself from a ruby DSL like say rspec.
I think the nicest feature of lisp DSLs is that lisp doesn't have the concept of an operator, and most langaguages make if difficult to define a function called or <- or something like that. But you can do that in Haskell or or ML, it's not really exclusive to S-exps.
In most other languages, if that sort of transformation is even possible, it is much less direct.
(1 + 2) (x = 1 + 2)
It needs to be something like
(!! 1 + 2)
And you need to have spaces.
(1+4/5)
Won't work.
And operator precedence is do-able, but a bitch.
Etc... Etc...
As for the issue of spaces, 1+4/5 is just a symbol, which you can interpret as a string, which you can then parse back to symbols.
All that said, if I really wanted infix math, I would probably just make something that interprets this:
{1 + {2 / 3}{4+5}}
Or if I really love my parentheses... (!! (1 + (2 / 3)(4+5)))You can write a parser in any language; nothing magical about Lisp there.
Your statement is correct; it is just misleading. First, it is irrelevant in that we are talking about parsing the syntax of your language and producing code; not "any language" can do that. You would also have to write an eval for the many languages that do not have an eval. See SICP for an introduction to eval-apply logic.
Second, it disregards ease of parsing. It is easier to write a parser in Lisp to translate Lisp-like syntax into Lisp code than to write a parser in another language to translate that language's syntax into that language's code (and exceptions to this are because the language was based on Lisp). This has to do with basic Lisp syntax being a syntax tree and is aided by the CL standard providing many tools for parsing.
So yes, you can complicate things a bit by mashing your symbols together, but that's just one extra parsing pass (insert spaces around operators). One READ-FROM-STRING later, and you have a symbol tree. In another language, it might be a series of complicated lexx statements and functions where the language relearns how to do simple addition.
Yeah, that's a neat thing about lisp, but it wasn't what the OP really said - he was talking about parsing a random string.
Incidentally, I would be curious to get a design guy - one who really knows little about code - to look at blocks of code in different languages and give us his opinion. I have suspicions about what he might say, but it'd be a fun experiment.
(def && #(and % %2))
(def || #(or % %2))
(def *rank* (zipmap [- + * / < > && || =]
(iterate inc 1)))
(defn- infix*
[[a b & [c d e & m]]]
(cond
(vector? a) (recur (list* (infix* a) b c d e m))
(vector? c) (recur (list* a b (infix* c) d e m))
(ifn? b) (if (and d (< (*rank* b 0) (*rank* d 0)))
(recur (list a b (infix* (list* c d e m))))
(recur (list* (b a c) d e m)))
:else a))
(defn infix [& args]
(infix* args))
* from my unfix lib http://fogus.me/fun/unfixI'm not sure why people repeat that, but Lisp has syntax ...
In the same way Xml, Yaml, Json have syntax ... plus it has operators that do stuff, like: quote / eval / for defining methods / for defining macros.
Sure, a serialization format for what are basically syntax-trees is lighter than for a language that requires a LALR parser ... but you have to limit yourself to that serialization format in your DSLs.