On Mon, 2012-03-19 at 03:56 -0700, Narvius wrote: > 2) Return [new-state success?] instead of just new-state - requires too > much acrobatics from the user of the function (which is still me, but > whatever).
Don't be so sure...you can arrange for values "on the side" to be readable and writable at various code depths. https://bazaar.launchpad.net/~scompall/+junk/clojure-stuff/view/head:/src/com/nocandysw/cloj_dummy/punch.clj > (play-a-round []) [nil {:opponent {:health 100, :shouts []}, :stamina 75}] > (play-a-round [[50 true]]) [:won! {:opponent {:health 0, :shouts ["Uggh..."]}, :stamina 25}] > (play-a-round [[10 false] [10 false] [50 true]]) [:won! {:opponent {:health -20, :shouts ["Ow!" "Ow!" "Uggh..."]}, :stamina 5}] > (play-a-round [[80 false]]) [:out-of-stamina! {:opponent {:health 100, :shouts []}, :stamina 75}] (As an exercise, make it possible to lose this game.) Moreover, there are many other useful HOFs I didn't use in this example, for the sake of introduction. For example, use m-lift to inject a normal function into the monadic data flow. > 4) Allow an optional last argument to world-modifying functions which is an > atom that gets set to the success value. This is what I ultimately settled > for, and I think it is somewhat elegant. That way I minimize the side > effects to a level I can fully control. It is slightly less elegant than `out' parameters in C#. How F# treats those parameters is instructional: it converts any method using them into a method that simply returns the extra results in a tuple with the primary return value. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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 Note that posts from new members are moderated - please be patient with your first post. 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