3 ms·
Flippant response: you're saying that nothing was added to Closure in order for some Closure code to get written? This is not unprecedented. Seriously - I don'
by confuzatron 16y ago
Flippant response: you're saying that nothing was added to Closure in order for some Closure code to get written? This is not unprecedented.
Seriously - I don't see what's unusual about the syntax of these examples that makes them a DSL that doesn't just look like clojure code.
If my Linq implementation is allowed to resemble the language for which it is implemented, then I can easily write a 'Linq' implementation in plain C# that will look just like plain C#. (Although I grant that LINQ refers to the syntax additions to C# and not just the library)
Not hugely worked up about this, just feeling a little 'Emperors New Clothes' about it.
- mquander 16y agoHere's the "LINQ" of Common Lisp, which may look "different" enough to convince you: http://www.unixuser.org/~euske/doc/cl/loop.html http://www.unixuser.org/~euske/doc/cl/loop.html (It could be implemented identically in Clojure, if you cared to.)
- confuzatron 16y agoThanks. To my untrained eye that looks more like it could be called a DSL than the article, where mostly it's just creative whitespace formatting, as far as I can tell. What's going on with the underlining?
- mquander 16y agoRe: the underlining -- no idea, just an instructional aid, I guess. Here's another example that might look "DSLy": http://www.brool.com/index.php/pattern-matching-in-clojure http://www.brool.com/index.php/pattern-matching-in-clojure The pattern matching macro "match" is written entirely in Clojure, without any compiler tricks. I wish I could do the same in C#! (I'd need to have a bunch of cruft defining a predicate object with options for each match criterion.) All of these techniques boil down to how easy it is to do two things in a language: - To write DSL code in your structure of choice without having to cover it in a huge amount of syntax goop, e.g. the loop macro or the magic LINQ syntax. - To analyze and transform that DSL code programmatically, in a way that's more structured than simple string manipulation, so that you can do the right thing with it. C# 2.0 was very bad at both of these. C# 3.0 improved a lot, by adding lambda expressions for the first, and allowing you to analyze C# expressions as a syntax tree. But Clojure (& Lisp in general) is really good at both.
- grayrest 16y agoThe point wasn't to make it not look like Clojure, the point was to express querying constructs in a way that's natural to the language. This isn't impossible in any language and is actually fairly common within the domain (e.g. SQLAlchemy for Python works similarly though operator overloading). The point he's trying to make is that the default way of doing things in a lisp is to adjust the language constructs to fit the domain of the problem. This (generally) results in a simpler mental model of the problem domain and less code. It's not a about being ABLE to do it. You can do something similar in most languages, but there it's just not as easy, not the default, and not as flexible.
- confuzatron 16y agoYou might be right, but if so it sounds like the talk of Linq, and syntax, and 'DSL's served to obscure his actual point, which is a shame. Guys, honestly, downvote if it makes you feel better.