Created
May 30, 2017 06:42
-
-
Save cleac/3d112070d755ce1f175817b4dd4b8899 to your computer and use it in GitHub Desktop.
Python style range implementation in lisp
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
(defun range(s &optional end step_) | |
(let | |
( | |
(start (cond | |
(end s) | |
(T 0))) | |
(end (cond | |
(end end) | |
(T s))) | |
(step_ (cond | |
(step_ step_) | |
(T 1))) | |
(result (list nil)) | |
) | |
(loop | |
(push start (cdr (last result))) | |
(setq start (+ start step_)) | |
(when | |
(or | |
(and (> step_ 0) (>= start end)) | |
(and (< step_ 0) (<= start end))) | |
(return (cdr result)) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which one could write as
or
or even