Using core.logic, I sometimes have the need to create a variable number of
fresh lvars.
For example, I want to create all possible combinations of "n" numbers
between "min" and "max". Currently the only way I found how to do this was
building the expression and evalling it:
(defn generate-symbols [n]
(for [i (range 0 n)]
(gensym 'x)))
(defn distinct-numbers [n min max]
(let [lvars (generate-symbols n)]
(eval
`(run* [q#]
(fresh [~@lvars]
(infd ~@lvars (interval ~min ~max))
(distinctfd [~@lvars])
(== q# [~@lvars]))))))
Is there a better way to do this?
Kind regards,
Frederik
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en