Created
June 21, 2014 08:48
-
-
Save toctan/3d8e63448c99556ccd9f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defmacro for (var start stop &rest body) | |
(let ((gstop (gensym))) | |
`(do ((,var ,start (1+ ,var)) | |
(,gstop ,stop)) | |
((> ,var ,gstop)) | |
,@body))) | |
(defmacro in (obj &rest choices) | |
(let ((insym (gensym))) | |
`(let ((,insym ,obj)) | |
(or ,@(mapcar #'(lambda (c) `(eql ,insym ,c)) | |
choices))))) | |
(defmacro random-choice (&rest exprs) | |
`(case (random ,(length exprs)) | |
,@(let ((key -1)) | |
(mapcar #'(lambda (expr) | |
`(,(incf key) ,expr)) | |
exprs)))) | |
(defmacro avg (&rest args) | |
`(/ (+ ,@args) ,(length args))) | |
(defmacro with-gensyms (syms &body body) | |
`(let ,(mapcar #'(lambda (s) | |
'(,s (gensym))) | |
syms) | |
,@body)) | |
(defmacro aif (test then &optional else) | |
`(let ((it ,test)) | |
(if it ,then ,else))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment