-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaddition.amod
102 lines (85 loc) · 1.94 KB
/
addition.amod
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
~~ model ~~
// The name of the model (used when generating code and for error messages)
name: addition
// Description of the model (currently output as a comment in the generated code)
description: 'This is a model which adds numbers. From the ccm u1_addition.py tutorial.'
// A list of authors. These are output as comments in the generated code.
authors {
'Andy Maloney <[email protected]>'
}
// Examples of starting goals to use when running the model
examples {
[add: 3 1 nil nil]
[add: 5 2 nil nil]
}
~~ config ~~
gactar {
// Logging level can be 'min', 'info' (default), or 'detail'
log_level: 'detail'
// Show detailed information about activations (if available)
trace_activations: false
}
// Declare chunk types and their layouts
chunks {
[add: num1 num2 count sum]
[count: number next]
}
~~ init ~~
// Initialize the memory
memory {
[count: 0 1]
[count: 1 2]
[count: 2 3]
[count: 3 4]
[count: 4 5]
[count: 5 6]
[count: 6 7]
[count: 7 8]
}
// Default goal
goal [add: 3 1 nil nil]
~~ productions ~~
// Name of the production
initializeAddition {
// Optional description
description: 'Starting point - first production to match'
// Buffers to match
match {
goal [add: ?num1 * * nil]
}
// Statements to execute
do {
set goal.count to 0
set goal.sum to ?num1
recall [count: ?num1 *]
}
}
terminateAddition {
match {
goal [add: * ?num2 ?num2 ?answer]
}
do {
print ?answer
stop
}
}
incrementSum {
match {
goal [add: * ?num2 ?count ?sum] when (?count != ?num2)
retrieval [count: ?sum ?next]
}
do {
set goal.sum to ?next
recall [count: ?count *]
}
}
incrementCount {
match {
goal [add: * * ?count ?sum]
retrieval [count: ?count ?next]
}
do {
set goal.count to ?next
recall [count: ?sum *]
}
}