core.logic has lazy-run. On Thursday, November 22, 2012, Jim foo.bar wrote:
> Hi all, > > this question may sound stupid but I've got to ask it.... > given a fn like the one below, how would one make it lazy (assuming that > it can be done)? > also if it can, I'd like to make it fully-lazy (instead of > chunked-lazy)...any ideas? I remember something about restoring '1 at a > time' laziness in the 'Joy of Clojure' but I 'm not sure if I rememer > correctly and I don't have access to the book at the moment (lent it to > someone for 2 weeks!)... > > (def ^:const board (vec (range 8))) > > (defn bishop-moves > "Returns the logical moves for a bishop (on a 8x8 grid) given its current > position and direction." > [x y] > (run* [q] > (fresh [a b] > (membero a board) > (membero b board) > (!= a x) > (!= b y) > (project [x y a b] > (== (Math/abs ^long (- x a)) > (Math/abs ^long (- y b))) > (== q [a b]))))) > > > the reason I want to do this, believe it or not, is performance !!! why > calculate all the moves if I'm not going to consume them all?it's a waste > isn't it? > > > many thanks in advance... > > Jim > > -- > 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<http://groups.google.com/group/clojure?hl=en> > -- 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