~technomancy/fennel

ref: 3ffd391d7fa3e774056555abd53156bb535d0c39 fennel/test/macros.fnl -rw-r--r-- 761 bytes
3ffd391dPhil Hagelberg Use semicolon instead of do/end as paren disambiguation. 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
;; this module is loaded by the test suite.

(fn def [] (error "oh no") 32)
(fn abc [] (def) 1)

{"->1" (fn [val ...]
        (var x val)
        (each [_ elt (ipairs [...])]
          (table.insert elt 2 x)
          (set x elt))
        x)
 :defn1 (fn [name args ...]
          (assert (sym? name) "defn1: function names must be symbols")
          `(global ,name (fn ,args ,...)))
 :inc   (fn [n] (if (not (list? n)) `(+ ,n 1)
                    `(let [num# ,n] (+ num# 1))))
 :inc! (fn [a ?n] `(set ,a (+ ,a (or ,?n 1))))
 :multigensym (fn []
                `(let [x# {:abc (fn [] 518)}
                       y# {:one 1}]
                   (+ (x#:abc) y#.one)))
 :unsandboxed (fn [] (view [:no :sandbox]))
 :fail-one (fn [x] (when (= x 1) (abc)) true)}