Skip to content

Commit f7eafcc

Browse files
committed
combinators.extras: make a throws? word that drops properly
1 parent bca53b4 commit f7eafcc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

extra/combinators/extras/extras-tests.factor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
! Copyright (C) 2013 Doug Coleman.
22
! See https://factorcode.org/license.txt for BSD license.
33
USING: alien.c-types arrays assocs combinators.extras io.files
4-
kernel math modern.slices parser ranges sequences splitting
5-
tools.test ;
4+
kernel math math.parser modern.slices parser ranges sequences
5+
splitting tools.test ;
66
IN: combinators.extras.tests
77

88

extra/combinators/extras/extras.factor

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,17 @@ SYNTAX: ?[ parse-quotation [ ?call ] curry append! ;
334334
: ?3unless ( ..a x y z pred: ( ..a x quot: ( ..a x y z -- ..b ? ) -- ..b x ? ) false: ( ..b x y z -- ..c ) -- ..c )
335335
[ ] swap ?3if ; inline
336336

337+
: throws? ( quot -- ? )
338+
[ '[ _ drop-outputs f ] ] [ '[ drop _ drop-inputs t ] ] bi recover ; inline
339+
337340
: filter-errors-as ( ... seq quot: ( ... elt -- ... ? ) -- ... subseq )
338-
[ '[ [ @ drop f ] [ 2drop t ] recover ] ] dip filter-as ; inline
341+
[ '[ _ throws? ] ] dip filter-as ; inline
339342

340343
: filter-errors ( ... seq quot: ( ... elt -- ... ? ) -- ... subseq )
341344
over filter-errors-as ; inline
342345

343346
: reject-errors-as ( ... seq quot: ( ... elt -- ... ? ) -- ... subseq )
344-
[ '[ [ @ drop f ] [ 2drop t ] recover ] ] dip reject-as ; inline
347+
[ '[ _ throws? ] ] dip reject-as ; inline
345348

346349
: reject-errors ( ... seq quot: ( ... elt -- ... ? ) -- ... subseq )
347350
over reject-errors-as ; inline

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy