try-find is just attempt-all. oops
parent
9a8bd26786
commit
1f76ab2d45
|
@ -59,11 +59,11 @@ M: windows-rng random-bytes* ( n tuple -- bytes )
|
|||
[ CryptGenRandom win32-error=0/f ] keep
|
||||
] with-destructors ;
|
||||
|
||||
ERROR: no-windows-crypto-provider ;
|
||||
ERROR: no-windows-crypto-provider error ;
|
||||
|
||||
: try-crypto-providers ( seq -- windows-rng )
|
||||
[ first2 <windows-rng> ] try-find drop
|
||||
[ no-windows-crypto-provider ] unless* ;
|
||||
[ first2 <windows-rng> ] attempt-all
|
||||
dup windows-rng? [ no-windows-crypto-provider ] unless ;
|
||||
|
||||
[
|
||||
{
|
||||
|
|
|
@ -48,10 +48,6 @@ $nl
|
|||
recover
|
||||
ignore-errors
|
||||
}
|
||||
"Word for mapping over a sequence with a quotation until an element doesn't throw an exception:"
|
||||
{ $subsections
|
||||
try-find
|
||||
}
|
||||
"Syntax sugar for defining errors:"
|
||||
{ $subsections POSTPONE: ERROR: }
|
||||
"Unhandled errors are reported in the listener and can be debugged using various tools. See " { $link "debugger" } "."
|
||||
|
@ -185,10 +181,6 @@ HELP: recover
|
|||
{ $values { "try" quotation } { "recovery" { $quotation "( error -- )" } } }
|
||||
{ $description "Calls the " { $snippet "try" } " quotation. If an exception is thrown in the dynamic extent of the " { $snippet "try" } " quotation, restores the data stack and calls the " { $snippet "recovery" } " quotation to handle the error." } ;
|
||||
|
||||
HELP: try-find
|
||||
{ $values { "seq" sequence } { "try" quotation } { "result" "the first non-false, non-exception result of the quotation" } { "elt" "the first matching element, or " { $link f } } }
|
||||
{ $description "Applies the quotation to each element of the sequence, until the quotation outputs a true value, and attempts the next element if an exception is thrown. If the quotation ever yields a result which is not " { $link f } ", then the value is output, along with the element of the sequence which yielded this." } ;
|
||||
|
||||
HELP: ignore-errors
|
||||
{ $values { "quot" quotation } }
|
||||
{ $description "Calls the quotation. If an exception is thrown in the dynamic extent of the quotation, restores the data stack and returns." } ;
|
||||
|
|
|
@ -106,15 +106,3 @@ SYMBOL: error-counter
|
|||
[ { 4 } ] [ { 2 2 } [ + ] with-datastack ] unit-test
|
||||
|
||||
[ with-datastack ] must-infer
|
||||
|
||||
[ { t 1 } ]
|
||||
[ { 1 1 } [ odd? ] try-find 2array ] unit-test
|
||||
|
||||
[ { 9 3 } ]
|
||||
[ { 3 3 } [ sq ] try-find 2array ] unit-test
|
||||
|
||||
[ { f f } ]
|
||||
[ { 1 1 } [ even? ] try-find 2array ] unit-test
|
||||
|
||||
[ { f f } ]
|
||||
[ { 1 1 } [ "error" throw ] try-find 2array ] unit-test
|
||||
|
|
|
@ -128,9 +128,6 @@ SYMBOL: thread-error-hook
|
|||
: cleanup ( try cleanup-always cleanup-error -- )
|
||||
[ compose [ dip rethrow ] curry recover ] [ drop ] 2bi call ; inline
|
||||
|
||||
: try-find ( seq try -- result elt )
|
||||
[ curry [ drop f ] recover ] curry map-find ; inline
|
||||
|
||||
ERROR: attempt-all-error ;
|
||||
|
||||
: attempt-all ( seq quot -- obj )
|
||||
|
|
Loading…
Reference in New Issue