Re: Please help me get rid of my mutable code.

2009-02-27 Thread CuppoJava

Thanks very much Itay,
I'm reading through your post very carefully. I sounds like it's the
answer to all my problems.
  -Patrick
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Please help me get rid of my mutable code.

2009-02-27 Thread Itay Maman

Hi,

I just posted about the application context pattern. I believe it
addresses the issue you're describing.

-Itay


On Feb 27, 4:21 am, CuppoJava  wrote:
> Hi,
> After having used Clojure for a few months now, I'm still having lots
> of trouble separating my mutable code from my immutable code. My use-
> case is pretty typical I think, so I'm wondering what sort of
> structure everyone else is using.
>
> Here's my current structure.
>
> I have an engine that manages a list of sprites. The engine runs in a
> loop and updates all the sprites incrementally sixty times a second.
> When an event occurs, the engine notifies each sprite. When a sprite
> receives an event, it processes it, and then notifies each of it's
> listeners. Typical Java event listener model.
>
> Well this scheme has mutability written all over it.
> I'm currently representing sprites as references of immutable maps. So
> my code is literally littered with (dosync) instructions.
>
> How would I go about separating my mutable code from my immutable
> code? I think I need a completely different angle to attack the
> problem?
>
> Thanks a lot for the help
>   -Patrick
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Please help me get rid of my mutable code.

2009-02-26 Thread Tom Ayerst
If most of the state is in the sprites and they don't co-ordinate then could
you make the sprites agents and use watchers to manage their forward
notifications.
Any global state (the event loop) can be managed functionally by recursively
passing the updated state as a parameter into the event function.

Tom

2009/2/27 CuppoJava 

>
> Hi,
> After having used Clojure for a few months now, I'm still having lots
> of trouble separating my mutable code from my immutable code. My use-
> case is pretty typical I think, so I'm wondering what sort of
> structure everyone else is using.
>
> Here's my current structure.
>
> I have an engine that manages a list of sprites. The engine runs in a
> loop and updates all the sprites incrementally sixty times a second.
> When an event occurs, the engine notifies each sprite. When a sprite
> receives an event, it processes it, and then notifies each of it's
> listeners. Typical Java event listener model.
>
> Well this scheme has mutability written all over it.
> I'm currently representing sprites as references of immutable maps. So
> my code is literally littered with (dosync) instructions.
>
> How would I go about separating my mutable code from my immutable
> code? I think I need a completely different angle to attack the
> problem?
>
> Thanks a lot for the help
>  -Patrick
> >
>

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



Please help me get rid of my mutable code.

2009-02-26 Thread CuppoJava

Hi,
After having used Clojure for a few months now, I'm still having lots
of trouble separating my mutable code from my immutable code. My use-
case is pretty typical I think, so I'm wondering what sort of
structure everyone else is using.

Here's my current structure.

I have an engine that manages a list of sprites. The engine runs in a
loop and updates all the sprites incrementally sixty times a second.
When an event occurs, the engine notifies each sprite. When a sprite
receives an event, it processes it, and then notifies each of it's
listeners. Typical Java event listener model.

Well this scheme has mutability written all over it.
I'm currently representing sprites as references of immutable maps. So
my code is literally littered with (dosync) instructions.

How would I go about separating my mutable code from my immutable
code? I think I need a completely different angle to attack the
problem?

Thanks a lot for the help
  -Patrick
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---