aboutsummaryrefslogtreecommitdiffstats
path: root/test/examples
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2025-06-28 16:05:08 -0400
committerGravatar Peter McGoron 2025-06-28 16:05:08 -0400
commitd23f88d18650de07399a25e05451f35b91d1d7d7 (patch)
tree781b75a1b2a96c85f6eb55d6405a9ca4d47b5fe6 /test/examples
parentFix list ellipses pattern matching (diff)
move tests to their own file; use debruijn form to test alpha equivalence
Diffstat (limited to 'test/examples')
-rw-r--r--test/examples/untyped-lambda-calculus.scm71
-rw-r--r--test/examples/untyped-lambda-calculus.sld23
2 files changed, 94 insertions, 0 deletions
diff --git a/test/examples/untyped-lambda-calculus.scm b/test/examples/untyped-lambda-calculus.scm
new file mode 100644
index 0000000..46f3f60
--- /dev/null
+++ b/test/examples/untyped-lambda-calculus.scm
@@ -0,0 +1,71 @@
+#| Copyright (c) Peter McGoron 2025
+ |
+ | Licensed under the Apache License, Version 2.0 (the "License");
+ | you may not use this file except in compliance with the License.
+ | You may obtain a copy of the License at
+ |
+ | http://www.apache.org/licenses/LICENSE-2.0
+ |
+ | Unless required by applicable law or agreed to in writing, software
+ | distributed under the License is distributed on an "AS IS" BASIS,
+ | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ | See the License for the specific language governing permissions and
+ | limitations under the License.
+ |#
+
+(define-syntax test-alpha
+ (syntax-rules ()
+ ((test-alpha name (inputs ...) output)
+
+ (let-values (((global-map expanded-list)
+ (expand initial-environment
+ (list (empty-wrap (quote inputs)) ...))))
+ (test-equal name
+ (map (lambda (term)
+ (debruijnize global-map term '()))
+ expanded-list)
+ (quote output))))))
+
+(define (test-expander)
+ (test-alpha "identity"
+ ((lambda x x))
+ ((lambda 0)))
+ (test-alpha "let-syntax of identifier"
+ ((let-syntax ((λ lambda))
+ (λ x x)))
+ ((lambda 0)))
+ (test-alpha "lexical renaming of keywords"
+ ((lambda lambda (lambda lambda)))
+ ((lambda (0 0))))
+ (test-alpha "simple define-syntax"
+ ((define-syntax let
+ (syntax-rules ()
+ ((let ((name value)) body)
+ ((lambda name body) value))))
+ (let ((x (f y))) (f x)))
+ (((lambda (f 0)) (f y))))
+ (test-alpha "define-syntax with ellipsis"
+ ((define-syntax let
+ (syntax-rules ()
+ ((let ((name value)) body)
+ ((lambda name body) value))))
+ (define-syntax or
+ (syntax-rules ()
+ ((or) false)
+ ((or x y ...)
+ (let ((tmp x))
+ (if tmp tmp (or y ...))))))
+ (or a tmp b))
+ (((lambda (if 0
+ 0
+ ((lambda (if 0
+ 0
+ ((lambda (if 0
+ 0
+ false))
+ b))) tmp))) a))))
+
+(define (test-untyped-lambda-calculus)
+ (test-group "untyped lambda calculus"
+ (test-expander)))
+
diff --git a/test/examples/untyped-lambda-calculus.sld b/test/examples/untyped-lambda-calculus.sld
new file mode 100644
index 0000000..6d85eed
--- /dev/null
+++ b/test/examples/untyped-lambda-calculus.sld
@@ -0,0 +1,23 @@
+#| Copyright (c) Peter McGoron 2025
+ |
+ | Licensed under the Apache License, Version 2.0 (the "License");
+ | you may not use this file except in compliance with the License.
+ | You may obtain a copy of the License at
+ |
+ | http://www.apache.org/licenses/LICENSE-2.0
+ |
+ | Unless required by applicable law or agreed to in writing, software
+ | distributed under the License is distributed on an "AS IS" BASIS,
+ | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ | See the License for the specific language governing permissions and
+ | limitations under the License.
+ |#
+
+(define-library (multisyntax examples untyped-lambda-calculus test)
+ (import (scheme base) (srfi 64)
+ (multisyntax syntax-object) (multisyntax examples untyped-lambda-calculus))
+ (cond-expand
+ (chicken (import (chicken condition)))
+ (else))
+ (export test-untyped-lambda-calculus)
+ (include "untyped-lambda-calculus.scm")) \ No newline at end of file