bitemyapp / revise

RethinkDB client for Clojure
146 stars 8 forks source link

Implement "do" #12

Open danielytics opened 10 years ago

danielytics commented 10 years ago

http://www.rethinkdb.com/api/javascript/#do

I have looked at how the javascript and python drivers implement do and they implement it with funcall, however, I can't figure out how to actually use funcall from revise.

bitemyapp commented 10 years ago

@danielytics well, @cesarbp is the expert, but if I had to guess, it's just another protobuf entity.

danielytics commented 10 years ago

@bitemyapp it doesn't seem to be. I've checked the spec and there isn't an entity for it. The javascript and python drivers implement it in terms of FUNCALL. As far as I can see, revise already implements all of the protobuf entities.

cesarbp commented 10 years ago

What's really just missing is this function func_wrap

danielytics commented 10 years ago

Is compile-term essentially expr?

cesarbp commented 10 years ago

parse-val is the equivalent of expr iirc. But unlike the other drivers it is not needed because it is already implicit when parsing the arguments to a revise.query fn.

cesarbp commented 10 years ago

Actually nevermind. func-wrap appears to be the way the drivers use to turn an actual lambda into a rethinkdb lambda. This is much easier than I thought initially. The hard part is a decent name :-P.

Something like this might even work:

(defn placeholder
   [& args-and-fn]
  (let [f (last args-and-fn)
         args (butlast args-and-fn)]
    (apply funcall f args))
danielytics commented 10 years ago

Brilliant, that works! :+1:

I personally would call it something similar or related to do because it will make reading the RethinkDB docs and example code easier, but obviously that clashes with Clojure's do. Perhaps something along the lines of with?


EDIT: Moved question to #13

cesarbp commented 10 years ago

@danielytics You can probably just open another issue.

danielytics commented 10 years ago

Enlive has a similar function which it calls do-> - maybe that's a reasonable name for this? Though do-> threads the result, while this doesn't. Maybe do-let or doto? I also still quite like with.