forked from eigenhombre/l1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz-legal.l1
executable file
·80 lines (60 loc) · 1.42 KB
/
fuzz-legal.l1
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env l1
;; fuzzing variant which only creates and evaluates legally evaluable expressions.
(defn one-of (() . xs)
(randchoice xs))
(defn randpos (n) (inc (randint (inc n))))
(defn cool (x) (/ x 2))
(defn randnum (n) (fuse (randigits (randpos n))))
(defn num (n)
((one-of randnum
arith
dolen)
(cool n)))
(defn nums (n)
(repeatedly (randint n) (partial num n)))
(defn atom (n)
(fuse (randalpha (randpos n))))
(defn atoms (n)
(repeatedly (randpos n) (partial atom n)))
(defn quoteatom (n)
(list 'quote (atom n)))
(defn nums (n)
(repeatedly (randpos n)
(partial num n)))
(defn /not0 (x . xs)
(doc (do not divide by zero))
(let ((divisor (apply * xs)))
(if (zero? divisor)
1
(/ x divisor))))
(defn arith (n)
(list* (one-of '+ '- '* '/not0)
(nums (cool n))))
(defn quote-atom (n)
`(quote ~(atom n)))
(defn quote-list (n)
(list 'quote ((one-of range
nums)
(cool n))))
(defn boolean (_)
(one-of t ()))
(defn dolen (n)
(list 'len ((one-of quote-list
dosplit)
(cool n))))
(defn dosplit (n)
(list 'split
((one-of quote-atom num) n)))
(defn expr (n)
((one-of arith
quote-atom
quote-list
dolen
boolean)
n))
(while t
(let ((e (expr 100)))
(println e
'==>
(eval e))
(println)))