Skip to content

Instantly share code, notes, and snippets.

@aamedina
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aamedina/82fee074fb2fb398d4e1 to your computer and use it in GitHub Desktop.
Save aamedina/82fee074fb2fb398d4e1 to your computer and use it in GitHub Desktop.
(def ^:dynamic *start-time* (System/nanoTime))
(defn elapsed-ms
[]
(/ (- (System/nanoTime) *start-time*) 1000000))
(defn ^double position-offset-angle
([]
(position-offset-angle 5000))
([^long duration]
(position-offset-angle duration (/ (* Math/PI 2.0) duration)))
([^long duration ^double scale]
(* (mod (elapsed-ms) duration) scale)))
;; This code will not compile:
;; https://gist.github.com/aamedina/3ccee6bac03c04be8d2a
(let [theta (position-offset-angle)
x-offset (* (Math/cos theta) 0.5)
y-offset (* (Math/sin theta) 0.5)])
;; This will compile successfully
(let [theta (position-offset-angle)] theta)
;; However any let binding which references the theta local will also throw:
;; https://gist.github.com/aamedina/f86d059d16e9cf27b567
(let [theta (position-offset-angle)
x-offset theta])
;; The following also throws the same exception as above:
(let [theta (position-offset-angle)]
(* 5 theta))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment