core.async: faulty rebinding of loop-bindings in go blocks

151 views
Skip to first unread message

Kemar

unread,
Aug 1, 2013, 6:05:59 AM8/1/13
to clo...@googlegroups.com
There seems to be an issue with the rebinding of loop-bindings using loop/recur in go blocks,
specifically when you are just changing the order of the original bindings in a recur call.

Take this snippet for example:
    (require '[clojure.core.async :refer [go timeout]])
    (go (loop [a :black, b :white] 

          (println a b)
          (<! (timeout 1000))
          (recur b a)))

    Instead of repeatedly printing

    :black :white
    :white :black
    :black :white

    :white :black
    (...)

     it actually prints

    :black :white
    :white :white
    :white :white
    :white :white

    (...)
     
    Note however, that
     
    (require '[clojure.core.async :refer [go timeout]])
    (go (loop [a :black, b :white] 

          (println a b)
          (<! (timeout 1000))
          (recur (identity b) (identity a))))

    works correctly.

    Any ideas as to what's causing this?


    Cheers,
    Kevin

    Ghadi Shayban

    unread,
    Aug 1, 2013, 12:47:16 PM8/1/13
    to clo...@googlegroups.com
    It's a nasty bug, seems like a local symbol scope issue.  I will take a look at it.  Thanks for the report.

    Ghadi Shayban

    unread,
    Aug 3, 2013, 3:05:57 PM8/3/13
    to clo...@googlegroups.com
    Fixed -- should make it to maven within an hour.

    Kemar

    unread,
    Aug 3, 2013, 7:07:46 PM8/3/13
    to clo...@googlegroups.com
    It appears to be working, awesome!
    Thanks!

    Cheers,
    Kevin
    Reply all
    Reply to author
    Forward
    0 new messages