60 lines
2.7 KiB
Plaintext
60 lines
2.7 KiB
Plaintext
|
! Copyright (C) 2006 Chris Double.
|
||
|
! See http://factorcode.org/license.txt for BSD license.
|
||
|
|
||
|
USING: help lazy-lists ;
|
||
|
|
||
|
HELP: <promise>
|
||
|
{ $values { "quot" "a quotation with stack effect ( -- X )" } { "promise" "a promise object" } }
|
||
|
{ $description "Creates a promise to return a value. When forced this quotation is called and the value returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." }
|
||
|
{ $see-also force } ;
|
||
|
|
||
|
HELP: force
|
||
|
{ $values { "promise" "a promise object" } { "value" "a factor object" } }
|
||
|
{ $description "Calls the quotation associated with the promise if it has not been called before, and returns the value. If the promise has been forced previously, returns the value from the previous call." }
|
||
|
{ $see-also <promise> } ;
|
||
|
|
||
|
HELP: <cons>
|
||
|
{ $values { "car" "A promise for the head of the lazy list" } { "cdr" "A promise for the tail of the lazy list" } { "cons" "a cons object" } }
|
||
|
{ $description "Constructs a lazy cons cell. The car and cdr are promises that, when forced, provide the non-lazy values." }
|
||
|
{ $see-also car cdr nil } ;
|
||
|
|
||
|
HELP: car
|
||
|
{ $values { "cons" "a cons object" } { "car" "the first item in the list" } }
|
||
|
{ $description "Returns the first item in the list. This causes the item to be evaluated." }
|
||
|
{ $see-also <cons> car cdr } ;
|
||
|
|
||
|
HELP: cdr
|
||
|
{ $values { "cons" "a cons object" } { "cdr" "a cons object" } }
|
||
|
{ $description "Returns the tail of the list." }
|
||
|
{ $see-also <cons> car cdr } ;
|
||
|
|
||
|
HELP: cons
|
||
|
{ $values { "car" "a quotation with stack effect ( -- X )" } { "cdr" "a quotation with stack effect ( -- cons )" } { "cons" "the resulting cons object" } }
|
||
|
{ $description "Constructs a cons object for a lazy list from two quotations. The 'car' quotation should return the head of the list, and the 'cons' quotation the tail when called." }
|
||
|
{ $see-also <cons> car cdr } ;
|
||
|
|
||
|
HELP: nil
|
||
|
{ $values { "array" "An empty array" } }
|
||
|
{ $description "Returns a representation of an empty lazy list" }
|
||
|
{ $see-also <cons> car cdr nil? } ;
|
||
|
|
||
|
HELP: nil?
|
||
|
{ $values { "cons" "a cons object" } }
|
||
|
{ $description "Return true if the cons object is the nil list." }
|
||
|
{ $see-also nil } ;
|
||
|
|
||
|
HELP: <list>
|
||
|
{ $values { "car" "the car of the list" } { "cdr" "a <cons> object for the cdr of the list" } { "list" "a lazy list" } }
|
||
|
{ $description "Constructs a lazy list where the car is already forced and the cdr is an already forced list." }
|
||
|
{ $see-also car cdr } ;
|
||
|
|
||
|
HELP: 1list
|
||
|
{ $values { "obj" "an object" } { "list" "a list" } }
|
||
|
{ $description "Create a list with 1 element." }
|
||
|
{ $see-also <list> 2list } ;
|
||
|
|
||
|
HELP: 2list
|
||
|
{ $values { "a" "an object" } { "b" "an object" } { "list" "a list" } }
|
||
|
{ $description "Create a list with 2 elements." }
|
||
|
{ $see-also <list> 1list } ;
|