@@ -468,6 +468,31 @@ let import = macro {
468
468
function self ( ) {
469
469
var name = 'self' ;
470
470
}
471
+ function and ( left , right ) {
472
+ if ( ! ( left instanceof Contract ) ) {
473
+ if ( typeof left === 'function' ) {
474
+ left = toContract ( left ) ;
475
+ } else {
476
+ throw new Error ( left + ' is not a contract' ) ;
477
+ }
478
+ }
479
+ if ( ! ( right instanceof Contract ) ) {
480
+ if ( typeof right === 'function' ) {
481
+ right = toContract ( right ) ;
482
+ } else {
483
+ throw new Error ( right + ' is not a contract' ) ;
484
+ }
485
+ }
486
+ var contractName = left + ' and ' + right ;
487
+ return new Contract ( contractName , 'and' , function ( blame ) {
488
+ return function ( val ) {
489
+ var leftProj = left . proj ( blame . addExpected ( contractName , true ) ) ;
490
+ var leftResult = leftProj ( val ) ;
491
+ var rightProj = right . proj ( blame . addExpected ( contractName , true ) ) ;
492
+ return rightProj ( leftResult ) ;
493
+ } ;
494
+ } ) ;
495
+ }
471
496
function or ( left , right ) {
472
497
if ( ! ( left instanceof Contract ) ) {
473
498
if ( typeof left === 'function' ) {
@@ -548,6 +573,7 @@ let import = macro {
548
573
check : check ,
549
574
fun : fun ,
550
575
or : or ,
576
+ and : and ,
551
577
self : new Contract ( 'self' , 'self' , function ( b ) {
552
578
return function ( ) {
553
579
} ;
@@ -706,7 +732,7 @@ macro predicate_contract {
706
732
}
707
733
708
734
709
- macro non_or_contract {
735
+ macro non_bin_contract {
710
736
rule { $contract :predicate_contract } = > { $contract }
711
737
rule { $contract :function_contract } => { $contract }
712
738
rule { $contract :object_contract } => { $contract }
@@ -717,14 +743,21 @@ macro non_or_contract {
717
743
}
718
744
719
745
macro or_contract {
720
- rule { $left :non_or_contract or $right :any_contract } = > {
746
+ rule { $left :non_bin_contract or $right :any_contract } = > {
721
747
_c . or ( $left , $right )
722
748
}
723
749
}
724
750
751
+ macro and_contract {
752
+ rule { $left :non_bin_contract and $right :any_contract } = > {
753
+ _c . and ( $left , $right )
754
+ }
755
+ }
756
+
725
757
macro any_contract {
726
758
rule { $contract :or_contract } = > { $contract }
727
- rule { $contract :non_or_contract } => { $contract }
759
+ rule { $contract :and_contract } => { $contract }
760
+ rule { $contract :non_bin_contract } => { $contract }
728
761
}
729
762
730
763
0 commit comments