Miscellaneous list oriented routines.
- Bugs and Limitations
- Version history
- skip+ LIST COUNTprocedure
Returns 2 values, the COUNT pair from LIST, and the remaining count. The remaining count will be zero when end-of-list reached.
COUNT is a natural fixnum.
(skip+ '(1 2) 3) ;=> '() 1 (skip+ '(1 2 3) 3) ;=> '() 0 (skip+ '(1 2 3 4) 3) ;=> '(4) 0
- split-at+ LIST COUNT #!optional PADSprocedure
Returns 2 values, the leading COUNT elements from LIST as a new list, and the remaining elements from LIST. Should there be fewer than COUNT elements available padding is attempted.
Padding is performed by trying to complete the remaining elements from the list PADS.
COUNT is a natural fixnum. PADS is a list or #f. Default is '().
A negative COUNT is treated as 0.
When PADS is #f then an incomplete leading sublist is treated as '(). The very odd treatment of PADS = #f can safely be ignored since this is not the default behavior.
(split-at+ '(1 2 3) 3) ;=> '(1 2 3) '() (split-at+ '(1 2 3) 2) ;=> '(1 2) '(3) (split-at+ '(1 2 3) 4) ;=> '(1 2 3) '() (split-at+ '(1 2 3) 4 #f) ;=> '() '()
- (section LIST SIZE [[STEP] PADS]) -> listprocedure
Returns a list of list, built by taking SIZE elements from LIST every STEP elements. When too few elements remain to complete a section padding is performed.
SIZE is a positive fixnum. STEP is a positive fixnum. Default is SIZE. PADS is a list or #f. Default is '().
When PADS is #f then any incomplete trailing section is dropped. The very odd treatment of PADS = #f can safely be ignored since this is not the default behavior.
(section '(1 2) 3 3 '(3 4 5)) ;=> ((1 2 3)) (section '(1 2 3) 2 1 '(3 4 5)) ;=> ((1 2) (2 3)) (section '(1 2 3) 2 2 '(4 5)) ;=> ((1 2) (3 4)) (section '(1 2 3) 2 2) ;=> ((1 2) (3))
- (length=0? LIST) -> booleansyntax
List of length zero? (Just null?.)
- (length=1? LIST) -> booleansyntax
List of length one?
- (length>1? LIST) -> booleansyntax
List of length greater than one?
- (length=2? LIST) -> booleansyntax
List of length two?
- (ensure-list OBJECT) -> listsyntax
Returns a list, either the list OBJECT or (list OBJECT).
- (not-null? LIST) -> (or list boolean)syntax
Returns #f if the given LIST is empty, and LIST otherwise.
- (alist-delete-first KEY ALIST [TEST?])syntax
Returns (alist-delete-with-count KEY ALIST [TEST?] 1).
- (assoc-def KEY ALIST [TEST] [NOT-FOUND])syntax
The assoc procedure with an optional test and default value.
Error signaling version of assoc. When the KEY is not found and a NOT-FOUND value is not supplied an error is invoked.
- (assv-def KEY ALIST [NOT-FOUND])syntax
The assv procedure with a default value.
Error signaling version of assv. When the KEY is not found and a NOT-FOUND value is not supplied an error is invoked.
- (assq-def KEY ALIST [NOT-FOUND])syntax
The assq procedure with a default value.
Error signaling version of assq. When the KEY is not found and a NOT-FOUND value is not supplied an error is invoked.
- alist-inverse-ref VALUE ALIST #!optional TEST? NOT-FOUNDprocedure
Returns the first key associated with VALUE in the ALIST using the TEST? predicate, else NOT-FOUND.
TEST? is eqv? and NOT-FOUND is #f.
- alist-delete-duplicates KEY ALIST #!optional TEST? COUNTprocedure
Deletes the first COUNT associations from alist ALIST with the given key KEY, using key-comparison procedure TEST?. The dynamic order in which the various applications of equality are made is from the alist head to the tail.
Returns a new alist. The alist is not disordered - elements that appear in the result alist occur in the same order as they occur in the argument alist.
The equality procedure is used to compare the element keys, key[i: 0 <= i < (length ALIST)', of the alist's entries to the key parameter in this way: (TEST? KEY key[i]).
COUNT defaults to unlimited, & EQUALITY? defaults to eqv?.
- alist-delete-duplicates! KEY ALIST #!optional TEST? COUNTprocedure
Destructive version of alist-delete-with-count.
- unzip-alist ALISTprocedure
Returns 2 values, a list of the keys & a list of the values from the ALIST.
- zip-alist KEYS VALUESprocedure
Returns an association list with elements from the corresponding items of KEYS and VALUES.
- plist->alist PLISTprocedure
Returns the association-list form of PLIST.
- alist->plist ALISTprocedure
Returns the property-list form of ALIST.
- shift! LIST #!optional DEFAULTprocedure
Returns the first element of LIST, or DEFAULT when LIST is null.
The car and cdr of the first pair of LIST are set to the corresponding element of the second pair.
Like a stack-pop.
- unshift! OBJECT LISTprocedure
The car of the first pair of LIST is set to OBJECT. The cdr of the first pair of LIST is set to LIST.
Like a stack-push.
- (shift!/set VARIABLE [WHEN-EMPTY])syntax
Like shift! but assigns the VARIABLE '() after shifting from a list of length 1.
WHEN-EMPTY, which defaults to #f, is returned when the list bound to VARIABLE is empty.
- andmap FUNC LIST...procedure
The arity of the function FUNC must be the length of LIST....
(and (FUNC (car LIST)...) (andmap FUNC (cdr LIST)...)).
- ormap FUNC LIST...procedure
The arity of the function FUNC must be the length of LIST....
(or (FUNC (car LIST)...) (ormap FUNC (cdr LIST)...)).
- pair-ref LIST IDXprocedure
Returns the IDXth pair of LIST.
- list-set! LIST IDX OBJprocedure
Replaces the car the (pair-ref LIST IDX) with OBJ.
- list-copy* LIST START END FILLprocedure
Returns a copy of LIST, from START until END, where END maybe > (length LIST)). In which case FILL is used.
- Add alist-delete-duplicates(!), pair-ref, list-set!, list-copy*. Deperecate alist-delete-with/for-count(!).
- Add alist-delete-with-count & alist-delete-with-count!.
- Add alist-delete-for-count & alist-delete-for-count!.
- Fix for ticket #630
- Added skip+, split-at+, and section.
Copyright (C) 2010-2017 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.