From d71596a0e6615e742dc4aa9a8780b8f2fbe731a3 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2023 19:55:44 +0900 Subject: [PATCH] Test flipped function composition --- curry-tests.scm | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/curry-tests.scm b/curry-tests.scm index 4d01adb..d866c0d 100644 --- a/curry-tests.scm +++ b/curry-tests.scm @@ -44,16 +44,41 @@ (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)))) -- 2.39.2