On Jan 6, 11:21 am, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> You might be able to simplify this by having just one Ref containing
> the global "state" of the game.

Hi Stuart, yes I agree that is the better approach.

I went down the 'multi-mutable' path trying to improve relationship
handling. Consider two rooms which are 'linked' allowing travel
between them. This could be represented with a link id which provided
a way to look up what the other room is. However if you wanted to link
the rooms themselves, that would be impossible to declare unless you
use mutation.

But why not just use id lookups? Say room 1 was deleted, now room 2
has an invalid link. Ok so when I delete a room I can find all other
rooms that reference it and update them, but what if players reference
rooms for their current location? I could update all the relationships
but I'm implementing a database. That's not necessarily bad, but it
seemed like a lot of work (maybe there is a framework that would make
it easy). So how about I just allow invalid ids as they'll just be
looked up as nil and I can check for nil in my code. That's really
easy, the only downside is that ids cannot be reused or my state will
be corrupt. Not really a big deal, but I thought I would try using a
mutable instead. With a mutable if I remove a room I can set it to nil
and anything linked to it will be unlinked. To remove a link I can nil
the link itself (not the target). It is not really a great solution,
but it does have the advantage of not requiring any lookup either. On
the downside the mutable version has all the drawbacks any mutable
brings with it, which I'd like to avoid.

I'm interested in any tips about representing relational information.


Regards,
Tim.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

  • mset Timothy Pratley
    • Re: mset Stuart Sierra
      • Re: mset Timothy Pratley

Reply via email to