Skip to content

Commit 64f99d3

Browse files
committed
Implement placeholder variable and fix examples
1 parent 9d9e400 commit 64f99d3

File tree

11 files changed

+171
-207
lines changed

11 files changed

+171
-207
lines changed

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,41 @@ philosophy).
3636
Finite state machine
3737

3838
```
39+
(new-declaration (:: tested test)
40+
(:= test @(exec (union @#tested #test)))
41+
(== test ok))
42+
3943
(spec binary [
40-
[(-i e) ok]
41-
[(-i [0 X]) (+i X)]
42-
[(-i [1 X]) (+i X)]])
44+
[(-i []) ok]
45+
[(-i [0|X]) (+i X)]
46+
[(-i [1|X]) (+i X)]])
4347
4448
'input words
49+
(:= e (+i []))
4550
(:: e binary)
46-
(:= e (+i e))
4751
52+
(:= 0 (+i [0]))
53+
(:: 0 binary)
54+
55+
(:= 000 (+i [0 0 0]))
4856
(:: 000 binary)
49-
(:= 000 (+i [0 0 0 e]))
5057
58+
(:= 010 (+i [0 1 0]))
5159
(:: 010 binary)
52-
(:= 010 (+i [0 1 0 e]))
5360
61+
(:= 110 (+i [1 1 0]))
5462
(:: 110 binary)
55-
(:= 110 (+i [1 1 0 e]))
5663
64+
'''
65+
automaton accepting words ending with 00
66+
'''
5767
(:= a1 [
5868
[(-i W) (+a W q0)]
59-
[(-a e q2) accept]
60-
[(-a [0 W] q0) (+a W q0)]
61-
[(-a [0 W] q0) (+a W q1)]
62-
[(-a [1 W] q0) (+a W q0)]
63-
[(-a [0 W] q1) (+a W q2)]])
69+
[(-a [] q2) accept]
70+
[(-a [0|W] q0) (+a W q0)]
71+
[(-a [0|W] q0) (+a W q1)]
72+
[(-a [1|W] q0) (+a W q0)]
73+
[(-a [0|W] q1) (+a W q2)]])
6474
6575
<show kill exec (union @#e #a1)>
6676
<show kill exec (union @#000 #a1)>

examples/binary4.sg

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
(spec u4
2-
(const
3-
(star (-b 1 _) (-b 2 _) (-b 3 _) (-b 4 _) ok)))
1+
(spec u4 [(-b 1 _) (-b 2 _) (-b 3 _) (-b 4 _) ok])
2+
3+
(new-declaration (:: tested test)
4+
(:= test @(exec (process #test #test)))
5+
(== test ok))
46

5-
(def checker
7+
(:= checker
68
(galaxy
79
(interaction
810
(process

examples/nat.sg

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
1-
(spec nat
2-
(const
3-
(star (-nat 0) ok)
4-
(star (-nat (s N)) (+nat N))))
1+
(spec nat [
2+
[(-nat 0) ok]
3+
[(-nat (s N)) (+nat N)]])
54

6-
(def fchecker
7-
(galaxy
8-
(interaction (union @#tested #test))
9-
(expect (const (star arg out)))))
5+
(new-declaration (:: tested test)
6+
(:= test @(exec (union @#tested #test)))
7+
(== test ok))
108

11-
(spec (arrow nat nat)
12-
(const
13-
(star (+nat X) arg)
14-
(star (-nat X) out)))
9+
(new-declaration (:: tested test fchecker)
10+
(:= test @(exec (union @#tested #test)))
11+
(== test [arg out]))
1512

13+
(spec (arrow nat nat) [
14+
[(+nat X) arg]
15+
[(-nat X) out]])
16+
17+
(:= 0 (+nat 0))
1618
(:: 0 nat)
17-
(def 0
18-
(const (star (+nat 0))))
1919

20+
(:= 1 (+nat (s 0)))
2021
(:: 1 nat)
21-
(def 1
22-
(const
23-
(star (+nat (s 0)))))
2422

23+
(:= 2 <+nat s s 0>)
2524
(:: 2 nat)
26-
(def 2
27-
(const
28-
(star <+nat s s /0>)))
29-
30-
(:: add1 ((arrow nat nat) / fchecker))
31-
(def add1
32-
(const
33-
(star (-nat X) (+nat (s X)))))
34-
35-
(def is_empty
36-
(const
37-
(star (-nat 0) (res 1))
38-
(star (-nat (s _)) (res 0))))
39-
40-
(show-exec (union @#add1 #2))
41-
(show-exec (union #is_empty @#0))
42-
(show-exec (union #is_empty @#1))
25+
26+
(:= add1 [(-nat X) (+nat (s X))])
27+
(:: add1 (arrow nat nat) fchecker)
28+
29+
(:= is_empty [
30+
[(-nat 0) (res 1)]
31+
[(-nat (s _)) (res 0)]])
32+
33+
<show exec (union @#add1 #2)>
34+
<show exec (union #is_empty @#0)>
35+
<show exec (union #is_empty @#1)>

examples/npda.sg

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
1-
(spec binary
2-
(const
3-
(star (-i e) ok)
4-
(star (-i [0 X]) (+i X))
5-
(star (-i [1 X]) (+i X))))
1+
(new-declaration (:: tested test)
2+
(:= test @(exec (union @#tested #test)))
3+
(== test ok))
4+
5+
(spec binary [
6+
[(-i []) ok]
7+
[(-i [0|X]) (+i X)]
8+
[(-i [1|X]) (+i X)]])
69

710
'input words
11+
(:= e (+i []))
812
(:: e binary)
9-
(def e
10-
(const (star (+i e))))
1113

14+
(:= 0000 (+i [0 0 0 0]))
1215
(:: 0000 binary)
13-
(def 0000
14-
(const (star (+i [0 0 0 0 e]))))
1516

17+
(:= 0110 (+i [0 1 1 0]))
1618
(:: 0110 binary)
17-
(def 0110
18-
(const (star (+i [0 1 1 0 e]))))
1919

20+
(:= 1110 (+i [1 1 1 0]))
2021
(:: 1110 binary)
21-
(def 1110
22-
(const (star (+i [1 1 1 0 e]))))
2322

24-
(def a1
25-
(galaxy
26-
(initial
27-
(const
28-
(star (-i W) (+a W e q0))))
29-
(final
30-
(const
31-
(star (-a e e q0) accept)
32-
(star (-a e e q1) accept)))
33-
(transitions
34-
(const
35-
(star (-a [0 W] S q0) (+a W [0 S] q0))
36-
(star (-a [1 W] S q0) (+a W [1 S] q0))
37-
(star (-a W S q0) (+a W S q1))
38-
(star (-a [0 W] [0 S] q1) (+a W S q1))
39-
(star (-a [1 W] [1 S] q1) (+a W S q1))))))
23+
(:= a1 [
24+
'initial
25+
[(-i W) (+a W [] q0)]
26+
'final
27+
[(-a [] [] q0) accept]
28+
[(-a [] [] q1) accept]
29+
'transitions
30+
[(-a [0|W] S q0) (+a W [0|S] q0)]
31+
[(-a [1|W] S q0) (+a W [1|S] q0)]
32+
[(-a W S q0) (+a W S q1)]
33+
[(-a [0|W] [0|S] q1) (+a W S q1)]
34+
[(-a [1|W] [1|S] q1) (+a W S q1)]])
4035

41-
(show (kill (exec
42-
(union @#e #a1))))
43-
(show (kill (exec
44-
(union @#0000 #a1))))
45-
(show (kill (exec
46-
(union @#0110 #a1))))
47-
(show (kill (exec
48-
(union @#1110 #a1))))
36+
<show kill exec (union @#e #a1)>
37+
<show kill exec (union @#0000 #a1)>
38+
<show kill exec (union @#0110 #a1)>
39+
<show kill exec (union @#1110 #a1)>

examples/prolog.sg

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
' unary addition
2-
(def add
3-
(const
4-
(star (+add 0 Y Y))
5-
(star (-add X Y Z) (+add (s X) Y (s Z)))))
2+
(:= add [
3+
[(+add 0 Y Y)]
4+
[(-add X Y Z) (+add (s X) Y (s Z))]])
65

76
' 2 + 2 = R
8-
(def query
9-
(const
10-
(star (-add <s s /0> <s s /0> R) R)))
7+
(:= query [(-add <s s 0> <s s 0> R) R])
118

12-
(show-exec (union #add @#query))
9+
<show exec (union #add @#query)>
1310

14-
(def graph
15-
(const
16-
(star (+from 1) (+to 2))
17-
(star (+from 1) (+to 3))
18-
(star (+from 3) (+to 2))
19-
(star (+from 3) (+to 4))))
20-
'(star (+from 4) (+to 3))
11+
(:= graph [
12+
[(+from 1) (+to 2)]
13+
[(+from 1) (+to 3)]
14+
[(+from 3) (+to 2)]
15+
'[(+from 4) (+to 3)]
16+
[(+from 3) (+to 4)]])
2117

22-
(def composition
23-
(const
24-
(star (-to X) (-from X))))
18+
(:= composition [(-to X) (-from X)])
2519

2620
' is there a path between 1 and 4?
27-
(def query
28-
(const
29-
(@star (-from 1))
30-
(star (-to 4) ok)))
21+
(:= query [
22+
@[(-from 1)]
23+
[(-to 4) ok]])
3124

32-
(show-exec (process
25+
<show exec (process
3326
#query
34-
(union #graph #composition)
35-
&kill))
27+
(union #graph #composition))>

examples/stack.sg

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
(show-exec (process
2-
(const (star (+stack0 e)))
1+
<show exec (process
2+
(+stack0 [])
33
'push 1 then 0
4-
(const
5-
(star (-stack0 X) (+stack1 [1 X]))
6-
(star (-stack1 X) (+stack2 [0 X])))
4+
[(-stack0 X) (+stack1 [1|X])]
5+
[(-stack1 X) (+stack2 [0|X])]
76

87
'pop & save
9-
(const (star (-stack2 [C X]) (+stack3 X) (+save C)))
8+
[(-stack2 [C|X]) (+stack3 X) (+save C)]
109

1110
'conditional duplication
12-
(const
13-
(star (-stack3 [0 X]) (+stack4 [0 0 X]))
14-
(star (-stack3 [1 X]) (+stack4 [1 1 X])))
11+
[(-stack3 [0|X]) (+stack4 [0 0|X])]
12+
[(-stack3 [1|X]) (+stack4 [1 1|X])]
1513

1614
'freeze information
17-
(const (star (-stack4 X) (stack X)))
15+
[(-save C) (save C)]
1816

19-
(const (star (-save C) (save C)))
20-
'kill remaining polarized stars
21-
&kill))
17+
'clean
18+
[(-stack4 _)])>

examples/sumtypes.sg

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
(def checker
2-
(galaxy
3-
(interaction (union @#tested #test))
4-
(expect (const (star ok)))))
1+
(new-declaration (:: tested test)
2+
(:= test @(exec (union @#tested #test)))
3+
(== test ok))
54

6-
(spec direction
7-
(const
8-
(star -north ok)
9-
(star -south ok)
10-
(star -west ok)
11-
(star -east ok)))
5+
(spec direction [
6+
[-north ok]
7+
[-south ok]
8+
[-west ok]
9+
[-east ok]])
1210

13-
(:: n (direction / checker))
14-
(def n
15-
(const (star +north)))
11+
(:= n +north)
12+
(:: n direction)
1613

17-
(spec result
18-
(const
19-
(star (-ok X) ok)
20-
(star (-error X) ok)))
14+
(spec result [
15+
[(-ok X) ok]
16+
[(-error X) ok]])
2117

22-
(:: x (result / checker))
23-
(def x
24-
(const (star (+ok a))))
18+
(:= x (+ok a))
19+
(:: x result)
2520

2621
'pattern matching
27-
(def get_ok
28-
(const
29-
(star (-ok X) X)
30-
(star (-error X) (+error X))))
22+
(:= get_ok [
23+
[(-ok X) X]
24+
[(-error X) (+error X)]])
3125

32-
(show-exec (union #get_ok @#x))
26+
<show exec (union #get_ok @#x)>

0 commit comments

Comments
 (0)