Hacker News new | past | comments | ask | show | jobs | submit login

Clever, as usual. But, this could have been done in far less code in a language that already supports term rewriting, such as Mathematica.



Funny story--I am also a (recovering) Mathematica programmer! I'm not sure it's quite as good of a fit, for a few reasons.

One is that Mathematica's syntax is, in a lot of ways, already pretty C-like. It uses mutable assignment `x = y`, function-arglist syntax `Fun[arg1, arg2]` instead of a Lisp-style `(f arg1 arg2)`, commas for list separators (in Clojure, they're whitespace), braces `{a, b, c}` are a sequential construct, rather than a map, and semicolons `first ; second ; third` denote sequential expressions (in Clojure, ; is an end-of-line comment).

The second reason is that Mathematica, in my understanding, doesn't treat parentheses as first-class syntactic elements: they're used to control interpretation of the parse tree, but they transparently collapse, instead of being accessible as a reified type. (Are they? I know Mathematica is sort of an endless coal-mine of a language, and it's entirely possible I'm just not experienced enough to know about this!) If this constraint is true, I'm not sure how you would parse `func(arg1, arg2)` vs `func((arg1, arg2))`. Maybe it's inferrable from any symbol followed by a list, since `(arg1, arg2)` gives you a bounded context for the arglist, even if the parens disappear--and we can give up on having `(a,b)` for tuples or `()` as a unit syntax. It might also be inferrable from context, depending on what types of infix operators you allow, and how ; works as a separator. My license is long-since expired, so I can't test right now--perhaps you can give it a shot and show it off here!

I wound up cutting this from the post, but... the full version of this rewriter provides a Java-style OO syntax with property accessors and chainable method calls. A tricky thing in Mathematica might be disambiguating `obj.property` from `obj.method()`, if the `()` isn't reified. For that matter, what do you do about `fun` vs `fun()`...

One possible workaround might be to exploit (as I've done to hack around Clojure's insistence that "map keys be unique" and "maps have even numbers of elements") lesser-used Unicode codepoints, only this time, using alternatives for `(` and `)`, and to roll your own stack parser for arglist parsing... ideas, ideas. :)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: