Hi,
On Jul 8, 4:53 pm, Brian Hurt <[email protected]> wrote:
> A better API for this particular use suggested itself to me: simply allow
> the state to be nil, and require the functions that are sent initialize the
> state if necessary. Code like:
>
> (defn my_f [ state ]
> (let [ state (or state (init-function)) ]
> ...
>
> In this case, it doesn't matter which f is the first f executed, it
> initializes the state, and everything works.
Instead of putting this in every f, you decorate the fs.
(defn init-and-call
[state initf f & args]
(let [state (if (nil? state) (initf) state)]
(apply f state args)))
(send a init-and-call init-function f)
If your init is constant (which it is probably not), you can also use
fnil:
(send a (fnil f init))
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en