Clojure

when-first double evaluation

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: Release 1.4
  • Fix Version/s: Release 1.5
  • Component/s: None
  • Labels:
  • Environment:
    Mac OS X 10.8.1, Java 1.7.0_06
  • Patch:
    Code
  • Approval:
    Ok

Description

The when-first macro will evaluate the xs expression twice. Admittedly, it does exactly what the doc string says, but that seems undesirable to me. Even without side effects, there's a potential performance issue if xs is some expensive operation.

Patch attached. The main diff is:

- `(when (seq ~xs)
- (let [~x (first ~xs)]
- ~@body))))
+ `(when-let xs# (seq ~xs)
+ (let ~x (first xs#)
+ ~@body))))

Activity

Hide
Stuart Sierra added a comment -

Screened.

Show
Stuart Sierra added a comment - Screened.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: