"a" is the current value of the agent. *agent* is the agent itself.
Remember the universal update mechanism: an agent, atom or ref is updated by applying a (normally) pure function to it; the function takes the current state and returns the new state. Phil On Jul 24, 2012 5:16 AM, "larry google groups" <lawrencecloj...@gmail.com> wrote: > > I am confused by this blog post: > > > http://www.bestinclass.dk/index.clj/2009/09/php-vs-clojure-what-does-it-cost-to-be-old-school.html > > In particular, I am confuse by this function: > > (defn log-dumper > [a] > (Thread/sleep *write-delay*) > (let [sql-statements (let [tmp @*sql-buffer*] > (ref-set *sql-buffer* []) > tmp)] > (doseq [stmt sql-statements] > (run *mysql-connection* stmt)) > (send-off *agent* log-dumper))) > > > It looks like "a" is being passed in as an argument to the function. But > at the end of the function, *agent* is being passed into the function > again. I don't see a point in this function where "a" is magically > transformed into *agent*. I'm under the impression that this same agent is > suppose to be sent, over and over again, every 5 minutes, for all eternity, > into the function. But if the function is suppose to send the same agent to > itself, 5 minutes in the future, then I would think that if the argument is > named "a" then "a" is what would be send-off to the function again. > > The blog post says: > > ""send-off" myself (the *agent* is the thread) to the same function > again, ie. keep running." > > How does this work? How does the final line know that *agent* is the "a" > that was passed in as an argument? > > > > > > -- > 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 -- 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