kernel: adding while* that passes the predicate result to the body.
parent
c33a406066
commit
05665e8d13
|
@ -885,6 +885,10 @@ HELP: while
|
||||||
{ $values { "pred" { $quotation ( ..a -- ..b ? ) } } { "body" { $quotation ( ..b -- ..a ) } } }
|
{ $values { "pred" { $quotation ( ..a -- ..b ? ) } } { "body" { $quotation ( ..b -- ..a ) } } }
|
||||||
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link f } "." } ;
|
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link f } "." } ;
|
||||||
|
|
||||||
|
HELP: while*
|
||||||
|
{ $values { "pred" { $quotation ( ..a -- ..b ? ) } } { "body" { $quotation ( ..b ? -- ..a ) } } }
|
||||||
|
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link f } "." } ;
|
||||||
|
|
||||||
HELP: until
|
HELP: until
|
||||||
{ $values { "pred" { $quotation ( ..a -- ..b ? ) } } { "body" { $quotation ( ..b -- ..a ) } } }
|
{ $values { "pred" { $quotation ( ..a -- ..b ? ) } } { "body" { $quotation ( ..b -- ..a ) } } }
|
||||||
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link t } "." } ;
|
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link t } "." } ;
|
||||||
|
|
|
@ -284,6 +284,9 @@ UNION: boolean POSTPONE: t POSTPONE: f ;
|
||||||
: while ( ..a pred: ( ..a -- ..b ? ) body: ( ..b -- ..a ) -- ..b )
|
: while ( ..a pred: ( ..a -- ..b ? ) body: ( ..b -- ..a ) -- ..b )
|
||||||
swap do compose [ loop ] curry when ; inline
|
swap do compose [ loop ] curry when ; inline
|
||||||
|
|
||||||
|
: while* ( ..a pred: ( ..a -- ..b ? ) body: ( ..b ? -- ..a ) -- ..b )
|
||||||
|
[ [ dup ] compose ] dip while drop ; inline
|
||||||
|
|
||||||
: until ( ..a pred: ( ..a -- ..b ? ) body: ( ..b -- ..a ) -- ..b )
|
: until ( ..a pred: ( ..a -- ..b ? ) body: ( ..b -- ..a ) -- ..b )
|
||||||
[ [ not ] compose ] dip while ; inline
|
[ [ not ] compose ] dip while ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue