move retry word to continuations
parent
3d17175926
commit
a329960d7e
|
@ -79,6 +79,7 @@ $nl
|
||||||
{ $subsection continue-with }
|
{ $subsection continue-with }
|
||||||
"Continuations as control-flow:"
|
"Continuations as control-flow:"
|
||||||
{ $subsection attempt-all }
|
{ $subsection attempt-all }
|
||||||
|
{ $subsection retry }
|
||||||
{ $subsection with-return }
|
{ $subsection with-return }
|
||||||
"Reflecting the datastack:"
|
"Reflecting the datastack:"
|
||||||
{ $subsection with-datastack }
|
{ $subsection with-datastack }
|
||||||
|
@ -237,6 +238,20 @@ HELP: attempt-all
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
HELP: retry
|
||||||
|
{ $values
|
||||||
|
{ "quot" quotation } { "n" null }
|
||||||
|
}
|
||||||
|
{ $description "Tries the quotation up to " { $snippet "n" } " times until it returns true. Retries the quotation if an exception is thrown or if the quotation returns " { $link f } ". The quotation is expected to have side effects that may fail, such as generating a random name for a new file until successful." }
|
||||||
|
{ $examples
|
||||||
|
{ $unchecked-example "USING: continuations math prettyprint ;"
|
||||||
|
"[ 5 random 0 = ] retry t"
|
||||||
|
"t"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
{ attempt-all retry } related-words
|
||||||
|
|
||||||
HELP: return
|
HELP: return
|
||||||
{ $description "Returns early from a quotation by reifying the continuation captured by " { $link with-return } " ; execution is resumed starting immediately after " { $link with-return } "." } ;
|
{ $description "Returns early from a quotation by reifying the continuation captured by " { $link with-return } " ; execution is resumed starting immediately after " { $link with-return } "." } ;
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,8 @@ ERROR: attempt-all-error ;
|
||||||
] { } make peek swap [ rethrow ] when
|
] { } make peek swap [ rethrow ] when
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
|
: retry ( quot: ( -- ? ) n -- ) swap [ drop ] prepose attempt-all ; inline
|
||||||
|
|
||||||
TUPLE: condition error restarts continuation ;
|
TUPLE: condition error restarts continuation ;
|
||||||
|
|
||||||
C: <condition> condition ( error restarts cc -- condition )
|
C: <condition> condition ( error restarts cc -- condition )
|
||||||
|
|
Loading…
Reference in New Issue