Created
October 28, 2012 14:40
-
-
Save sunilnandihalli/3968777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol polynomial | |
(eval-poly [this t]) | |
(derivative [this]) | |
(derivative [this n]) | |
(coeffs [this])) | |
(deftype poly [coeffs] | |
polynomial | |
(eval-poly [this t] | |
(reduce #(+ (* %1 t) %2) 0.0 coeffs)) | |
(derivative [this] | |
(->poly (map #(* %1 %2) coeffs (range (count coeffs) 0 -1)))) | |
(derivative [this n] | |
(loop [c-poly this n-left n] | |
(if-not (> n 0) c-poly | |
(recur (derivative c-poly) (dec n))))) | |
(coeffs [this] coeffs)) |
(defprotocol polynomial
(eval-poly [this t])
(derivative [this])
(derivative [this n])
(coeffs [this]))
(deftype poly [coeffs]
polynomial
(eval-poly [this t]
(reduce #(+ (* %1 t) %2) 0.0 coeffs))
(derivative
([this]
(->poly (map #(* %1 %2) coeffs (range (count coeffs) 0 -1))))
([this n]
(loop [c-poly this n-left n]
(if-not (> n 0) c-poly
(recur (derivative c-poly) (dec n))))))
(coeffs [this] coeffs))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it keeps giving me the following error
1 compiler notes:
Unknown location:
error: java.lang.IllegalArgumentException: Can't define method not in interfaces: derivative
core.clj:113:1:
error: java.lang.IllegalArgumentException: Can't define method not in interfaces: derivative, compiling:(/home/sunil/swig-java/one/src/clj/
one/core.clj:113)
Compilation failed.