Skip to content

Instantly share code, notes, and snippets.

@rpgoldman
Created August 17, 2011 17:07
Show Gist options
  • Save rpgoldman/1152035 to your computer and use it in GitHub Desktop.
Save rpgoldman/1152035 to your computer and use it in GitHub Desktop.
First shot at an &rest arguments function
(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