3 ms·
It looks a lot like Clojure but I'm not sure it is. For example, this expression: (filter (> age 20)) That second form to filter should be a function, but in
by hellofunk 11y ago
It looks a lot like Clojure but I'm not sure it is. For example, this expression:
(filter (> age 20))
That second form to filter should be a function, but in this case it is an expression that returns a boolean and is not itself a function.
- j_m_b 11y ago>That second form to filter should be a function, but in this case it is an expression that returns a boolean and is not itself a function. I'm pretty sure this is Clojure or something very close to it. ->> is the thread-last macro. What it does is take the first expression, ($alice) and inserts it as the last expr in the next form so that the second step (assoc $friends) would eval to (assoc $friends $alice). It continues this by inserting this expr into the last part of the next form. So the example would reduce to: (filter (> age 20) (assoc $friends (assoc $friends $alice)))
- hellofunk 11y agoBut as I mentioned, the second argument to Clojure's filter is a function, and (> age 20) is not a function; therefore, this is not normal Clojure (or Clojure or at all). You'd have to replace the standard library's filter function to get the syntax you see in this article, which I doubt they are doing. therefore: not Clojure.
- emidln 11y agoYou could also walk the ast and do something special with unknown symbols (and functions that contain them). i.e. while walking, we notice a function (> age 20) and age isn't visible in scope. We thus rewrite that into something like (fn [age] (> age 20)) or (fn [x] (> (:age x) 20)). I've taken this approach before with DSLs. It makes for extremely fast to write business logic where business users don't have to care as much about where their data comes from (they just need field names).
- hellofunk 11y agoIn general code, that would be very hard to read, not knowing if a form represented an actual value or a function. Clojure being dynamically typed makes things hard enough; changing the language syntax as you describe sounds pretty risky to me.
- emidln 11y agoThe purpose of such a DSL isn't to let you write generic clojure faster. The DSL isn't even targetted at traditional programmers. The purpose is to enable training people who have no idea what Clojure or Lisp to get things done that are complicated (or expensive) to design graphical UX for. These people might have some excel experience or maybe a programming class in college, but are mostly reliant on examples and documentation to get things done. Why teach them things like how to create a function when they don't need to know or care? There is a huge usability difference for these people between (fn [age] (> age 18)) and (> age 18).
- adsharma 11y agoRight, it's not Clojure, but we tried to borrow some syntactical elements for readability. More discussion here: https://groups.google.com/forum/#!topic/clojure/P3eW6Vi2QcU https://groups.google.com/forum/#!topic/clojure/P3eW6Vi2QcU
- okram 11y agoIt has a very similar look and feel to Gremlin (http://tinkerpop.apache.org http://tinkerpop.apache.org). (->> ($alice) (assoc $friends) (assoc $friends) (filter (> age 20)) (count)) ...in Gremlin is: g.V(alice).out("friends").out("friends").has("age",gt(20)).count()