shen-ruby 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY.md +5 -0
- data/README.md +8 -12
- data/Rakefile +4 -9
- data/bin/shen_test_suite.rb +0 -1
- data/bin/srrepl +2 -4
- data/lib/shen_ruby/shen.rb +98 -0
- data/lib/shen_ruby/version.rb +1 -1
- data/shen-ruby.gemspec +3 -3
- data/shen/README.txt +9 -13
- data/shen/release/BSD +24 -0
- data/shen/release/klambda/core.kl +157 -0
- data/shen/release/klambda/declarations.kl +109 -0
- data/shen/release/klambda/load.kl +59 -0
- data/shen/release/klambda/macros.kl +91 -0
- data/shen/release/klambda/prolog.kl +228 -0
- data/shen/release/klambda/reader.kl +198 -0
- data/shen/release/klambda/sequent.kl +142 -0
- data/shen/release/klambda/sys.kl +253 -0
- data/shen/release/klambda/t-star.kl +123 -0
- data/shen/release/klambda/toplevel.kl +110 -0
- data/shen/release/klambda/track.kl +79 -0
- data/shen/release/{k_lambda → klambda}/types.kl +41 -63
- data/shen/release/klambda/writer.kl +81 -0
- data/shen/release/klambda/yacc.kl +87 -0
- data/shen/release/license.pdf +0 -0
- data/shen/release/test_programs/Chap13/problems.txt +26 -26
- data/shen/release/test_programs/README.shen +52 -52
- data/shen/release/test_programs/TinyLispFunctions.txt +15 -15
- data/shen/release/test_programs/TinyTypes.shen +55 -55
- data/shen/release/test_programs/binary.shen +24 -24
- data/shen/release/test_programs/bubble_version_1.shen +28 -28
- data/shen/release/test_programs/bubble_version_2.shen +22 -22
- data/shen/release/test_programs/calculator.shen +21 -21
- data/shen/release/test_programs/cartprod.shen +23 -23
- data/shen/release/test_programs/change.shen +25 -25
- data/shen/release/test_programs/classes-defaults.shen +94 -94
- data/shen/release/test_programs/classes-inheritance.shen +100 -100
- data/shen/release/test_programs/classes-typed.shen +74 -74
- data/shen/release/test_programs/classes-untyped.shen +46 -46
- data/shen/release/test_programs/depth_.shen +14 -14
- data/shen/release/test_programs/einstein.shen +34 -34
- data/shen/release/test_programs/fruit_machine.shen +46 -46
- data/shen/release/test_programs/interpreter.shen +217 -217
- data/shen/release/test_programs/metaprog.shen +85 -85
- data/shen/release/test_programs/minim.shen +192 -192
- data/shen/release/test_programs/mutual.shen +11 -11
- data/shen/release/test_programs/n_queens.shen +45 -45
- data/shen/release/test_programs/newton_version_1.shen +33 -33
- data/shen/release/test_programs/newton_version_2.shen +24 -24
- data/shen/release/test_programs/parse.prl +14 -14
- data/shen/release/test_programs/parser.shen +51 -51
- data/shen/release/test_programs/powerset.shen +10 -10
- data/shen/release/test_programs/prime.shen +10 -10
- data/shen/release/test_programs/prolog.shen +78 -78
- data/shen/release/test_programs/proof_assistant.shen +80 -80
- data/shen/release/test_programs/proplog_version_1.shen +25 -25
- data/shen/release/test_programs/proplog_version_2.shen +27 -27
- data/shen/release/test_programs/qmachine.shen +66 -66
- data/shen/release/test_programs/red-black.shen +54 -54
- data/shen/release/test_programs/search.shen +55 -55
- data/shen/release/test_programs/semantic_net.shen +44 -44
- data/shen/release/test_programs/spreadsheet.shen +34 -34
- data/shen/release/test_programs/stack.shen +27 -27
- data/shen/release/test_programs/streams.shen +20 -20
- data/shen/release/test_programs/strings.shen +57 -57
- data/shen/release/test_programs/structures-typed.shen +71 -71
- data/shen/release/test_programs/structures-untyped.shen +41 -41
- data/shen/release/test_programs/tests.shen +232 -232
- data/shen/release/test_programs/types.shen +11 -11
- data/shen/release/test_programs/whist.shen +239 -239
- data/shen/release/test_programs/yacc.shen +132 -132
- metadata +21 -35
- data/shen/lib/shen_ruby/shen.rb +0 -160
- data/shen/license.txt +0 -34
- data/shen/release/benchmarks/N_queens.shen +0 -45
- data/shen/release/benchmarks/README.shen +0 -14
- data/shen/release/benchmarks/benchmarks.shen +0 -52
- data/shen/release/benchmarks/bigprog +0 -2173
- data/shen/release/benchmarks/einstein.shen +0 -33
- data/shen/release/benchmarks/heatwave.gif +0 -0
- data/shen/release/benchmarks/interpreter.shen +0 -219
- data/shen/release/benchmarks/jnk.shen +0 -194
- data/shen/release/benchmarks/picture.jpg +0 -0
- data/shen/release/benchmarks/plato.jpg +0 -0
- data/shen/release/benchmarks/powerset.shen +0 -10
- data/shen/release/benchmarks/prime.shen +0 -10
- data/shen/release/benchmarks/short.shen +0 -129
- data/shen/release/benchmarks/text.txt +0 -68
- data/shen/release/k_lambda/core.kl +0 -181
- data/shen/release/k_lambda/declarations.kl +0 -131
- data/shen/release/k_lambda/load.kl +0 -84
- data/shen/release/k_lambda/macros.kl +0 -112
- data/shen/release/k_lambda/prolog.kl +0 -252
- data/shen/release/k_lambda/reader.kl +0 -222
- data/shen/release/k_lambda/sequent.kl +0 -166
- data/shen/release/k_lambda/sys.kl +0 -271
- data/shen/release/k_lambda/t-star.kl +0 -139
- data/shen/release/k_lambda/toplevel.kl +0 -135
- data/shen/release/k_lambda/track.kl +0 -103
- data/shen/release/k_lambda/writer.kl +0 -105
- data/shen/release/k_lambda/yacc.kl +0 -113
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
(declare defclass [symbol --> [list [class A]] --> [list [symbol * symbol]] --> symbol])
|
|
2
|
-
|
|
3
|
-
(datatype subtype
|
|
4
|
-
|
|
5
|
-
(subtype B A); X : B;
|
|
6
|
-
_____________________
|
|
7
|
-
X : A;)
|
|
8
|
-
|
|
9
|
-
(define defclass
|
|
10
|
-
Class SuperClasses ClassDef
|
|
11
|
-
-> (let Attributes (map fst ClassDef)
|
|
12
|
-
Inherited (put-prop Class attributes
|
|
13
|
-
(append Attributes (collect-attributes SuperClasses)))
|
|
14
|
-
Types (record-attribute-types Class ClassDef)
|
|
15
|
-
Assoc (map (/. Attribute [Attribute | fail!]) Inherited)
|
|
16
|
-
ClassDef [[class | Class] | Assoc]
|
|
17
|
-
Store (put-prop Class classdef ClassDef)
|
|
18
|
-
RecordClass (axiom Class Class [class Class])
|
|
19
|
-
SubTypes (record-subtypes Class SuperClasses)
|
|
20
|
-
Class))
|
|
21
|
-
|
|
22
|
-
(define record-subtypes
|
|
23
|
-
_ [] -> _
|
|
24
|
-
Class SuperClasses -> (eval [datatype (concat Class superclasses)
|
|
25
|
-
| (record-subtypes-help Class SuperClasses)]))
|
|
26
|
-
|
|
27
|
-
(define record-subtypes-help
|
|
28
|
-
_ [] -> []
|
|
29
|
-
Class [SuperClass | SuperClasses] -> [_______________________
|
|
30
|
-
[subtype SuperClass Class]; |
|
|
31
|
-
(record-subtypes-help Class SuperClasses)])
|
|
32
|
-
|
|
33
|
-
(define collect-attributes
|
|
34
|
-
[] -> []
|
|
35
|
-
[SuperClass | SuperClasses] -> (append (get-prop SuperClass attributes [])
|
|
36
|
-
(collect-attributes SuperClasses)))
|
|
37
|
-
|
|
38
|
-
(define axiom
|
|
39
|
-
DataType X A -> (eval [datatype DataType
|
|
40
|
-
________
|
|
41
|
-
X : A;]))
|
|
42
|
-
|
|
43
|
-
(define record-attribute-types
|
|
44
|
-
_ [] -> []
|
|
45
|
-
Class [(@p Attribute Type) | ClassDef]
|
|
46
|
-
-> (let DataTypeName (concat Class Attribute)
|
|
47
|
-
DataType (axiom DataTypeName Attribute [attribute Class Type])
|
|
48
|
-
(record-attribute-types Class ClassDef)))
|
|
49
|
-
|
|
50
|
-
(declare make-instance [[class Class] --> [instance Class]])
|
|
51
|
-
|
|
52
|
-
(define make-instance
|
|
53
|
-
Class -> (let ClassDef (get-prop Class classdef [])
|
|
54
|
-
(if (empty? ClassDef)
|
|
55
|
-
(error "class ~A does not exist~%" Class)
|
|
56
|
-
ClassDef)))
|
|
57
|
-
|
|
58
|
-
(declare get-value [[attribute Class A] --> [instance Class] --> A])
|
|
59
|
-
|
|
60
|
-
(define get-value
|
|
61
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
62
|
-
(get-value-test LookUp)))
|
|
63
|
-
|
|
64
|
-
(define get-value-test
|
|
65
|
-
[ ] -> (error "no such attribute!~%")
|
|
66
|
-
[_ | fail!] -> (error "no such value!~%")
|
|
67
|
-
[_ | Value] -> Value)
|
|
68
|
-
|
|
69
|
-
(declare has-value? [[attribute Class A] --> [instance Class] --> boolean])
|
|
70
|
-
|
|
71
|
-
(define has-value?
|
|
72
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
73
|
-
(has-value-test LookUp)))
|
|
74
|
-
|
|
75
|
-
(define has-value-test
|
|
76
|
-
[ ] -> (error "no such attribute!~%")
|
|
77
|
-
[_ | fail!] -> false
|
|
78
|
-
_ -> true)
|
|
79
|
-
|
|
80
|
-
(declare has-attribute? [symbol --> [instance Class] --> boolean])
|
|
81
|
-
|
|
82
|
-
(define has-attribute?
|
|
83
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
84
|
-
(not (empty? LookUp))))
|
|
85
|
-
|
|
86
|
-
(declare change-value [[instance Class] --> [attribute Class A] --> A --> [instance Class]])
|
|
87
|
-
|
|
88
|
-
(define change-value
|
|
89
|
-
_ class _ -> (error "cannot change the class of an instance!~%")
|
|
90
|
-
[ ] _ _ -> (error "no such attribute!~%")
|
|
91
|
-
[[Attribute | _] | Instance] Attribute Value
|
|
92
|
-
-> [[Attribute | Value] | Instance]
|
|
93
|
-
[Slot | Instance] Attribute Value
|
|
94
|
-
-> [Slot | (change-value Instance Attribute Value)])
|
|
95
|
-
|
|
96
|
-
(declare instance-of [[instance Class] --> [class Class]])
|
|
97
|
-
|
|
98
|
-
(define instance-of
|
|
99
|
-
[[class | Class] | _] -> Class
|
|
100
|
-
_ -> (error "not a class instance!"))
|
|
1
|
+
(declare defclass [symbol --> [list [class A]] --> [list [symbol * symbol]] --> symbol])
|
|
2
|
+
|
|
3
|
+
(datatype subtype
|
|
4
|
+
|
|
5
|
+
(subtype B A); X : B;
|
|
6
|
+
_____________________
|
|
7
|
+
X : A;)
|
|
8
|
+
|
|
9
|
+
(define defclass
|
|
10
|
+
Class SuperClasses ClassDef
|
|
11
|
+
-> (let Attributes (map fst ClassDef)
|
|
12
|
+
Inherited (put-prop Class attributes
|
|
13
|
+
(append Attributes (collect-attributes SuperClasses)))
|
|
14
|
+
Types (record-attribute-types Class ClassDef)
|
|
15
|
+
Assoc (map (/. Attribute [Attribute | fail!]) Inherited)
|
|
16
|
+
ClassDef [[class | Class] | Assoc]
|
|
17
|
+
Store (put-prop Class classdef ClassDef)
|
|
18
|
+
RecordClass (axiom Class Class [class Class])
|
|
19
|
+
SubTypes (record-subtypes Class SuperClasses)
|
|
20
|
+
Class))
|
|
21
|
+
|
|
22
|
+
(define record-subtypes
|
|
23
|
+
_ [] -> _
|
|
24
|
+
Class SuperClasses -> (eval [datatype (concat Class superclasses)
|
|
25
|
+
| (record-subtypes-help Class SuperClasses)]))
|
|
26
|
+
|
|
27
|
+
(define record-subtypes-help
|
|
28
|
+
_ [] -> []
|
|
29
|
+
Class [SuperClass | SuperClasses] -> [_______________________
|
|
30
|
+
[subtype SuperClass Class]; |
|
|
31
|
+
(record-subtypes-help Class SuperClasses)])
|
|
32
|
+
|
|
33
|
+
(define collect-attributes
|
|
34
|
+
[] -> []
|
|
35
|
+
[SuperClass | SuperClasses] -> (append (get-prop SuperClass attributes [])
|
|
36
|
+
(collect-attributes SuperClasses)))
|
|
37
|
+
|
|
38
|
+
(define axiom
|
|
39
|
+
DataType X A -> (eval [datatype DataType
|
|
40
|
+
________
|
|
41
|
+
X : A;]))
|
|
42
|
+
|
|
43
|
+
(define record-attribute-types
|
|
44
|
+
_ [] -> []
|
|
45
|
+
Class [(@p Attribute Type) | ClassDef]
|
|
46
|
+
-> (let DataTypeName (concat Class Attribute)
|
|
47
|
+
DataType (axiom DataTypeName Attribute [attribute Class Type])
|
|
48
|
+
(record-attribute-types Class ClassDef)))
|
|
49
|
+
|
|
50
|
+
(declare make-instance [[class Class] --> [instance Class]])
|
|
51
|
+
|
|
52
|
+
(define make-instance
|
|
53
|
+
Class -> (let ClassDef (get-prop Class classdef [])
|
|
54
|
+
(if (empty? ClassDef)
|
|
55
|
+
(error "class ~A does not exist~%" Class)
|
|
56
|
+
ClassDef)))
|
|
57
|
+
|
|
58
|
+
(declare get-value [[attribute Class A] --> [instance Class] --> A])
|
|
59
|
+
|
|
60
|
+
(define get-value
|
|
61
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
62
|
+
(get-value-test LookUp)))
|
|
63
|
+
|
|
64
|
+
(define get-value-test
|
|
65
|
+
[ ] -> (error "no such attribute!~%")
|
|
66
|
+
[_ | fail!] -> (error "no such value!~%")
|
|
67
|
+
[_ | Value] -> Value)
|
|
68
|
+
|
|
69
|
+
(declare has-value? [[attribute Class A] --> [instance Class] --> boolean])
|
|
70
|
+
|
|
71
|
+
(define has-value?
|
|
72
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
73
|
+
(has-value-test LookUp)))
|
|
74
|
+
|
|
75
|
+
(define has-value-test
|
|
76
|
+
[ ] -> (error "no such attribute!~%")
|
|
77
|
+
[_ | fail!] -> false
|
|
78
|
+
_ -> true)
|
|
79
|
+
|
|
80
|
+
(declare has-attribute? [symbol --> [instance Class] --> boolean])
|
|
81
|
+
|
|
82
|
+
(define has-attribute?
|
|
83
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
84
|
+
(not (empty? LookUp))))
|
|
85
|
+
|
|
86
|
+
(declare change-value [[instance Class] --> [attribute Class A] --> A --> [instance Class]])
|
|
87
|
+
|
|
88
|
+
(define change-value
|
|
89
|
+
_ class _ -> (error "cannot change the class of an instance!~%")
|
|
90
|
+
[ ] _ _ -> (error "no such attribute!~%")
|
|
91
|
+
[[Attribute | _] | Instance] Attribute Value
|
|
92
|
+
-> [[Attribute | Value] | Instance]
|
|
93
|
+
[Slot | Instance] Attribute Value
|
|
94
|
+
-> [Slot | (change-value Instance Attribute Value)])
|
|
95
|
+
|
|
96
|
+
(declare instance-of [[instance Class] --> [class Class]])
|
|
97
|
+
|
|
98
|
+
(define instance-of
|
|
99
|
+
[[class | Class] | _] -> Class
|
|
100
|
+
_ -> (error "not a class instance!"))
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
(declare defclass [symbol --> [list [symbol * symbol]] --> symbol])
|
|
2
|
-
|
|
3
|
-
(define defclass
|
|
4
|
-
Class ClassDef -> (let Attributes (map (function fst) ClassDef)
|
|
5
|
-
Types (record-attribute-types Class ClassDef)
|
|
6
|
-
Assoc (map (/. Attribute [Attribute | fail]) Attributes)
|
|
7
|
-
ClassDef [[class | Class] | Assoc]
|
|
8
|
-
Store (put Class classdef ClassDef)
|
|
9
|
-
RecordClass (axiom Class Class [class Class])
|
|
10
|
-
Class))
|
|
11
|
-
|
|
12
|
-
(define axiom
|
|
13
|
-
DataType X A -> (eval [datatype DataType
|
|
14
|
-
________
|
|
15
|
-
X : A;]))
|
|
16
|
-
|
|
17
|
-
(define record-attribute-types
|
|
18
|
-
_ [] -> []
|
|
19
|
-
Class [(@p Attribute Type) | ClassDef]
|
|
20
|
-
-> (let DataTypeName (concat Class Attribute)
|
|
21
|
-
DataType (axiom DataTypeName Attribute [attribute Class Type])
|
|
22
|
-
(record-attribute-types Class ClassDef)))
|
|
23
|
-
|
|
24
|
-
(declare make-instance [[class Class] --> [instance Class]])
|
|
25
|
-
|
|
26
|
-
(define make-instance
|
|
27
|
-
Class -> (let ClassDef (trap-error (get Class classdef) (/. E []))
|
|
28
|
-
(if (empty? ClassDef)
|
|
29
|
-
(error "class ~A does not exist~%" Class)
|
|
30
|
-
ClassDef)))
|
|
31
|
-
|
|
32
|
-
(declare get-value [[attribute Class A] --> [instance Class] --> A])
|
|
33
|
-
|
|
34
|
-
(define get-value
|
|
35
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
36
|
-
(get-value-test LookUp)))
|
|
37
|
-
|
|
38
|
-
(define get-value-test
|
|
39
|
-
[ ] -> (error "no such attribute!~%")
|
|
40
|
-
[_ | fail!] -> (error "no such value!~%")
|
|
41
|
-
[_ | Value] -> Value)
|
|
42
|
-
|
|
43
|
-
(declare has-value? [[attribute Class A] --> [instance Class] --> boolean])
|
|
44
|
-
|
|
45
|
-
(define has-value?
|
|
46
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
47
|
-
(has-value-test LookUp)))
|
|
48
|
-
|
|
49
|
-
(define has-value-test
|
|
50
|
-
[ ] -> (error "no such attribute!~%")
|
|
51
|
-
[_ | fail] -> false
|
|
52
|
-
_ -> true)
|
|
53
|
-
|
|
54
|
-
(declare has-attribute? [symbol --> [instance Class] --> boolean])
|
|
55
|
-
|
|
56
|
-
(define has-attribute?
|
|
57
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
58
|
-
(not (empty? LookUp))))
|
|
59
|
-
|
|
60
|
-
(declare change-value [[instance Class] --> [attribute Class A] --> A --> [instance Class]])
|
|
61
|
-
|
|
62
|
-
(define change-value
|
|
63
|
-
_ class _ -> (error "cannot change the class of an instance!~%")
|
|
64
|
-
[ ] _ _ -> (error "no such attribute!~%")
|
|
65
|
-
[[Attribute | _] | Instance] Attribute Value
|
|
66
|
-
-> [[Attribute | Value] | Instance]
|
|
67
|
-
[Slot | Instance] Attribute Value
|
|
68
|
-
-> [Slot | (change-value Instance Attribute Value)])
|
|
69
|
-
|
|
70
|
-
(declare instance-of [[instance Class] --> [class Class]])
|
|
71
|
-
|
|
72
|
-
(define instance-of
|
|
73
|
-
[[class | Class] | _] -> Class
|
|
74
|
-
_ -> (error "not a class instance!"))
|
|
1
|
+
(declare defclass [symbol --> [list [symbol * symbol]] --> symbol])
|
|
2
|
+
|
|
3
|
+
(define defclass
|
|
4
|
+
Class ClassDef -> (let Attributes (map (function fst) ClassDef)
|
|
5
|
+
Types (record-attribute-types Class ClassDef)
|
|
6
|
+
Assoc (map (/. Attribute [Attribute | fail]) Attributes)
|
|
7
|
+
ClassDef [[class | Class] | Assoc]
|
|
8
|
+
Store (put Class classdef ClassDef)
|
|
9
|
+
RecordClass (axiom Class Class [class Class])
|
|
10
|
+
Class))
|
|
11
|
+
|
|
12
|
+
(define axiom
|
|
13
|
+
DataType X A -> (eval [datatype DataType
|
|
14
|
+
________
|
|
15
|
+
X : A;]))
|
|
16
|
+
|
|
17
|
+
(define record-attribute-types
|
|
18
|
+
_ [] -> []
|
|
19
|
+
Class [(@p Attribute Type) | ClassDef]
|
|
20
|
+
-> (let DataTypeName (concat Class Attribute)
|
|
21
|
+
DataType (axiom DataTypeName Attribute [attribute Class Type])
|
|
22
|
+
(record-attribute-types Class ClassDef)))
|
|
23
|
+
|
|
24
|
+
(declare make-instance [[class Class] --> [instance Class]])
|
|
25
|
+
|
|
26
|
+
(define make-instance
|
|
27
|
+
Class -> (let ClassDef (trap-error (get Class classdef) (/. E []))
|
|
28
|
+
(if (empty? ClassDef)
|
|
29
|
+
(error "class ~A does not exist~%" Class)
|
|
30
|
+
ClassDef)))
|
|
31
|
+
|
|
32
|
+
(declare get-value [[attribute Class A] --> [instance Class] --> A])
|
|
33
|
+
|
|
34
|
+
(define get-value
|
|
35
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
36
|
+
(get-value-test LookUp)))
|
|
37
|
+
|
|
38
|
+
(define get-value-test
|
|
39
|
+
[ ] -> (error "no such attribute!~%")
|
|
40
|
+
[_ | fail!] -> (error "no such value!~%")
|
|
41
|
+
[_ | Value] -> Value)
|
|
42
|
+
|
|
43
|
+
(declare has-value? [[attribute Class A] --> [instance Class] --> boolean])
|
|
44
|
+
|
|
45
|
+
(define has-value?
|
|
46
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
47
|
+
(has-value-test LookUp)))
|
|
48
|
+
|
|
49
|
+
(define has-value-test
|
|
50
|
+
[ ] -> (error "no such attribute!~%")
|
|
51
|
+
[_ | fail] -> false
|
|
52
|
+
_ -> true)
|
|
53
|
+
|
|
54
|
+
(declare has-attribute? [symbol --> [instance Class] --> boolean])
|
|
55
|
+
|
|
56
|
+
(define has-attribute?
|
|
57
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
58
|
+
(not (empty? LookUp))))
|
|
59
|
+
|
|
60
|
+
(declare change-value [[instance Class] --> [attribute Class A] --> A --> [instance Class]])
|
|
61
|
+
|
|
62
|
+
(define change-value
|
|
63
|
+
_ class _ -> (error "cannot change the class of an instance!~%")
|
|
64
|
+
[ ] _ _ -> (error "no such attribute!~%")
|
|
65
|
+
[[Attribute | _] | Instance] Attribute Value
|
|
66
|
+
-> [[Attribute | Value] | Instance]
|
|
67
|
+
[Slot | Instance] Attribute Value
|
|
68
|
+
-> [Slot | (change-value Instance Attribute Value)])
|
|
69
|
+
|
|
70
|
+
(declare instance-of [[instance Class] --> [class Class]])
|
|
71
|
+
|
|
72
|
+
(define instance-of
|
|
73
|
+
[[class | Class] | _] -> Class
|
|
74
|
+
_ -> (error "not a class instance!"))
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
(define defclass
|
|
2
|
-
Class Attributes
|
|
3
|
-
-> (let Assoc (map (/. Attribute [Attribute | fail]) Attributes)
|
|
4
|
-
ClassDef [[class | Class] | Assoc]
|
|
5
|
-
Store (put Class classdef ClassDef)
|
|
6
|
-
Class))
|
|
7
|
-
|
|
8
|
-
(define make-instance
|
|
9
|
-
Class -> (let ClassDef (trap-error (get Class classdef) (/. E []))
|
|
10
|
-
(if (empty? ClassDef)
|
|
11
|
-
(error "class ~A does not exist~%" Class)
|
|
12
|
-
ClassDef)))
|
|
13
|
-
|
|
14
|
-
(define get-value
|
|
15
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
16
|
-
(get-value-test LookUp)))
|
|
17
|
-
|
|
18
|
-
(define get-value-test
|
|
19
|
-
[ ] -> (error "no such attribute!~%")
|
|
20
|
-
[_ | fail] -> (error "no such value!~%")
|
|
21
|
-
[_ | Value] -> Value)
|
|
22
|
-
|
|
23
|
-
(define has-value?
|
|
24
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
25
|
-
(has-value-test LookUp)))
|
|
26
|
-
|
|
27
|
-
(define has-value-test
|
|
28
|
-
[ ] -> (error "no such attribute!~%")
|
|
29
|
-
[_ | fail] -> false
|
|
30
|
-
_ -> true)
|
|
31
|
-
|
|
32
|
-
(define has-attribute?
|
|
33
|
-
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
34
|
-
(not (empty? LookUp))))
|
|
35
|
-
|
|
36
|
-
(define change-value
|
|
37
|
-
_ class _ -> (error "cannot change the class of an instance!~%")
|
|
38
|
-
[ ] _ _ -> (error "no such attribute!~%")
|
|
39
|
-
[[Attribute | _] | Instance] Attribute Value
|
|
40
|
-
-> [[Attribute | Value] | Instance]
|
|
41
|
-
[Slot | Instance] Attribute Value
|
|
42
|
-
-> [Slot | (change-value Instance Attribute Value)])
|
|
43
|
-
|
|
44
|
-
(define instance-of
|
|
45
|
-
[[class | Class] | _] -> Class
|
|
46
|
-
_ -> (error "not a class instance!"))
|
|
1
|
+
(define defclass
|
|
2
|
+
Class Attributes
|
|
3
|
+
-> (let Assoc (map (/. Attribute [Attribute | fail]) Attributes)
|
|
4
|
+
ClassDef [[class | Class] | Assoc]
|
|
5
|
+
Store (put Class classdef ClassDef)
|
|
6
|
+
Class))
|
|
7
|
+
|
|
8
|
+
(define make-instance
|
|
9
|
+
Class -> (let ClassDef (trap-error (get Class classdef) (/. E []))
|
|
10
|
+
(if (empty? ClassDef)
|
|
11
|
+
(error "class ~A does not exist~%" Class)
|
|
12
|
+
ClassDef)))
|
|
13
|
+
|
|
14
|
+
(define get-value
|
|
15
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
16
|
+
(get-value-test LookUp)))
|
|
17
|
+
|
|
18
|
+
(define get-value-test
|
|
19
|
+
[ ] -> (error "no such attribute!~%")
|
|
20
|
+
[_ | fail] -> (error "no such value!~%")
|
|
21
|
+
[_ | Value] -> Value)
|
|
22
|
+
|
|
23
|
+
(define has-value?
|
|
24
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
25
|
+
(has-value-test LookUp)))
|
|
26
|
+
|
|
27
|
+
(define has-value-test
|
|
28
|
+
[ ] -> (error "no such attribute!~%")
|
|
29
|
+
[_ | fail] -> false
|
|
30
|
+
_ -> true)
|
|
31
|
+
|
|
32
|
+
(define has-attribute?
|
|
33
|
+
Attribute Instance -> (let LookUp (assoc Attribute Instance)
|
|
34
|
+
(not (empty? LookUp))))
|
|
35
|
+
|
|
36
|
+
(define change-value
|
|
37
|
+
_ class _ -> (error "cannot change the class of an instance!~%")
|
|
38
|
+
[ ] _ _ -> (error "no such attribute!~%")
|
|
39
|
+
[[Attribute | _] | Instance] Attribute Value
|
|
40
|
+
-> [[Attribute | Value] | Instance]
|
|
41
|
+
[Slot | Instance] Attribute Value
|
|
42
|
+
-> [Slot | (change-value Instance Attribute Value)])
|
|
43
|
+
|
|
44
|
+
(define instance-of
|
|
45
|
+
[[class | Class] | _] -> Class
|
|
46
|
+
_ -> (error "not a class instance!"))
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
(define depth'
|
|
2
|
-
{A --> (A --> (list A)) --> (A --> boolean) --> (A --> boolean) --> (list A)}
|
|
3
|
-
State Successors Goal? Fail? -> (depth-help' [State] Successors Goal? Fail? []))
|
|
4
|
-
|
|
5
|
-
(define depth-help'
|
|
6
|
-
{(list A) --> (A --> (list A)) --> (A --> boolean) --> (A --> boolean) --> (list A) --> (list A)}
|
|
7
|
-
[State | _] _ Goal? _ Path -> (reverse [State | Path]) where (Goal? State)
|
|
8
|
-
[State | _] _ _ Fail? _ -> [] where (Fail? State)
|
|
9
|
-
[State | _] Successors Goal? Fail? Path <- (fail-if empty?
|
|
10
|
-
(depth-help' (Successors State)
|
|
11
|
-
Successors Goal? Fail? [State | Path]))
|
|
12
|
-
[_ | States] Successors Goal? Fail? Path -> (depth-help' States Successors Goal? Fail? Path)
|
|
13
|
-
_ _ _ _ _ -> [])
|
|
14
|
-
|
|
1
|
+
(define depth'
|
|
2
|
+
{A --> (A --> (list A)) --> (A --> boolean) --> (A --> boolean) --> (list A)}
|
|
3
|
+
State Successors Goal? Fail? -> (depth-help' [State] Successors Goal? Fail? []))
|
|
4
|
+
|
|
5
|
+
(define depth-help'
|
|
6
|
+
{(list A) --> (A --> (list A)) --> (A --> boolean) --> (A --> boolean) --> (list A) --> (list A)}
|
|
7
|
+
[State | _] _ Goal? _ Path -> (reverse [State | Path]) where (Goal? State)
|
|
8
|
+
[State | _] _ _ Fail? _ -> [] where (Fail? State)
|
|
9
|
+
[State | _] Successors Goal? Fail? Path <- (fail-if empty?
|
|
10
|
+
(depth-help' (Successors State)
|
|
11
|
+
Successors Goal? Fail? [State | Path]))
|
|
12
|
+
[_ | States] Successors Goal? Fail? Path -> (depth-help' States Successors Goal? Fail? Path)
|
|
13
|
+
_ _ _ _ _ -> [])
|
|
14
|
+
|