Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
[[tags: egg]] == list-utils Miscellaneous list oriented routines. [[toc:]] == Documentation === list-utils basic === Usage <enscript language=scheme> (import (list-utils basic)) </enscript> === length=0? <macro>(length=0? LIST) -> boolean</macro> List of length zero? (Just {{null?}}.) === length=1? <macro>(length=1? LIST) -> boolean</macro> List of length one? === length>1? <macro>(length>1? LIST) -> boolean</macro> List of length greater than one? === length=2? <macro>(length=2? LIST) -> boolean</macro> List of length two? === ensure-list <macro>(ensure-list OBJECT) -> list</macro> Returns a list, either the list {{OBJECT}} or {{(list OBJECT)}}. === ensure-flat-list <procedure>(ensure-flat-list OBJ) -> list</procedure> Returns a flat {{list}} from {{OBJ}}. === list-flatten <procedure>(list-flatten LS) -> list</procedure> Returns a flattened {{LS}}. === not-null? <macro>(not-null? LIST) -> (or list boolean)</macro> Returns {{#f}} if the given {{LIST}} is empty, and {{LIST}} otherwise. === pair-ref <procedure>(pair-ref LIST IDX) -> list</procedure> Returns the {{IDX}}th {{pair}} of {{LIST}}. === list-set! <procedure>(list-set! LIST IDX OBJ) -> list</procedure> Replaces the {{car}} the {{(pair-ref LIST IDX)}} with {{OBJ}}. === list-copy* <procedure>(list-copy* LIST START END FILL) -> list</procedure> Returns a copy of {{LIST}}, from {{START}} until {{END}}, where {{END}} maybe {{>}} {{(length LIST))}}. In which case {{FILL}} is used. ==== make-list/as <procedure>(make-list/as OBJ) --> (#!optional (or integer list) -> (or OBJ (list-of OBJ)))</procedure> Returns a procedure producing a list of the supplied object {{OBJ}}, of length equal to the {{integer}} or the {{(length list)}}. <enscript language=scheme> (define falses (make-list/as #f)) (falses '(1 2)) ;=> (#f #f) (falses 1) ;=> (#f) </enscript> === list-utils operations === Usage <enscript language=scheme> (import (list-utils operations)) </enscript> === skip+ <procedure>(skip+ LIST COUNT) -> (list integer)</procedure> 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}}. <enscript language=scheme> (skip+ '(1 2) 3) ;=> '() 1 (skip+ '(1 2 3) 3) ;=> '() 0 (skip+ '(1 2 3 4) 3) ;=> '(4) 0 </enscript> === list-unique/duplicates <procedure>(list-unique/duplicates LS [EQAL?]) -> list list</procedure> Returns 2 values, the sorted list w/o duplicates & the list of duplicates. ; {{EQAL?}} : {{a b -> *}} ; the equality predicate. === list-unique <procedure>(list-unique LS [EQAL?]) -> list</procedure> Returns the sorted list w/o duplicates. ; {{EQAL?}} : {{a b -> *}} ; the equality predicate. === split-at+ <procedure>(split-at+ LIST COUNT [PADS]) -> (list list)</procedure> 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. <enscript language=scheme> (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) ;=> '() '() </enscript> === section <procedure>(section LIST SIZE [[STEP] PADS]) -> list</procedure> 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. <enscript language=scheme> (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)) </enscript> === shift! <procedure>(shift! LIST [DEFAULT]) -> *</procedure> 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! <procedure>(unshift! OBJECT LIST) -> list</procedure> 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 <macro>(shift!/set VARIABLE [WHEN-EMPTY])</macro> 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</procedure> 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</procedure> The arity of the function {{FUNC}} must be the length of {{LIST...}}. {{(or (FUNC (car LIST)...) (ormap FUNC (cdr LIST)...))}}. === list-utils alist === Usage <enscript language=scheme> (import (list-utils alist)) </enscript> === alist-delete-first <macro>(alist-delete-first KEY ALIST [TEST?])</macro> Returns {{(alist-delete-with-count KEY ALIST [TEST?] 1)}}. === alist-delete-first! <macro>(alist-delete-first! KEY ALIST [TEST?])</macro> Destructive version of {{alist-delete-first}}. === assoc-def <macro>(assoc-def KEY ALIST [TEST] [NOT-FOUND])</macro> 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 <macro>(assv-def KEY ALIST [NOT-FOUND])</macro> 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 <macro>(assq-def KEY ALIST [NOT-FOUND])</macro> 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 <procedure>(alist-inverse-ref VALUE ALIST [TEST? [NOT-FOUND]])</procedure> 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 <procedure>(alist-delete-duplicates KEY ALIST [TEST? [COUNT]]) -> alist</procedure> 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! <procedure>(alist-delete-duplicates! KEY ALIST [TEST? [COUNT]]) -> alist</procedure> Destructive version of {{alist-delete-with-count}}. {{alist-delete-first}} and {{alist-delete-first!}} are also available. === sort-alist <procedure>(sort-alist ALIST [LESSP]) -> alist</procedure> ; {{ALIST}} : {{(list-of pair)}} ; less-than procedure, default {{<}}. ; {{LESSP}} : {{(* * --> boolean)}} ; less-than procedure, default {{<}}. === sort-alist! <procedure>(sort-alist! ALIST [LESSP]) -> alist</procedure> ; {{ALIST}} : {{(list-of pair)}} ; less-than procedure, default {{<}}. ; {{LESSP}} : {{(* * --> boolean)}} ; less-than procedure, default {{<}}. === unzip-alist <procedure>(unzip-alist ALIST)</procedure> Returns 2 values, a list of the keys & a list of the values from the {{ALIST}}. === zip-alist <procedure>(zip-alist KEYS VALUES)</procedure> Returns an association list with elements from the corresponding items of {{KEYS}} and {{VALUES}}. === plist->alist <procedure>(plist->alist PLIST) -> list</procedure> Returns the association-list form of {{PLIST}}. === alist->plist <procedure>(alist->plist ALIST) -> list</procedure> Returns the property-list form of {{ALIST}}. === list-utils sample === Usage <enscript language=scheme> (import (list-utils sample)) </enscript> === list-randoms <procedure>(list-randoms CNT [END [LOW [DUPS?]]]) -> (list-of integer)</procedure> Returns list of random integers in the open-interval {{[LOW END)}}. ; {{CNT}} : {{fixnum}} ; length of result list. ; {{END}} : {{integer}} ; maximum value + 1, default {{most-positive-fixnum}}. ; {{LOW}} : {{integer}} ; minimum value, default {{0}}. ; {{DUPS?}} : {{boolean}} ; allow duplicates, default {{#f}}. === list-random-sample <procedure>(list-random-sample LS [CNT]) -> list</procedure> Returns list of elements randomly sampled from {{LS}}. ; {{CNT}} : {{fixnum}} ; length of result list, default is random in {{[0 (- (length LS) 1)]}}. === list-cyclic-sample <procedure>(list-cyclic-sample LS [CNT]) -> list</procedure> Returns list of elements, sampled every {{CNT}} elements, from {{LS}}. Every element {{i}} in {{[0 length(LS)-1]}} where {{i modulo CNT = 0}}; so first element always included. ; {{CNT}} : {{fixnum}} ; cycle length, default is {{7}}. === list-utils comma) === Usage <enscript language=scheme> (import (list-utils comma)) </enscript> === list->comma-string <procedure>(list->comma-string LS [EMPTY? [COMMA]]) -> string</procedure> Returns list elements, as strings, joined with {{COMMA}}. ; {{EMPTY?}} : {{boolean}} ; allow empties? default {{#f}}. ; {{COMMA}} : {{string}} ; comma string. default {{", "}}. === comma-string->list <procedure>(comma-string->list STR [TRIM]) -> (list-of string)</procedure> Returns {{STR}} elements, joined with {{#\,}}, as a {{list}}. ; {{STR}} : {{string}} ; simple comma list. ; {{TRIM}} : {{(string -> string)}} ; process list elements. default {{string-trim-whitespace-both}}. === list-comma-join <procedure>(list-comma-join . REST) -> string</procedure> Returns {{(list->comma-string REST}}. === make-comma-string <procedure>(make-comma-string LEN [STR]) -> string</procedure> Returns a comma-string of length {{LEN}} and element {{STR}}, default {{"?"}}. == Requirements [[utf8]] [[srfi-1]] [[check-errors]] [[test]] [[test-utils]] == Author [[/users/kon-lovett|Kon Lovett]] == Repository This egg is hosted on the CHICKEN Subversion repository: [[https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/list-utils|https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/list-utils]] If you want to check out the source code repository of this egg and you are not familiar with Subversion, see [[/egg-svn-checkout|this page]]. == Version history ; 2.6.0 : Split into {{(list-utils basic)}}, {{(list-utils alist)}}, and {{(list-utils operations)}} w/ {{(list-utils)}} as omnibus. Add {{make-list/as}}. ; 2.5.1 : Copy tail. ; 2.5.0 : Add {{(list-utils sample)}}, & {{(list-utils comma)}}. ; 2.4.2 : New test-runner, add . ; 2.4.1 : Use check-errors. ; 2.4.0 : Add {{sort-alist}}, {{sort-alist!}}, {{list-randoms}}, & {{list-sample}}. ; 2.3.0 : Add {{list-flatten}} & {{ensure-flat-list}}. Add ''comma-list-utils''. ; 2.2.0 : Add {{list-unique}} & {{list-unique/duplicates}}. ; 2.1.1 : Fix {{split-at+}} optional argument. ; 2.1.0 : Deprecate {{alist-delete/count}} & {{alist-delete!/count}}. ; 2.0.1 : Fix egg category. ; 2.0.0 : CHICKEN 5 release. ; 1.4.0 : Add {{alist-delete-duplicates(!)}}, {{pair-ref}}, {{list-set!}}, {{list-copy*}}. Deperecate {{alist-delete-with/for-count(!)}}. ; 1.3.0 : Add {{alist-delete-with-count}} & {{alist-delete-with-count!}}. ; 1.2.0 : Add {{alist-delete-for-count}} & {{alist-delete-for-count!}}. ; 1.1.2 : . ; 1.1.1 : Fix for ticket #630 ; 1.1.0 : Added {{skip+}}, {{split-at+}}, and {{section}}. ; 1.0.0 : Hello, == License Copyright (C) 2010-2023 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.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 19 to 13?