You are looking at historical revision 19252 of this page. It may differ significantly from its current revision.

list-utils

Miscellaneous list oriented routines.

Documentation

length=0?

[syntax] (length=0? LIST) => boolean

List of length zero? (Just null?.)

length=1?

[syntax] (length=1? LIST) => boolean

List of length one?

length>1?

[syntax] (length>1? LIST) => boolean

List of length greater than one?

length=2?

[syntax] (length=2? LIST) => boolean

List of length two?

ensure-list

[syntax] (ensure-list OBJECT) => list

Returns a list, either the list OBJECT or (list OBJECT).

not-null?

[syntax] (not-null? LIST) => (union list boolean)

Returns #f if the given LIST is empty, and LIST otherwise.

alist-delete-first

[syntax] (alist-delete-first KEY ALIST [TEST?])

Returns (alist-delete/count KEY ALIST [TEST?] 1).

alist-delete-first!

[syntax] (alist-delete-first! KEY ALIST [TEST?])

Destructive version of alist-delete-first.

assoc-def

[syntax] (assoc-def KEY ALIST [TEST] [NOT-FOUND])

The assoc procedure with an optional test and default value.

assv-def

[syntax] (assv-def KEY ALIST [NOT-FOUND])

The assv procedure with a default value.

assq-def

[syntax] (assq-def KEY ALIST [NOT-FOUND])

The assq procedure with a default value.

alist-inverse-ref

[procedure] (alist-inverse-ref VALUE ALIST [TEST? [NOT-FOUND]])

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/count

[procedure] (alist-delete/count KEY ALIST [TEST? [COUNT]])

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 essentially, infinity, and EQUALITY? defaults to eqv?.

alist-delete!/count

[procedure] (alist-delete!/count KEY ALIST [TEST? [COUNT]])

Destructive version of alist-delete/count.

alist-delete-first and alist-delete-first! are also available as procedures.

unzip-alist

[procedure] (unzip-alist ALIST)

Returns 2 values, a list of the keys & a list of the values from the ALIST.

zip-alist

[procedure] (zip-alist KEYS VALUES)

Returns an association list with elements from the corresponding items of KEYS and VALUES.

Error signaling versions of the standard association lookup functions. When the KEY is not found and a NOT-FOUND value is not supplied an error is invoked.

plist->alist

[procedure] (plist->alist PLIST) => list

Returns the association-list form of PLIST.

alist->plist

[procedure] (alist->plist ALIST) => list

Returns the property-list form of ALIST.

shift!

[procedure] (shift! LIST [DEFAULT]) => *

Retrns 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!

[procedure] (unshift! OBJECT LIST) => list

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

[syntax] (shift!/set VARIABLE [WHEN-EMPTY])

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

[procedure] (andmap FUNC LIST...) => boolean

The arity of the function FUNC must be the length of LIST....

(and (FUNC (car LIST)...) (andmap FUNC (cdr LIST)...)).

ormap

[procedure] (ormap FUNC LIST...) => boolean

The arity of the function FUNC must be the length of LIST....

(or (FUNC (car LIST)...) (ormap FUNC (cdr LIST)...)).

Usage

(require-extension list-utils)

Requirements

check-errors

Bugs and Limitations

Author

kon lovett

Version history

1.0.0

License

Copyright (C) 2010 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.