kernel: adding while* that passes the predicate result to the body.

fix-linux
John Benediktsson 2019-12-13 14:35:51 -08:00
parent c33a406066
commit 05665e8d13
2 changed files with 7 additions and 0 deletions

View File

@ -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 } "." } ;

View File

@ -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