core.async

Possible incorrect behavior on apply >! within go block

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Java 1.7.0_15 Java HotSpot(TM) 64-Bit Server VM
    clojure 1.5.1
    core.async 0.1.0-SNAPSHOT

Description

Below is code taken form the example file at https://github.com/clojure/core.async/blob/master/examples/walkthrough.clj

(let [c (chan)]
  (go (>! c "hello"))
    (assert (= "hello" (<!! (go (<! c)))))
    (close! c)))

I get different behavior when I change the first go block above to apply the >! function. In this case the execution hangs on the second go block. An example is below:

(let [c (chan)]
  (go (apply >! [c "hello"]))
    (assert (= "hello" (<!! (go (<! c)))))
    (close! c)))

Activity

Hide
Timothy Baldridge added a comment -

If you need behavior like you show above, consider using a destructuring let/loop/fn

Show
Timothy Baldridge added a comment - If you need behavior like you show above, consider using a destructuring let/loop/fn
Hide
Timothy Baldridge added a comment -

<! and >! are not functions, they are go macro special forms. They should be treated as macros. This is not a feature we plan to implement.

Show
Timothy Baldridge added a comment - <! and >! are not functions, they are go macro special forms. They should be treated as macros. This is not a feature we plan to implement.
Hide
Ghadi Shayban added a comment -

<! and >! are not normal IFn's or applicative function calls. They are akin to special forms or value-less macros compiled by the go macro. Maybe we can improve the docstring to show that those forms can't be applied across its arguments.

>! macro docstring:

puts a val into port. nil values are not allowed. Must be called inside a (go ...) block. Will park if no buffer space is available.

The >! var in clojure.core.async is just a hook to attach some docstring metadata. Its state can be nil and the go macro would still work the same.

Show
Ghadi Shayban added a comment - <! and >! are not normal IFn's or applicative function calls. They are akin to special forms or value-less macros compiled by the go macro. Maybe we can improve the docstring to show that those forms can't be applied across its arguments. >! macro docstring:
puts a val into port. nil values are not allowed. Must be called inside a (go ...) block. Will park if no buffer space is available.
The >! var in clojure.core.async is just a hook to attach some docstring metadata. Its state can be nil and the go macro would still work the same.
Hide
Jeff Sigmon added a comment -

Sorry about the misleading indentation in the code above...

Show
Jeff Sigmon added a comment - Sorry about the misleading indentation in the code above...

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: