On Sat, Jan 10, 2009 at 6:57 PM, CuppoJava <patrickli_2...@hotmail.com> 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 (create_person "bill" bob)])

If you want to draw inspiration from other languages, take a look at
PLT Scheme's "shared" which is kind of like a letrec for creating
mutually recursive data structures:

http://docs.plt-scheme.org/reference/shared.html

But in the absence of such a construct, you've got two main options.
One is to use mutation to set up the mutual references, like what
Stuart Sierra described.

The other main option is to give each of your people a unique ID or
name.  You keep a hash table that maps these names to the actual
person object.  Within a person, your list of friends is actually a
list of names, rather than a list of people objects.  This adds a
level of indirection that avoids mutual references and makes
everything work.  To get to the actual person object, you look up the
name in your hash table.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to