On Fri, Jan 2, 2009 at 9:31 PM, John Newman <john...@gmail.com> wrote: > I don't know much about functional programming, but I believe you're > supposed to think about functions as black boxes. Put something in, get > something out. > > Take this function, for example: > > (defn snake-head [] (first (@snake :body))) > > (We're cheating on the put something in part!) > > Perhaps it'd be better if we didn't instantiate the snake until later in the > "game loop." What if we wanted to make a game with two snakes? Then > snake-head is broken. > > Rather, we just do something like: > > (defn snake-head [any-snake] (first (@any-snake :body))) > > Now many snakes from many threads can use this function. (I think.. I'm > noobs, so... :)
I think you're probably right. I wonder though if it's better to make the callers do the dereference instead of doing it in the snake-head function. What do others think about this? > In fact, in most game tutorials, the "game loop" will be in a separate > thread all together, so it might be more common to leave any def'ing of > apples and snakes toward the bottom, where you have the gui code. Yeah, I need to work on making that change. > As a side note, if I remember correctly, other Java game tutorials usually > frame up the gui fairly early in the code. They probably do that for > aesthetic reasons -- so the Java app seems to load faster. Don't quote me > on that though. Thanks for the feedback! -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---