Do not create an extra scope in "if-amb"

db4
Samuel Tardieu 2009-05-24 15:42:57 +02:00
parent 98d282dd90
commit 1b9b27213d
1 changed files with 6 additions and 2 deletions

View File

@ -29,6 +29,10 @@ MACRO: checkpoint ( quot -- quot' )
<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 )
2dup = [ [ 1 + unsafe-number-from-to ] checkpoint ] unless ;
@ -57,13 +61,13 @@ MACRO: amb-execute ( seq -- quot )
[ length 1 - ] [ <enum> [ 1quotation ] assoc-map ] bi
'[ _ 0 unsafe-number-from-to nip _ case ] ;
: if-amb ( true false -- )
: if-amb ( true false -- ? )
[
[ { t f } amb ]
[ '[ @ require t ] ]
[ '[ @ f ] ]
tri* if
] with-scope ; inline
] amb-preserve ; inline
: cut-amb ( -- )
f failure set ;