Clojure

Agents printed at the REPL do not always reflect their value

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None

Description

Starting with a fresh REPL and entering the following:

(def counter (agent 0))
(defn add1 [x] (inc x))
(send counter add1)
;; repeat many times
(send counter add1)

The representation printed at the REPL will not always display the correct value for the agent (e.g. the second call to `send` would print #<Agent@743fba: 1>). This appears to happen only in the first few calls to `send` before the value eventually "catches up". This behavior of course never occurs with `send-off`. This appears to only affect the printed value and not the actual value, but can still cause confusion.

My setup is as follows:
Mac OSX 10.5
Clojure 1.0.0
Running with `java -server -cp $CP jline.ConsoleRunner clojure.lang.Repl $*` where $CP points to clojure.jar, clojure-contrib.jar, and jline.jar

This also occurs with a fresh build of Clojure 1.1.0-alpha-SNAPSHOT from github.

-m

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/132
Hide
Assembla Importer added a comment -

stu said: I don't think this is a bug – there is no "correct value for the agent" as seen from the calling thread. There is a race condition when viewing agents at the REPL, and this is by design.

Show
Assembla Importer added a comment - stu said: I don't think this is a bug – there is no "correct value for the agent" as seen from the calling thread. There is a race condition when viewing agents at the REPL, and this is by design.
Hide
Assembla Importer added a comment -

fogus said: I understand why it happens, but it might be worthwhile to at least document this condition and/or consider removing the print of the value. In some cases reporting nothing is better than potentially incorrect information. Or is it enough to just say, "it's correct eventually or at least most of the time"?

-m

Show
Assembla Importer added a comment - fogus said: I understand why it happens, but it might be worthwhile to at least document this condition and/or consider removing the print of the value. In some cases reporting nothing is better than potentially incorrect information. Or is it enough to just say, "it's correct eventually or at least most of the time"? -m

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: