Skip to content

Commit

Permalink
#19 - changed map0-n to use loop -- 25% faster
Browse files Browse the repository at this point in the history
  • Loading branch information
mck- committed Mar 14, 2012
1 parent d581252 commit fe744bc
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/simple-utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
(defun single (lst)
(and (consp lst) (not (cdr lst))))

(defun mapa-b (fn a b &optional (step 1))
"Maps function over integers from a to b"
(do ((i a (+ i step))
(result nil))
((> i b) (nreverse result))
(push (funcall fn i) result)))

(defun map0-n (fn n)
"maps from 0 to n"
(mapa-b fn 0 n))
(loop for x from 0 to n
collect (funcall fn x)))

(defun map1-n (fn n)
"maps from 1 to n"
(mapa-b fn 1 n))
(loop for x from 1 to n
collect (funcall fn x)))

(defmacro mac (expr)
`(pprint (macroexpand-1 ',expr)))
Expand Down

0 comments on commit fe744bc

Please sign in to comment.