~jojo/Carth

ref: 749208029494a7c48ce04444a513424f4b998416 Carth/std/macros.carth -rw-r--r-- 983 bytes
74920802JoJo update TODO 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(defmacro apps ()
  (case (op x) x)
  (case (op x1 x2 xs ...) (apps op (op x1 x2) xs ...)))

(defmacro appsr ()
  (case (op x) x)
  (case (op x xs ...) (op x (appsr op xs ...))))

(defmacro list ()
  (case (xs ...) (appsr list/cons xs ... Nil)))

(defmacro +s () (case (xs ...) (apps + xs ...)))
(defmacro =s ()
  (case (x xs ...) (all (= x) (list/iter (list xs ...)))))

(defmacro io/wrap ()
  (case (computation) (IO (fun (real-world) [computation real-world]))))

(defmacro lazy ()
  (case (computation) (Lazy [(unsafe-perform-io mutex/new)
                             (box (Left (fun (Unit) computation)))])))

(defmacro do (<-)
  (case (do-bind ma) ma)
  (case (do-bind (<- a ma) mbs ...)
        (do-bind (fun (a) (do do-bind mbs ...)) ma))
  (case (do-bind (let1 x a) mbs ...)
        (let1 x a (do do-bind mbs ...)))
  (case (do-bind (let bs) mbs ...)
        (let bs (do do-bind mbs ...)))
  (case (do-bind ma mbs ...)
        (do-bind (fun (_) (do do-bind mbs ...)) ma)))