ea581753e904
Add range functions
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Sun, 27 Sep 2020 13:47:35 -0400 |
parents | 1aa2e5785e6f |
children | d8fe9c6ee9f4 |
branches/tags | (none) |
files | package.lisp src/lists.lisp |
Changes
--- a/package.lisp Wed Sep 02 11:45:13 2020 -0400 +++ b/package.lisp Sun Sep 27 13:47:35 2020 -0400 @@ -90,6 +90,8 @@ (:use :cl :iterate :losh.quickutils) (:documentation "Utilities for operating on lists.") (:export + :0.. :1.. :n.. + :0... :1... :n... :somelist)) (defpackage :losh.mutation @@ -305,6 +307,7 @@ :randomp :random-elt :random-range + :random-range-exclusive :random-range-inclusive :random-around
--- a/src/lists.lisp Wed Sep 02 11:45:13 2020 -0400 +++ b/src/lists.lisp Sun Sep 27 13:47:35 2020 -0400 @@ -14,3 +14,27 @@ (iterate (for l :on list) (thereis (funcall predicate l))))) + +(defun 0.. (below) + "Return a fresh list of the range `[0, below)`." + (loop :for i :from 0 :below below :collect i)) + +(defun 1.. (below) + "Return a fresh list of the range `[1, below)`." + (loop :for i :from 1 :below below :collect i)) + +(defun n.. (from below) + "Return a fresh list of the range `[from, below)`." + (loop :for i :from from :below below :collect i)) + +(defun 0... (to) + "Return a fresh list of the range `[0, to]`." + (loop :for i :from 0 :to to :collect i)) + +(defun 1... (to) + "Return a fresh list of the range `[1, to]`." + (loop :for i :from 1 :to to :collect i)) + +(defun n... (from to) + "Return a fresh list of the range `[from, to]`." + (loop :for i :from from :to to :collect i))