Hello James,
Thank you for more examples.
> > (count (take-while belowCount (filter identity (map isInteresting
> > pixels))))
> This particular piece of code doesn't look like it would work, unless
> I've misunderstood what Vlad is asking. I think you'd want something
> more like:
If I understood the Patrick's code right, it works as:
1. The (map isInteresting ...) returns lazy sequence of true/false
values for each pixel (true for interesting pixel)
2. The (filter identity ...) returns a lazy sequence of only true
values from the above
3. The (take-while belowCount ...) will return items of lazy sequence
while the predicate "belowCount"
holds. This implies that the predicate would have to be stateful
(i.e. increment a counter
on each invocation and return false when this counter == count-I-
am-interested-in . So the
take-while "stops" once the count is reached
4. the result of (count ...) would be compared with count-I-am-
interested-in and if ==, the image is
"interesting"
> (defn interesting? [pixels c]
> (>= c (count (take c (filter in-interval? pixels)))))
>
> Where c is the number past which an image is considered "interesting".
> However, if c is very large, then (take c ...) is going to result in a
> large sequence.
The large sequence should not be a problem for this particular
application.
> We'd probably want to define a function:
>
> (defn count-more-than? [n xs]
> (or (zero? n)
> (if (seq xs)
> (recur (dec n) (rest xs)))))
>
> (defn interesting? [pixels c]
> (count-more-than? c (filter in-interval? pixels)))
Cheers, I will try to code different variants, see how fast they are,
+ report back at some point with the findings.
Kind regards,
Vlad
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---