Hello samppi,

You could try this, the list does not really contain itself, but it
builds lists that are like itself recursively:

;builds recursion into lists, like Y the combinator
(defn build-recursive-list [fun list]
   (fun (delay (build-recursive-list fun list)) list))

(def cyclic-list1
   (build-recursive-list
      (fn [self [a b c]] (lazy-cat [a b c] [(force self)])) [3 2 1]))

The second solution is simpler, but it looks a bit like a hack. cyclic-
list2 can contain itself becuase it is bound to a var before its
contents are evaluated.

(def cyclic-list2
   (lazy-cat [3 2 1] [cyclic-list2]))

;It does realy contain ITSELF and not a list like itself
(let [[a b c self] cyclic-list2]
   (= cyclic-list2 self))

(Well-intentioned advice: Don't try to print or otherwise completely
evaluate these lists or it will overflow your stack. Also don't
compare the first list to its self-similar elements, for the same
reason.)

hth, Robert Pfeiffer
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to