Hello all,

I've been reading Clojure Programming by Emerick, Carper, and Grand from 
O'Reilly and have a question.  Towards the end of Chapter 4, they implement a 
little web-crawler that uses agents.  I'm having some trouble getting my head 
around one piece of the code.  Specifically the `run` function they define, 
which I've pasted here: http://pastebin.com/EWqPaBPt.

In human terms, I understand this code to:

1) `send` a function "foo" to the agent to execute it (this will happen in 
another thread)
2) "foo" figures out the function "bar" to call to transition to the next state 
and calls it using either `send` or `send-off` as appropriate
3) whatever "bar" happens to be, it is going to end with a call to run which 
will keep the wheels of the state machine turning

So my question is regarding the return form of the outer send, which is 
`state`.  Is the idea here to basically return the identity of the agent for 
this outer send?  Meaning, don't change anything this time, affect all change 
via the inner send|send-off?

I know I can't really make this assumption, but to simplify for a moment, 
assume that these computations took place in three separate threads; A, B, and 
C.

A: call `run`
    call send with "foo" (this will be executed in thread B)
    return immediately since agents are asynchronous

B: call "foo" with the agent
    "foo" calls send|send-off with "bar" (this will be executed in thread C)
    "foo" returns the agent as it was when it was called, so it's only real 
purpose was to get "bar" going.

C: call "bar" with the agent
     this is where we actually do work and change the state of the agent
     call `run`

Am I on the right track?

Best regards,
--mike

Michael Erickson
erickson.mich...@gmail.com


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

Reply via email to