ClojureScript

max and other inlining arithmetics macros in cljs.core double evals args

Details

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

Description

if I want to randomly vary some number in an atom:

(def a (atom 5))

(swap! a (fn [n] (+ n (- (rand-int 1000) (rand-int 1000)))))

if I want my number to never be negative

(def a (atom 5))

(swap! a (fn [n] (max 0 (+ n (- (rand-int 1000) (rand-int 1000))))))

but in the second case I still get negative numbers, because some times the result of the rands is greater than zero, but the max macro runs them again and gets a result less than zero.

Activity

Hide
David Nolen added a comment -

patch for this exists in CLJS-541 along with other related macros issues.

Show
David Nolen added a comment - patch for this exists in CLJS-541 along with other related macros issues.
Hide
David Nolen added a comment -
Show
David Nolen added a comment - see CLJS-541

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: