Skip to content
TurtleKitty edited this page May 11, 2019 · 2 revisions

when

This operator is a one-armed version of if. It is most useful for side effects.

(def got-two (cell false))

(proc foo (x)
   (when (= x 2)
      (got-two.set! true))
   (* x 10))

got-two.get  ; false
(foo 0)      ; 0
got-two.get  ; false
(foo 1)      ; 10
got-two.get  ; false
(foo 2)      ; 20
got-two.get  ; true
Clone this wiki locally