Skip to content

Instantly share code, notes, and snippets.

@swannodette
Forked from cgrand/fib.clj
Created June 4, 2010 15:58
Show Gist options
  • Save swannodette/425591 to your computer and use it in GitHub Desktop.
Save swannodette/425591 to your computer and use it in GitHub Desktop.
(definterface IntToIntFn
(#^int call [^int n]))
(def fibr
(let [one (int 1)
two (int 2)]
(reify
IntToIntFn
(call [this n]
(if (>= one n) one (+ (.call this (dec n)) (.call this (- n two))))))))
(def fibr
(reify
IntToIntFn
(call [this n]
(if (>= (int 1) n) (int 1) (+ (.call this (dec n)) (.call this (- n (int 2))))))))
;; rhickey's comments
;; (definterface IFib (^int fib [^int n]))
;; (deftype Fib [] IFib (fib [this n] (if (>= (int 1) n) (int 1) (+ (.fib this (dec n)) (.fib this (- n (int 2)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment