# HG changeset patch # User Steve Losh # Date 1601228855 14400 # Node ID ea581753e904d1b61da00205fd6311b9e8ce343f # Parent 1aa2e5785e6f87920bb6b099bbbe849cafd761b1 Add range functions diff -r 1aa2e5785e6f -r ea581753e904 package.lisp --- 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 diff -r 1aa2e5785e6f -r ea581753e904 src/lists.lisp --- 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))