Sam
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
- James
Great work. Has the updated version been pushed to clojars yet? Or do I
need to git pull and build manually?
--
Omnem crede diem tibi diluxisse supremum.
You just touched on an idiom I see fairly often here that bugs me. I'm
not intentionally singling you - or CQL! - out for this, but you made
a comment that sets up my question perfectly.
> (let [photo-counts (-> (table :photos)
> (aggregate [[:count/* :as :cnt]] [:id])))]
> (-> (table :users)
> (join photo-counts (= {:users.id :photos.id}))
>
> I think thats really as simple as you can express that join operation.
Um, I can see two macros that, if expanded in place, would result in a
simpler expression (assuming that CQL doesn't redefine ->):
(let [photo-counts (aggregate (table :photos) [[:count/* :as :cnt]] [:id])]
(join (table :users) photo-counts (= {:users.id :photos.id})))
I also fixed the parens - I think. I removed one after [:id], and it
seems like two were missing at the end as well.
Ok, I understand why you would use -> if you're threading through
multiple forms. I don't know that I like it, but I can at least
understand it. But when it's only one form? In the best case - when
the form is a symbol, as in (-> 1 inc) - it just wastes three
characters to reverse the form and argument. More often - for example
(-> 1 (+ 2)) - it also adds another level of parenthesis, which I
thought most people considered a hindrance to comprehension.
Could someone explain where this urge to write (-> expr (func arg))
instead of (func expr arg) comes from?
<mike
--
Mike Meyer <m...@mired.org> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
I like to use -> and ->> because they allow me to add more steps to
the "pipeline" as needed, without requiring ever more deeply nested
parentheses. Of course, the examples you cited were intentionally
trivial, but in a setting where you either have many consecutive
transformations on a piece of data, or you *expect* that these
transformations will grow numerous in the future, threading can help
keep the visual and cognitive complexity down. One could probably say
it makes nested s-exprs more scalable ;-)
Interestingly, in languages that prefer dot (.) method call notation
instead of prefix notation, the issue hasn't ever come up for me
because one generally doesn't have a choice. Take Pythons SQLAlchemy
as an example:
Customer.query.filter_by(validated=True).group_by('customer_gender').add_column(func.count()).values(Customer.customer_id)
Pretty neat, isn't it? The threading operators nicely introduce this
style of writing into the world of prefix notation.
> On 24 November 2010 21:40, Mike Meyer
> <mwm-keyword-goo...@mired.org> wrote:
> > Could someone explain where this urge to write (-> expr (func arg))
> > instead of (func expr arg) comes from?
>
> I like to use -> and ->> because they allow me to add more steps to
> the "pipeline" as needed, without requiring ever more deeply nested
> parentheses. Of course, the examples you cited were intentionally
> trivial
Those cases weren't "intentionally trivial", they were the
point. What's the motive for using -> when there's only one form after
the expression? I get why you'd do it with two or more forms - it
reduces the nesting, and reading left-to right follows the evaluation
order. But with just one form it's liable to have the opposite effect
on nesting, and it makes the evaluation order read zig-zag.
On Wed, 24 Nov 2010 22:51:09 +0100Those cases weren't "intentionally trivial", they were the
Daniel Werner <daniel....@googlemail.com> wrote:
> On 24 November 2010 21:40, Mike Meyer
> <mwm-keyword-goo...@mired.org> wrote:
> > Could someone explain where this urge to write (-> expr (func arg))
> > instead of (func expr arg) comes from?
>
> I like to use -> and ->> because they allow me to add more steps to
> the "pipeline" as needed, without requiring ever more deeply nested
> parentheses. Of course, the examples you cited were intentionally
> trivial
point. What's the motive for using -> when there's only one form after
the expression? I get why you'd do it with two or more forms - it
reduces the nesting, and reading left-to right follows the evaluation
order. But with just one form it's liable to have the opposite effect
on nesting, and it makes the evaluation order read zig-zag.
I'm experimenting with ClojureQL for accessing Postgis, the spacial
extender for Postgres. To improve the ClojureQL for this use case, it
would be useful to have a way to add custom predicates. For example to
find all places whose location column intersect with a polygon, you
can use a query like this:
SELECT * FROM place WHERE ST_Intersects(location,
ST_GeographyFromText('SRID=4326;POLYGON((33 38,34 38,34 39,33 39,33
38))'))
It would be nice, if I could write that as
(-> places (select (where (st-intersects :location polygon))))
Is there a way to do this (or something similar) in ClojureQL or is it
planned for a future version?
Janico
Yes, that works nicely. Thank you. I didn't realize you could use a
function that returns a string as a predicate.
Janico