1. Pypy
  2. Untitled project
  3. lang-scheme

Commits

Jürgen Bömmels  committed 046b82d

Stubbing of case, basic tests work

  • Participants
  • Parent commits a93db4d
  • Branches default

Comments (0)

Files changed (2)

File scheme/r5rs_derived_expr.ss

View file
      (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 ...)))))

File scheme/test/test_eval.py

View file
     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"))
+