Hi,
After (are-friends bill bob) they should be friends,
so I tried @bob
and don't see bill as a friend. why?
@bob
{:friends #{#}, :name "Bob"}
-sun
On Jan 10, 9:44 pm, Stuart Sierra wrote:
> Hi Patrick,
>
> Here's one way to do it:
>
> (defn new-person [name]
> (ref {:name name, :frien
On Sat, Jan 10, 2009 at 6:57 PM, CuppoJava wrote:
> ps: I'm doing a bit of reading about mutually-recursive data
> structures on the net. Is Lisp's letrec supposed to handle this
> situation?
>
> It would be handy just to be able to do:
>
> (letrec [bob (create_person "bob" bill)
> bill
Thank you for the replies.
My actual problem is a bit more convoluted, so I can't separate the
issue like in Mark's solution very easily.
Stuart's solution is more general, and I think I can apply that in a
straight-forward way. Thanks.
ps: I'm doing a bit of reading about mutually-recursive data
I suggest moving friendship outside of the objects themselves.
(defn person [name] {:name name})
(def bob (person "Bob"))
(def bill (person "Bill))
(def *friends* {bob bill})
now friends is a map of who likes whom. Then you can implement
(defn friend? [p1 p2] (or (= p1 (*friends* p2)) (= p2 (*
Hi Patrick,
Here's one way to do it:
(defn new-person [name]
(ref {:name name, :friends #{}}))
(defn are-friends [a b]
(dosync
(commute a assoc :friends (conj (:friends @a) b))
(commute b assoc :friends (conj (:friends @b) a
(def bill (new-person "Bill"))
(def bob (new-person "Bo