Re: calling a clojure function within a quote/(')

2017-11-18 Thread Dustin Getz
Here is my attempt at gymnastics, exploits that < does indeed resolve to 
clojure.core/< in datomic query:

(def c 5)
[:find '?e :where ['?e :db/ident] [`(< ~'?e ~c)]]=> [:find 
?e :where [?e :db/ident] [(clojure.core/< ?e 5)]]
(d/q [:find '?e :where
  ['?e :db/ident]
  [`(< ~'?e ~c)]]
 $)
  => #{[1] [2] [3] [4] [0]}

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: calling a clojure function within a quote/(')

2017-11-18 Thread Dustin Getz
I wouldn't try to fight this battle, just parameterize the query

[:find ?e :in $ ?three :where
 [? :data/number ?number] 
 [(> ?number ?three)]]

http://docs.datomic.com/best-practices.html#parameterize-queries

*Datomic will cache queries, so long as the query (first) argument data 
structures evaluate as equal. As a result, reusing parameterized queries is 
much more efficient than building different query data structures. If you 
need to build data structures at run time for query, you should do so using 
a standard process so that equivalent queries will evaluate as equal.*

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: calling a clojure function within a quote/(')

2017-11-18 Thread Alex Baranosky
Also:

(cond-> query
true
(conj ['? :data/number '?number])
true
(conj [(list '> '?number (foo 2))]))

;; => [:find ?e :in $ :where w [? :data/number ?number] [(> ?number 3)]]

On Fri, Nov 17, 2017 at 8:44 PM, Matching Socks 
wrote:

> In the docs: "syntax quote" on https://clojure.org/reference/reader
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: calling a clojure function within a quote/(')

2017-11-17 Thread Matching Socks
In the docs: "syntax quote" on https://clojure.org/reference/reader

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: calling a clojure function within a quote/(')

2017-11-17 Thread Armando Blancas


user=> (cond-> query

  #_=> true

  #_=> (conj '[? :data/number ?number])

  #_=> true

  #_=> (conj `[(~'> ~'?number ~(foo 2))]))

[:find ?e :in $ :where [? :data/number ?number] [(> ?number 3)]]


On Friday, November 17, 2017 at 6:15:18 AM UTC-8, Njab Soul wrote:
>
> Hi guys I need your help.
>
> I want to make a clojure query, but the :where conditions are condition. 
> SO i used cond->.
> this works well. but now my problem is that I want to make a clojure 
> function call inside a (') or quote.
>
>
> (defn foo [num]
>
>   (inc num))
>
> (def query '[:find ?e
>   :in $
>   :where ])
>
> (cond-> query
> (some-condition) 
> (conj '[? :data/number ?number])
> (some-other-condition)
> (conj `[~'(> ?number ~(foo 2))]))
>
>
> I get this result:
> [:find ?e 
>   :in $ 
>   :where [? :data/number ?number] 
>   [(> ?number (clojure.core/unquote (foo 2)))]]
>
>
> What I am trying to achieve is this:
>
> [:find ?e 
>   :in $ 
>   :where [? :data/number ?number] 
>   [(> ?number 3)]]
>
>
> Can anyone please help
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


calling a clojure function within a quote/(')

2017-11-17 Thread Njab Soul
Hi guys I need your help.

I want to make a clojure query, but the :where conditions are condition. SO 
i used cond->.
this works well. but now my problem is that I want to make a clojure 
function call inside a (') or quote.


(defn foo [num]

  (inc num))

(def query '[:find ?e
  :in $
  :where ])

(cond-> query
(some-condition) 
(conj '[? :data/number ?number])
(some-other-condition)
(conj `[~'(> ?number ~(foo 2))]))


I get this result:
[:find ?e 
  :in $ 
  :where [? :data/number ?number] 
  [(> ?number (clojure.core/unquote (foo 2)))]]


What I am trying to achieve is this:

[:find ?e 
  :in $ 
  :where [? :data/number ?number] 
  [(> ?number 3)]]


Can anyone please help

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.