Jürgen Bömmels avatar Jürgen Bömmels committed 046b82d

Stubbing of case, basic tests work

Comments (0)

Files changed (2)

scheme/r5rs_derived_expr.ss

      (let ((x test1))
        (if x x (or test2 ...))))))
 
+(define-syntax case
+  (syntax-rules (else)
+;;; XXX this check does not work yet
+;    ((case (key ...) clauses ...)
+;     (let ((atom-key (key ...)))
+;       (case atom-key clauses ...)))
+    ((case key (else expr1 expr2 ...))
+     (begin expr1 expr2 ...))
+    ((case key ((atoms ...) expr1 expr2 ...))
+     (if (memv key '(atoms ...))
+         (begin expr1 expr2 ...)))
+    ((case key ((atoms ...) expr1 expr2 ...) clause2 clause3 ...)
+     (if (memv key '(atoms ...))
+         (begin expr1 expr2 ...)
+         (case key clause2 clause3 ...)))))

scheme/test/test_eval.py

     w_res = eval_noctx("""(cddddr '((((a b) c d) (e f) g h)
                                     ((i j) k l) (m n) o p))""")
     assert w_res.equal(parse_("(p)"))
+
+def test_case():
+    w_res = eval_noctx("""
+         (case (* 2 3)
+           ((2 3 5 7) 'prime)
+           ((1 4 6 8 9) 'composite))
+           """)
+    assert w_res.eq(symbol("composite"))
+
+    w_res = eval_noctx("""
+         (case (car '(c d))
+           ((a e i o u) 'vowel)
+           ((w y) 'semivowel)
+           (else 'consonant))
+           """)
+    assert w_res.eq(symbol("consonant"))
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.