ClojureScript

ClojureScript's 'and' does not always short-circuit

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Not Reproducible
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:

Description

I have a section of code: and false (function-that-should-not-be-called). Now, we should never call the function inside the and, but I'm seeing behavior where sometimes we are. It seems to depend on what's going on inside the definition of {function-that-should-not-be-called}. If we define a function this way, everything is fine:

(defn implicit-return-value
  []
  (.log js/console "implicit-return-value called")
  (dom/setTextContent (dom/getElement "executed")
                      "We called (implicit-return-value)"))

When I say "everything is fine", I mean the function is not called when this code is executed: (and false (implicit-return-value).

On the other hand, if we define a function this way, everything is not fine:

(defn explicit-return-value
  []
  (.log js/console "explicit-true-return called.")
  (dom/setTextContent (dom/getElement "executed")
                      "We called (explicit-return-value)")
  true)

When we execute this code: (and false (explicit-return-value), we do call the function explicit-return-value.

I have made a minimal project using the latest ClojureScript. The output of that project is located on my webpage. The project itself is on bitbucket. I'm not able to reproduce in a ClojureScript repl, and I haven't played around with optimizations to see when it does and does not happen.

Activity

Hide
Francis Avila added a comment -

Most likely the problem is in core.async's go macro, not clojurescript. You should bring this issue up with them.

Other avenues of investigation:

  • Are go blocks required to trigger the problem? (Seems so from what is said about repl.)
  • Does similar code (and inside go block with compile-time-known return value) exhibit the same behavior in Clojure?
Show
Francis Avila added a comment - Most likely the problem is in core.async's go macro, not clojurescript. You should bring this issue up with them. Other avenues of investigation:
  • Are go blocks required to trigger the problem? (Seems so from what is said about repl.)
  • Does similar code (and inside go block with compile-time-known return value) exhibit the same behavior in Clojure?
Hide
Francis Avila added a comment -

Indeed, it seems the same issue has a ticket in core.async JIRA: ASYNC-91

Show
Francis Avila added a comment - Indeed, it seems the same issue has a ticket in core.async JIRA: ASYNC-91
Hide
David Nolen added a comment -

This is a core.async issue

Show
David Nolen added a comment - This is a core.async issue
Hide
Zachary Kanfer added a comment -

Thanks for the suggestions to help narrow down where the problem is. I'll see if I can figure out any more information, and update the other ticket.

Show
Zachary Kanfer added a comment - Thanks for the suggestions to help narrow down where the problem is. I'll see if I can figure out any more information, and update the other ticket.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: