Hi,

lazy-seq to the rescue:

(defn mouse-seq
  []
  (lazy-seq
    (when (Mouse/hasEvent)
      (cons (Mouse/getEvent) (mouse-seq)))))

Sincerely
Meikel

Am 07.05.2009 um 23:40 schrieb CuppoJava:


Yeah (pred) is not supposed to depend on any items inside f.

This is why (take-while pred (repeatedly f)))
won't work in this situation.

(take-while) will always take an element out of f, so that it can be
tested using (pred). I don't want any elements of (f) to be looked at
if (pred) is false.

----USE CASE----
I'm using it in combination with some Java libraries. The following
seems like a very clojure-ish way of doing things.

(for [:while (Mouse/hasEvent)] (Mouse/getEvent))

so this returns a nice lazy stream of mouse events, which can be
processed however i like.
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to