 : interval-contains? ( x int -- ? )
     dup empty-interval eq? [ 2drop f ] [
         dup full-interval eq? [ 2drop t ] [
-            [ from>> first2 [ >= ] [ > ] if ]
-            [ to>>   first2 [ <= ] [ < ] if ]
-            2bi and
+            {
+                [ from>> first2 [ >= ] [ > ] if ]
+                [ to>>   first2 [ <= ] [ < ] if ]
+            } 2&&
         ] if
     ] if ;
 

! See http://factorcode.org/license.txt for BSD license.
! Based on Slate's src/unfinished/interval.slate by Brian Rice.
USING: accessors kernel sequences arrays math math.order
combinators generic layouts memoize ;
IN: math.intervals

SYMBOL: empty-interval

: [-inf,inf] ( -- interval ) full-interval ; inline

: compare-endpoints ( p1 p2 quot -- ? )
    [ 2dup [ first ] bi@ 2dup ] dip call [
        2drop 2drop t
    ] [
        number= [ [ second ] bi@ not or ] [ 2drop f ] if
    ] if ; inline

: endpoint= ( p1 p2 -- ? )
    { [ [ first ] bi@ number= ] [ [ second ] bi@ eq? ] } 2&& ;

: endpoint< ( p1 p2 -- ? )
    [ < ] compare-endpoints ;

: endpoint<= ( p1 p2 -- ? )
    { [ endpoint< ] [ endpoint= ] } 2|| ;

: endpoint> ( p1 p2 -- ? )
    [ > ] compare-endpoints ;

: endpoint>= ( p1 p2 -- ? )
    { [ endpoint> ] [ endpoint= ] } 2|| ;

: endpoint-min ( p1 p2 -- p3 ) [ endpoint< ] most ;

