3 ms·
Most of my work in Clojure these days involves implementing logic programming and state-of-art predicate dispatch. Both have numerous practical real world use c
by swannodette 15y ago
Most of my work in Clojure these days involves implementing logic programming and state-of-art predicate dispatch. Both have numerous practical real world use cases (I want them right now) and both would be near impossible to implement with acceptable syntax / performance in plain JavaScript.
Even more importantly this functionality can be provided to end users as libraries not as an alternate version of ClojureScript. For example, while I have a deep respect for CoffeeScript, these types of innovations are "ghettoized" in CoffeeScript because they require users to fork the compiler.
- jashkenas 15y agoGreat -- so if logic programming and predicate dispatch allow you to tackle problems that would otherwise be intractable in JS... Do you have an example of such a problem that you've used logic programming in Clojure to tackle? Perhaps a link to your code? I'd tend to give Turing-completeness a bit more credit where it's due, especially for flexible dynamic languages.
- apgwoz 15y agoI trust that you do understand the concept of compilation right? It'd be terribly difficult and tedious to implement JavaScript, for instance, in x86 assembly (but possible!), much like it would be to implement the things that David's logic programming and predicate dispatch in JavaScript directly. Having a language which supports syntactic abstraction allows you to hide away lots of the complexities and let the compiler generate them for you. It's no different than using C instead of x86, or Scheme to C to x86, or whatever other path to x86 you can think of.
- sitkack 15y agoI am pretty sure he understands compilation.
- fogus 15y agoI'd tend to give Turing-completeness a bit more credit where it's due Turing completeness is a fun topic for conversation, but it doesn't stand up to practical application. That is, every language has a point of diminishing returns regarding expressivity vs. possibility. JavaScript falls somewhere on the spectrum with things like Underscore.js and Coffeescript providing increasingly more bang for the buck. If you were truly such an adherent to the Turing completeness trap then I would be a sad panda without the clear expressivity gains that Underscore and Coffeescript provide.
- swannodette 15y agoWe've all written code like this: class Foo method bar(x) switch x case even? case odd? This is closed. What if I want to add a new case without modifying this class? I could subclass but then I have to know a lot about how Foo works. Perhaps bars has assumptions about whether it needs to run before or after I run my subclassed version, and on and on. This kind of nastiness pervades too much code. method bar Foo even?(x) method bar Foo odd?(x) ... As far as logic programming - I think the paradigm is so little known that people fail to see how useful it is. Yet many non-trivial programs use ... relational databases! How would you even begin to express the following idea in JavaScript? http://stackoverflow.com/questions/6713424/how-do-i-express-this-logic/6719627#6719627 http://stackoverflow.com/questions/6713424/how-do-i-express-... Note that the idea is actually quite simple and useful! Another example is to produce all words that form a specific telephone number: https://gist.github.com/1107653 https://gist.github.com/1107653 Of particular interest is the encode function, the relevant bit: (run* [q] (exist [x y xo yo] (appendo x y s) ;; infer all possible lists that could concat ;; to form s (wordo x xo) (wordo y yo) ;; convert to words (project [xo yo] (== q (apply str xo yo)))) ;; create the combined string Note I don't have to mention indices, for loops, list comprehensions or any other iterative machinery. All the other solutions I saw had a lot of boilerplate to express this simple idea of inferring the lists that could be concatenated to form s.