From df44c8979b90ae1db13ca11eefef16ba2dc5b0f1 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Wed, 7 Oct 2015 11:04:11 -0400 Subject: [PATCH] little explanation --- remix/tests/simple.rkt | 61 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/remix/tests/simple.rkt b/remix/tests/simple.rkt index 456729b..a9da67c 100644 --- a/remix/tests/simple.rkt +++ b/remix/tests/simple.rkt @@ -2,6 +2,12 @@ (require remix/stx0 remix/num/gen0) +;; define is replaced with def +(def z 42) +(module+ test + z) + +;; when def has more forms than one, they are put inside of a block (def x (def a 40) (def b 2) @@ -9,22 +15,35 @@ (module+ test x) +;; but of course def supports function definitions. [] is NOT the same +;; as () and defaults to expanding to a block definition (def (f x y) - (+ [(def z (+ x x)) z] y)) + (+ [(def z (+ x x)) + z] + y)) (module+ test (f x x)) +;; cond requires []s for the question-answer pairs. It uses this to +;; make any code in between clauses go in between the `if`s that pop +;; out of the cond macro. finally, cond REQUIRES a #:else clause. (def (g x) (cond [(< x 100) "100"] (def z (/ x 2)) [(< z 100) "div 100"] - [#:else "other"])) + [#:else z])) (module+ test (g 50) (g 199) (g 200)) +;; the @ reader is always on. One fun thing about this is that you can +;; make non-() macros. I wrote a little helper function to turn the +;; string arguments that @{} produces into a string port that has +;; accurate source location information for the original file. datalog +;; uses this to make all the source locations correct, so errors in +;; datalog will give accurate source locations. (require remix/datalog0) (def graph (make-theory)) @datalog[graph]{ @@ -34,26 +53,26 @@ path(X, Y)? } +;; {} is also not (), but is an infix macro (def v7 {3 + 4}) (module+ test v7) +;; {} use C's precedence and considers the things you expect to be +;; operators (def v-26 {2 * 3 - 48 / 4 - 4 * 5}) (module+ test v-26) -(def v15 - {v7 * 2 + 1}) +;; if a symbol contains no alphabetic or numeric characters, then it +;; is considered an operator. This means you can automatically use +;; stuff like & and →, but you won't confuse it with symbols like z +(def v85 + {z * 2 + 1}) (module+ test - v15) - -(def v14 - (def (f x y) (+ x y)) - {v7 ,f v7}) -(module+ test - v14) + v85) (def v1 (def & bitwise-and) @@ -61,6 +80,26 @@ (module+ test v1) +(def v56 + (def (→ x y) (+ (* x x) y)) + {v7 → v7}) +(module+ test + v56) + +;; However, if you use , then you can force anything to be a binary +;; operator and force something that would have been a binary operator +;; into an argument. +(def v14 + (def (f x y) (+ x y)) + {v7 ,f v7}) +(module+ test + v14) + +(def v14b + {v7 ,(λ (x y) (+ x y)) v7}) +(module+ test + v14b) + (def v9 (def & 2) {v7 + ,&})