On Mar 20, 1:52 pm, Glen Rubin <[email protected]> wrote:
> Hey all,
>
> I am working through the problems on project euler. On question
> number 11 (http://projecteuler.net/index.php?section=problems&id=11),
> I was unable to come up with a solution, so I cheated and looked at
> some other people's answer's here:
> http://clojure-euler.wikispaces.com/Problem+011
>
> Unfortunately, I am so dumb I cannot even understand the solutions
> very well...hahhaha. The first solution on that page defines the
> following function:
>
> (defn select-dir [array x y ncol span fnx fny]
> (when (not (zero? span))
> (lazy-cons
> (array-get array x y ncol)
> (select-dir array (fnx x) (fny y) ncol (dec span) fnx fny))))
>
> Right off the bat, I am wondering what is lazy-cons? I could not find
> it in the api.
That's because it has been removed. It became obsoleted by seq
behaviour changes sometime before 1.0 was released.
a more up-to-date version of that would be:
(defn select-dir [array x y ncol span fnx fny]
(when-not (zero? span)
(lazy-seq
(cons (array-get array x y ncol)
(select-dir array (fnx x) (fny y) ncol (dec span) fnx
fny)))))
Another approach that is common when constructing lazy seqs,
forming a closure over the constant parameters:
(defn s-dir [array x y ncol span fnx fny]
(letfn [(worker [x y span]
(when-not (zero? span)
(lazy-seq
(cons (array-get array x y ncol)
(worker (fnx x) (fny y) (dec span))))))]
(worker x y span)))
--
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
To unsubscribe from this group, send email to
clojure+unsubscribegooglegroups.com or reply to this email with the words
"REMOVE ME" as the subject.