(test-error (e '(+ 1 (λc (x) x))))
;; composition
-;; we are going for (∘ * 1+ 1 3) ≡ ((∘ * 1+) 1 3) ≡ (((∘ * 1+) 1) 3) where:
-;; ∘ ≡ (λc (g f) (λc (x) (g (f x))))
-;; * ≡ (λc (x y) (* x y))
-;; and 1+ is the Scheme procedure.
-(test-equal (* (1+ 1) 3)
- (e '((λc (g f) (λc (x) (g (f x)))) (λc (x y) (* x y)) 1+ 1 3)))
-(test-equal (* (1+ 1) 3)
- (e '(((λc (g f) (λc (x) (g (f x)))) (λc (x y) (* x y)) 1+) 1 3)))
-(test-equal (* (1+ 1) 3)
- (e '((((λc (g f) (λc (x) (g (f x)))) (λc (x y) (* x y)) 1+) 1) 3)))
+;; ∘ ≡ function composition ≡ (λc (g f) (λc (x) (g (f x))))
+;; ۰ ≡ flipped ∘ ≡ (λc (f g) (λc (x) (g (f x))))
+(test-equal (expt (1+ 1) 3)
+ ;; (∘ expt 1+ 1 3)
+ (e '((λc (g f) (λc (x) (g (f x)))) ; ∘
+ (λc (x y) (expt x y)) ; expt
+ 1+ 1 3)))
+(test-equal (expt (1+ 1) 3)
+ ;; ((∘ expt 1+) 1 3)
+ (e '(((λc (g f) (λc (x) (g (f x)))) ; ∘
+ (λc (x y) (expt x y)) ; expt
+ 1+)
+ 1 3)))
+(test-equal (expt (1+ 1) 3)
+ ;; (((∘ expt 1+) 1) 3)
+ (e '((((λc (g f) (λc (x) (g (f x)))) ; ∘
+ (λc (x y) (expt x y)) ; expt
+ 1+)
+ 1)
+ 3)))
+(test-equal (1+ (expt 2 3))
+ ;; ((∘ (∘ 1+) expt) 2 3)
+ (e '(((λc (g f) (λc (x) (g (f x)))) ; ∘
+ ((λc (g f) (λc (x) (g (f x)))) ; ∘
+ (λc (x) (1+ x))) ; 1+
+ (λc (x y) (expt x y)) ; expt
+ )
+ 2 3)))
+(test-equal (expt 2 (1+ 3))
+ ;; (expt x (1+ y)) ≡ (∘ (۰ 1+) expt)
+ (e '(((λc (g f) (λc (x) (g (f x)))) ; ∘
+ ((λc (f g) (λc (x) (g (f x)))) (λc (x) (1+ x))) ; (۰ 1+)
+ (λc (x y) (expt x y)) ; expt
+ )
+ 2 3)))
;; misc
(test-equal 3 (e '(+ 1 ((λc (x) x) 2))))