Created
August 17, 2011 17:07
-
-
Save rpgoldman/1152035 to your computer and use it in GitHub Desktop.
First shot at an &rest arguments function
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
(defrecord complex [real imag]) | |
(defn add [c1 c2 & x] | |
(if (nil? x) | |
(complex. (+ (:real c1) (:real c2)) | |
(+ (:imag c1) (:imag c2))) | |
(add (add c1 c2) (first x) (rest x)))) | |
;; probably this last line is buggy --- there's almost certainly an idiomatic way to do | |
;; what I would do as (apply ADD (add c1 c2) (first x) (rest x)) | |
;; failing call | |
;; (add (complex. 1 0) (complex. 2 0) (complex. 3 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment