Do not create an extra scope in "if-amb"
parent
98d282dd90
commit
1b9b27213d
|
@ -29,6 +29,10 @@ MACRO: checkpoint ( quot -- quot' )
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
: preserve ( quot var -- ) [ get [ call ] dip ] keep set ; inline
|
||||||
|
|
||||||
|
: amb-preserve ( quot -- ) failure preserve ; inline
|
||||||
|
|
||||||
: unsafe-number-from-to ( to from -- to from+n )
|
: unsafe-number-from-to ( to from -- to from+n )
|
||||||
2dup = [ [ 1 + unsafe-number-from-to ] checkpoint ] unless ;
|
2dup = [ [ 1 + unsafe-number-from-to ] checkpoint ] unless ;
|
||||||
|
|
||||||
|
@ -57,13 +61,13 @@ MACRO: amb-execute ( seq -- quot )
|
||||||
[ length 1 - ] [ <enum> [ 1quotation ] assoc-map ] bi
|
[ length 1 - ] [ <enum> [ 1quotation ] assoc-map ] bi
|
||||||
'[ _ 0 unsafe-number-from-to nip _ case ] ;
|
'[ _ 0 unsafe-number-from-to nip _ case ] ;
|
||||||
|
|
||||||
: if-amb ( true false -- )
|
: if-amb ( true false -- ? )
|
||||||
[
|
[
|
||||||
[ { t f } amb ]
|
[ { t f } amb ]
|
||||||
[ '[ @ require t ] ]
|
[ '[ @ require t ] ]
|
||||||
[ '[ @ f ] ]
|
[ '[ @ f ] ]
|
||||||
tri* if
|
tri* if
|
||||||
] with-scope ; inline
|
] amb-preserve ; inline
|
||||||
|
|
||||||
: cut-amb ( -- )
|
: cut-amb ( -- )
|
||||||
f failure set ;
|
f failure set ;
|
||||||
|
|
Loading…
Reference in New Issue