Refactor >list to be a generic word
parent
8d6df6d128
commit
edff21ada3
|
@ -121,11 +121,6 @@ HELP: sequence-tail>list
|
|||
{ $description "Convert the sequence into a list, starting from " { $snippet "index" } "." }
|
||||
{ $see-also >list } ;
|
||||
|
||||
HELP: >list
|
||||
{ $values { "object" object } { "list" "a list" } }
|
||||
{ $description "Convert the object into a list. Existing lists are passed through intact, sequences are converted using " { $link sequence-tail>list } " and other objects cause an error to be thrown." }
|
||||
{ $see-also sequence-tail>list } ;
|
||||
|
||||
{ leach foldl lazy-map ltake lfilter lappend lfrom lfrom-by lconcat lcartesian-product lcartesian-product* lcomp lcomp* lmerge lwhile luntil } related-words
|
||||
|
||||
HELP: lconcat
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2004, 2008 Chris Double, Matthew Willis, James Cash.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays combinators io kernel lists math
|
||||
promises quotations sequences summary vectors ;
|
||||
promises quotations sequences vectors ;
|
||||
IN: lists.lazy
|
||||
|
||||
M: promise car ( promise -- car )
|
||||
|
@ -241,17 +241,7 @@ M: sequence-cons cdr ( sequence-cons -- cdr )
|
|||
M: sequence-cons nil? ( sequence-cons -- ? )
|
||||
drop f ;
|
||||
|
||||
ERROR: list-conversion-error object ;
|
||||
|
||||
M: list-conversion-error summary
|
||||
drop "Could not convert object to list" ;
|
||||
|
||||
: >list ( object -- list )
|
||||
{
|
||||
{ [ dup sequence? ] [ 0 swap sequence-tail>list ] }
|
||||
{ [ dup list? ] [ ] }
|
||||
[ list-conversion-error ]
|
||||
} cond ;
|
||||
M: sequence >list 0 swap sequence-tail>list ;
|
||||
|
||||
TUPLE: lazy-concat car cdr ;
|
||||
|
||||
|
|
|
@ -169,3 +169,6 @@ HELP: lmap>array
|
|||
{ $values { "list" list } { "quot" quotation } { "array" array } }
|
||||
{ $description "Executes the quotation on each element of the list, collecting the results in an array." } ;
|
||||
|
||||
HELP: >list
|
||||
{ $values { "object" object } { "list" "a list" } }
|
||||
{ $description "Converts the object into a list." } ;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2008 James Cash, Daniel Ehrenberg, Chris Double.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel sequences accessors math arrays vectors classes words
|
||||
combinators.short-circuit combinators locals ;
|
||||
combinators.short-circuit combinators locals summary ;
|
||||
IN: lists
|
||||
|
||||
! List Protocol
|
||||
|
@ -95,3 +95,7 @@ PRIVATE>
|
|||
|
||||
INSTANCE: cons-state list
|
||||
INSTANCE: +nil+ list
|
||||
|
||||
GENERIC: >list ( object -- list )
|
||||
|
||||
M: list >list ;
|
||||
|
|
Loading…
Reference in New Issue