on 3c19574 help sign in
97 lines 3.0 kB history raw
1---
2navhome: /docs/
3next: true
4sort: 2
5title: A new-Gall example app
6---
8# A new-Gall example app
10```
11:: counter app
12:: new gall example, may or may not compile.
13::
14|%
15++ query :> valid queries
16 $% {$number $~} :< current number
17 {$mul-of val/@ud} :< is num multiple of?
18 == ::
19++ prize :> query results
20 $% {$number num/@ud} :< /number
21 {$mul-of mul/?} :< /mul-of
22 == ::
23++ rumor :> query result changes
24 $% {$number delta} :< /number
25 {$mul-of mul/?} ::TODO or just flip? :< /mul-of
26 == ::
27:: the above would ordinarily be placed in sur/, ::
28:: since other apps might want to use it. ::
29++ brain {num/@ud $~} :< application state
30++ delta :> state change
31 $% {$increment $~} :< +1
32 {$decrement $~} :< -1
33 == ::
34--
35::
36|_ {bol/bowl brain}
37::
38++ leak :> read permission
39 |= {who/ship qer/query}
40 ^- ?
41 & :: everyone's allowed
42::
43++ peek :> synchronous read
44 |= qer/query
45 ^- (unit (unit prize))
46 ?- -.qer
47 $number ``[%number num]
48 $mul-of ?: =(0 mul.qer) [~ ~]
49 ``[%mul-of =(0 (mod num mul.qer))]
50 ==
51::
52++ poke-loob :> regular old poke
53 |= inc/?
54 ^- (list delta)
55 :_ ~
56 ?: inc [%increment ~]
57 [%decrement ~]
58::
59++ bake :> apply delta to state
60 |= del/delta
61 ^- (quip opera +>)
62 :- ~
63 ?- -.del
64 $increment +>(num +(num))
65 $decrement +>(num (dec num))
66 ==
67::
68++ feel :> delta to rumor
69 |= {qer/query del/delta}
70 ^- (unit rumor)
71 ?- -.qer
72 $number
73 `[%number del]
74 ::
75 $mul-of
76 :: since we only want to send a rumor if result
77 :: changed, we need to deduce the old state from
78 :: the current state and the delta. depends on the
79 :: fact that state changes before ++feel. funky!
80 :: we could, of course, store mul/? in state, and
81 :: make a delta for it, but should we need to?
82 =/ old
83 .= 0
84 %+ mod
85 ?- -.del
86 $increment (dec num)
87 $decrement +(num)
88 ==
89 mul.qer
90 =/ new =(0 (mod num mul.qer))
91 ?: =(old new) ~
92 `[%mul-of new]
93 ==
94::
95:: not pictured: ++path-to-query
96--
97```