shen-ruby 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +5 -0
  3. data/README.md +8 -12
  4. data/Rakefile +4 -9
  5. data/bin/shen_test_suite.rb +0 -1
  6. data/bin/srrepl +2 -4
  7. data/lib/shen_ruby/shen.rb +98 -0
  8. data/lib/shen_ruby/version.rb +1 -1
  9. data/shen-ruby.gemspec +3 -3
  10. data/shen/README.txt +9 -13
  11. data/shen/release/BSD +24 -0
  12. data/shen/release/klambda/core.kl +157 -0
  13. data/shen/release/klambda/declarations.kl +109 -0
  14. data/shen/release/klambda/load.kl +59 -0
  15. data/shen/release/klambda/macros.kl +91 -0
  16. data/shen/release/klambda/prolog.kl +228 -0
  17. data/shen/release/klambda/reader.kl +198 -0
  18. data/shen/release/klambda/sequent.kl +142 -0
  19. data/shen/release/klambda/sys.kl +253 -0
  20. data/shen/release/klambda/t-star.kl +123 -0
  21. data/shen/release/klambda/toplevel.kl +110 -0
  22. data/shen/release/klambda/track.kl +79 -0
  23. data/shen/release/{k_lambda → klambda}/types.kl +41 -63
  24. data/shen/release/klambda/writer.kl +81 -0
  25. data/shen/release/klambda/yacc.kl +87 -0
  26. data/shen/release/license.pdf +0 -0
  27. data/shen/release/test_programs/Chap13/problems.txt +26 -26
  28. data/shen/release/test_programs/README.shen +52 -52
  29. data/shen/release/test_programs/TinyLispFunctions.txt +15 -15
  30. data/shen/release/test_programs/TinyTypes.shen +55 -55
  31. data/shen/release/test_programs/binary.shen +24 -24
  32. data/shen/release/test_programs/bubble_version_1.shen +28 -28
  33. data/shen/release/test_programs/bubble_version_2.shen +22 -22
  34. data/shen/release/test_programs/calculator.shen +21 -21
  35. data/shen/release/test_programs/cartprod.shen +23 -23
  36. data/shen/release/test_programs/change.shen +25 -25
  37. data/shen/release/test_programs/classes-defaults.shen +94 -94
  38. data/shen/release/test_programs/classes-inheritance.shen +100 -100
  39. data/shen/release/test_programs/classes-typed.shen +74 -74
  40. data/shen/release/test_programs/classes-untyped.shen +46 -46
  41. data/shen/release/test_programs/depth_.shen +14 -14
  42. data/shen/release/test_programs/einstein.shen +34 -34
  43. data/shen/release/test_programs/fruit_machine.shen +46 -46
  44. data/shen/release/test_programs/interpreter.shen +217 -217
  45. data/shen/release/test_programs/metaprog.shen +85 -85
  46. data/shen/release/test_programs/minim.shen +192 -192
  47. data/shen/release/test_programs/mutual.shen +11 -11
  48. data/shen/release/test_programs/n_queens.shen +45 -45
  49. data/shen/release/test_programs/newton_version_1.shen +33 -33
  50. data/shen/release/test_programs/newton_version_2.shen +24 -24
  51. data/shen/release/test_programs/parse.prl +14 -14
  52. data/shen/release/test_programs/parser.shen +51 -51
  53. data/shen/release/test_programs/powerset.shen +10 -10
  54. data/shen/release/test_programs/prime.shen +10 -10
  55. data/shen/release/test_programs/prolog.shen +78 -78
  56. data/shen/release/test_programs/proof_assistant.shen +80 -80
  57. data/shen/release/test_programs/proplog_version_1.shen +25 -25
  58. data/shen/release/test_programs/proplog_version_2.shen +27 -27
  59. data/shen/release/test_programs/qmachine.shen +66 -66
  60. data/shen/release/test_programs/red-black.shen +54 -54
  61. data/shen/release/test_programs/search.shen +55 -55
  62. data/shen/release/test_programs/semantic_net.shen +44 -44
  63. data/shen/release/test_programs/spreadsheet.shen +34 -34
  64. data/shen/release/test_programs/stack.shen +27 -27
  65. data/shen/release/test_programs/streams.shen +20 -20
  66. data/shen/release/test_programs/strings.shen +57 -57
  67. data/shen/release/test_programs/structures-typed.shen +71 -71
  68. data/shen/release/test_programs/structures-untyped.shen +41 -41
  69. data/shen/release/test_programs/tests.shen +232 -232
  70. data/shen/release/test_programs/types.shen +11 -11
  71. data/shen/release/test_programs/whist.shen +239 -239
  72. data/shen/release/test_programs/yacc.shen +132 -132
  73. metadata +21 -35
  74. data/shen/lib/shen_ruby/shen.rb +0 -160
  75. data/shen/license.txt +0 -34
  76. data/shen/release/benchmarks/N_queens.shen +0 -45
  77. data/shen/release/benchmarks/README.shen +0 -14
  78. data/shen/release/benchmarks/benchmarks.shen +0 -52
  79. data/shen/release/benchmarks/bigprog +0 -2173
  80. data/shen/release/benchmarks/einstein.shen +0 -33
  81. data/shen/release/benchmarks/heatwave.gif +0 -0
  82. data/shen/release/benchmarks/interpreter.shen +0 -219
  83. data/shen/release/benchmarks/jnk.shen +0 -194
  84. data/shen/release/benchmarks/picture.jpg +0 -0
  85. data/shen/release/benchmarks/plato.jpg +0 -0
  86. data/shen/release/benchmarks/powerset.shen +0 -10
  87. data/shen/release/benchmarks/prime.shen +0 -10
  88. data/shen/release/benchmarks/short.shen +0 -129
  89. data/shen/release/benchmarks/text.txt +0 -68
  90. data/shen/release/k_lambda/core.kl +0 -181
  91. data/shen/release/k_lambda/declarations.kl +0 -131
  92. data/shen/release/k_lambda/load.kl +0 -84
  93. data/shen/release/k_lambda/macros.kl +0 -112
  94. data/shen/release/k_lambda/prolog.kl +0 -252
  95. data/shen/release/k_lambda/reader.kl +0 -222
  96. data/shen/release/k_lambda/sequent.kl +0 -166
  97. data/shen/release/k_lambda/sys.kl +0 -271
  98. data/shen/release/k_lambda/t-star.kl +0 -139
  99. data/shen/release/k_lambda/toplevel.kl +0 -135
  100. data/shen/release/k_lambda/track.kl +0 -103
  101. data/shen/release/k_lambda/writer.kl +0 -105
  102. data/shen/release/k_lambda/yacc.kl +0 -113
@@ -1,24 +1,24 @@
1
- (datatype binary
2
-
3
- if (element? X [0 1])
4
- _____________
5
- X : zero-or-one;
6
-
7
- X : zero-or-one;
8
- ________________
9
- [X] : binary;
10
-
11
- X : zero-or-one; Y : binary;
12
- ____________________________
13
- [X | Y] : binary;
14
-
15
- X : zero-or-one, [Y | Z] : binary >> P;
16
- ________________________________________
17
- [X Y | Z] : binary >> P;)
18
-
19
- (define complement
20
- {binary --> binary}
21
- [0] -> [1]
22
- [1] -> [0]
23
- [1 N | X] -> [0 | (complement [N | X])]
24
- [0 N | X] -> [1 | (complement [N | X])])
1
+ (datatype binary
2
+
3
+ if (element? X [0 1])
4
+ _____________
5
+ X : zero-or-one;
6
+
7
+ X : zero-or-one;
8
+ ________________
9
+ [X] : binary;
10
+
11
+ X : zero-or-one; Y : binary;
12
+ ____________________________
13
+ [X | Y] : binary;
14
+
15
+ X : zero-or-one, [Y | Z] : binary >> P;
16
+ ________________________________________
17
+ [X Y | Z] : binary >> P;)
18
+
19
+ (define complement
20
+ {binary --> binary}
21
+ [0] -> [1]
22
+ [1] -> [0]
23
+ [1 N | X] -> [0 | (complement [N | X])]
24
+ [0 N | X] -> [1 | (complement [N | X])])
@@ -1,28 +1,28 @@
1
- (define bubble-sort
2
- \* bubble again if you need to *\
3
- X -> (bubble-again-perhaps (bubble X) X))
4
-
5
- (define bubble
6
- [] -> []
7
- [X] -> [X]
8
- [X Y | Z] -> [Y | (bubble [X | Z])] where (> Y X)
9
- [X Y | Z] -> [X | (bubble [Y | Z])])
10
-
11
- (define bubble-again-perhaps
12
- \* no change as a result of bubbling - then the job is done *\
13
- X X -> X
14
- \* else bubble again *\
15
- X _ -> (bubble-sort X))
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
1
+ (define bubble-sort
2
+ \* bubble again if you need to *\
3
+ X -> (bubble-again-perhaps (bubble X) X))
4
+
5
+ (define bubble
6
+ [] -> []
7
+ [X] -> [X]
8
+ [X Y | Z] -> [Y | (bubble [X | Z])] where (> Y X)
9
+ [X Y | Z] -> [X | (bubble [Y | Z])])
10
+
11
+ (define bubble-again-perhaps
12
+ \* no change as a result of bubbling - then the job is done *\
13
+ X X -> X
14
+ \* else bubble again *\
15
+ X _ -> (bubble-sort X))
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
@@ -1,22 +1,22 @@
1
- (define bubble-sort
2
- X -> (fix bubble X))
3
-
4
- (define bubble
5
- [] -> []
6
- [X] -> [X]
7
- [X Y | Z] -> [Y | (bubble [X | Z])] where (> Y X)
8
- [X Y | Z] -> [X | (bubble [Y | Z])])
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
1
+ (define bubble-sort
2
+ X -> (fix bubble X))
3
+
4
+ (define bubble
5
+ [] -> []
6
+ [X] -> [X]
7
+ [X Y | Z] -> [Y | (bubble [X | Z])] where (> Y X)
8
+ [X Y | Z] -> [X | (bubble [Y | Z])])
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
@@ -1,21 +1,21 @@
1
- (datatype arith-expr
2
-
3
- X : number;
4
- ====================
5
- [num X] : arith-expr;
6
-
7
- if (element? Op [+ - * /])
8
- X : arith-expr; Y : arith-expr;
9
- ===============================
10
- [X Op Y] : arith-expr;)
11
-
12
- (define do-calculation
13
- {arith-expr --> number}
14
- [X + Y] -> (+ (do-calculation X) (do-calculation Y))
15
- [X - Y] -> (- (do-calculation X) (do-calculation Y))
16
- [X * Y] -> (* (do-calculation X) (do-calculation Y))
17
- [X / Y] -> (/ (do-calculation X) (do-calculation Y))
18
- [num X] -> X)
19
-
20
-
21
-
1
+ (datatype arith-expr
2
+
3
+ X : number;
4
+ ====================
5
+ [num X] : arith-expr;
6
+
7
+ if (element? Op [+ - * /])
8
+ X : arith-expr; Y : arith-expr;
9
+ ===============================
10
+ [X Op Y] : arith-expr;)
11
+
12
+ (define do-calculation
13
+ {arith-expr --> number}
14
+ [X + Y] -> (+ (do-calculation X) (do-calculation Y))
15
+ [X - Y] -> (- (do-calculation X) (do-calculation Y))
16
+ [X * Y] -> (* (do-calculation X) (do-calculation Y))
17
+ [X / Y] -> (/ (do-calculation X) (do-calculation Y))
18
+ [num X] -> X)
19
+
20
+
21
+
@@ -1,23 +1,23 @@
1
- (define cartesian-product
2
- [ ] _ -> [ ]
3
- [X | Y] Z -> (append (all-pairs-using-X X Z) (cartesian-product Y Z)))
4
-
5
- (define all-pairs-using-X
6
- _ [ ] -> [ ]
7
- X [Y | Z] -> [[X Y] | (all-pairs-using-X X Z)])
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
1
+ (define cartesian-product
2
+ [ ] _ -> [ ]
3
+ [X | Y] Z -> (append (all-pairs-using-X X Z) (cartesian-product Y Z)))
4
+
5
+ (define all-pairs-using-X
6
+ _ [ ] -> [ ]
7
+ X [Y | Z] -> [[X Y] | (all-pairs-using-X X Z)])
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
@@ -1,25 +1,25 @@
1
- (define count-change
2
- Amount -> (count-change* Amount 200))
3
-
4
- (define count-change*
5
- 0 _ -> 1
6
- _ 0 -> 0
7
- Amount _ -> 0 where (> 0 Amount)
8
- Amount Fst_Denom
9
- -> (+ (count-change* (- Amount Fst_Denom) Fst_Denom)
10
- (count-change* Amount (next-denom Fst_Denom))))
11
-
12
- (define next-denom
13
- 200 -> 100
14
- 100 -> 50
15
- 50 -> 20
16
- 20 -> 10
17
- 10 -> 5
18
- 5 -> 2
19
- 2 -> 1
20
- 1 -> 0)
21
-
22
-
23
-
24
-
25
-
1
+ (define count-change
2
+ Amount -> (count-change* Amount 200))
3
+
4
+ (define count-change*
5
+ 0 _ -> 1
6
+ _ 0 -> 0
7
+ Amount _ -> 0 where (> 0 Amount)
8
+ Amount Fst_Denom
9
+ -> (+ (count-change* (- Amount Fst_Denom) Fst_Denom)
10
+ (count-change* Amount (next-denom Fst_Denom))))
11
+
12
+ (define next-denom
13
+ 200 -> 100
14
+ 100 -> 50
15
+ 50 -> 20
16
+ 20 -> 10
17
+ 10 -> 5
18
+ 5 -> 2
19
+ 2 -> 1
20
+ 1 -> 0)
21
+
22
+
23
+
24
+
25
+
@@ -1,94 +1,94 @@
1
- (datatype class
2
-
3
- Slots : [slot];
4
- _______________________________________
5
- (defclass Class Slots) : (class Class);
6
-
7
- Attribute : symbol; Type : symbol;
8
- ===================================
9
- (@p Attribute Type) : slot;
10
-
11
- Default : Type; Attribute : symbol; Type : symbol;
12
- ==================================================
13
- (@p Attribute Type Default) : slot;)
14
-
15
- (define defclass
16
- Class ClassDef -> (let Attributes (map fst ClassDef)
17
- Types (record-attribute-types Class ClassDef)
18
- Assoc (map assign-values ClassDef)
19
- NewClassDef [[class | Class] | Assoc]
20
- Store (put-prop Class classdef NewClassDef)
21
- RecordClass (axiom Class Class [class Class])
22
- Class))
23
-
24
- (define assign-values
25
- (@p Attribute _ Value) -> [Attribute | Value]
26
- (@p Attribute _) -> [Attribute | fail!])
27
-
28
- (define axiom
29
- DataType X A -> (eval [datatype DataType
30
- ________
31
- X : A;]))
32
-
33
- (define record-attribute-types
34
- _ [] -> []
35
- Class [(@p Attribute Type _) | ClassDef]
36
- -> (let DataTypeName (concat Class Attribute)
37
- DataType (axiom DataTypeName Attribute [attribute Class Type])
38
- (record-attribute-types Class ClassDef))
39
- Class [(@p Attribute Type) | ClassDef]
40
- -> (let DataTypeName (concat Class Attribute)
41
- DataType (axiom DataTypeName Attribute [attribute Class Type])
42
- (record-attribute-types Class ClassDef)))
43
-
44
- (declare make-instance [[class Class] --> [instance Class]])
45
-
46
- (define make-instance
47
- Class -> (let ClassDef (get-prop Class classdef [])
48
- (if (empty? ClassDef)
49
- (error "class ~A does not exist~%" Class)
50
- ClassDef)))
51
-
52
- (declare get-value [[attribute Class A] --> [instance Class] --> A])
53
-
54
- (define get-value
55
- Attribute Instance -> (let LookUp (assoc Attribute Instance)
56
- (get-value-test LookUp)))
57
-
58
- (define get-value-test
59
- [ ] -> (error "no such attribute!~%")
60
- [_ | fail!] -> (error "no such value!~%")
61
- [_ | Value] -> Value)
62
-
63
- (declare has-value? [[attribute Class A] --> [instance Class] --> boolean])
64
-
65
- (define has-value?
66
- Attribute Instance -> (let LookUp (assoc Attribute Instance)
67
- (has-value-test LookUp)))
68
-
69
- (define has-value-test
70
- [ ] -> (error "no such attribute!~%")
71
- [_ | fail!] -> false
72
- _ -> true)
73
-
74
- (declare has-attribute? [symbol --> [instance Class] --> boolean])
75
-
76
- (define has-attribute?
77
- Attribute Instance -> (let LookUp (assoc Attribute Instance)
78
- (not (empty? LookUp))))
79
-
80
- (declare change-value [[instance Class] --> [attribute Class A] --> A --> [instance Class]])
81
-
82
- (define change-value
83
- _ class _ -> (error "cannot change the class of an instance!~%")
84
- [ ] _ _ -> (error "no such attribute!~%")
85
- [[Attribute | _] | Instance] Attribute Value
86
- -> [[Attribute | Value] | Instance]
87
- [Slot | Instance] Attribute Value
88
- -> [Slot | (change-value Instance Attribute Value)])
89
-
90
- (declare instance-of [[instance Class] --> [class Class]])
91
-
92
- (define instance-of
93
- [[class | Class] | _] -> Class
94
- _ -> (error "not a class instance!"))
1
+ (datatype class
2
+
3
+ Slots : [slot];
4
+ _______________________________________
5
+ (defclass Class Slots) : (class Class);
6
+
7
+ Attribute : symbol; Type : symbol;
8
+ ===================================
9
+ (@p Attribute Type) : slot;
10
+
11
+ Default : Type; Attribute : symbol; Type : symbol;
12
+ ==================================================
13
+ (@p Attribute Type Default) : slot;)
14
+
15
+ (define defclass
16
+ Class ClassDef -> (let Attributes (map fst ClassDef)
17
+ Types (record-attribute-types Class ClassDef)
18
+ Assoc (map assign-values ClassDef)
19
+ NewClassDef [[class | Class] | Assoc]
20
+ Store (put-prop Class classdef NewClassDef)
21
+ RecordClass (axiom Class Class [class Class])
22
+ Class))
23
+
24
+ (define assign-values
25
+ (@p Attribute _ Value) -> [Attribute | Value]
26
+ (@p Attribute _) -> [Attribute | fail!])
27
+
28
+ (define axiom
29
+ DataType X A -> (eval [datatype DataType
30
+ ________
31
+ X : A;]))
32
+
33
+ (define record-attribute-types
34
+ _ [] -> []
35
+ Class [(@p Attribute Type _) | ClassDef]
36
+ -> (let DataTypeName (concat Class Attribute)
37
+ DataType (axiom DataTypeName Attribute [attribute Class Type])
38
+ (record-attribute-types Class ClassDef))
39
+ Class [(@p Attribute Type) | ClassDef]
40
+ -> (let DataTypeName (concat Class Attribute)
41
+ DataType (axiom DataTypeName Attribute [attribute Class Type])
42
+ (record-attribute-types Class ClassDef)))
43
+
44
+ (declare make-instance [[class Class] --> [instance Class]])
45
+
46
+ (define make-instance
47
+ Class -> (let ClassDef (get-prop Class classdef [])
48
+ (if (empty? ClassDef)
49
+ (error "class ~A does not exist~%" Class)
50
+ ClassDef)))
51
+
52
+ (declare get-value [[attribute Class A] --> [instance Class] --> A])
53
+
54
+ (define get-value
55
+ Attribute Instance -> (let LookUp (assoc Attribute Instance)
56
+ (get-value-test LookUp)))
57
+
58
+ (define get-value-test
59
+ [ ] -> (error "no such attribute!~%")
60
+ [_ | fail!] -> (error "no such value!~%")
61
+ [_ | Value] -> Value)
62
+
63
+ (declare has-value? [[attribute Class A] --> [instance Class] --> boolean])
64
+
65
+ (define has-value?
66
+ Attribute Instance -> (let LookUp (assoc Attribute Instance)
67
+ (has-value-test LookUp)))
68
+
69
+ (define has-value-test
70
+ [ ] -> (error "no such attribute!~%")
71
+ [_ | fail!] -> false
72
+ _ -> true)
73
+
74
+ (declare has-attribute? [symbol --> [instance Class] --> boolean])
75
+
76
+ (define has-attribute?
77
+ Attribute Instance -> (let LookUp (assoc Attribute Instance)
78
+ (not (empty? LookUp))))
79
+
80
+ (declare change-value [[instance Class] --> [attribute Class A] --> A --> [instance Class]])
81
+
82
+ (define change-value
83
+ _ class _ -> (error "cannot change the class of an instance!~%")
84
+ [ ] _ _ -> (error "no such attribute!~%")
85
+ [[Attribute | _] | Instance] Attribute Value
86
+ -> [[Attribute | Value] | Instance]
87
+ [Slot | Instance] Attribute Value
88
+ -> [Slot | (change-value Instance Attribute Value)])
89
+
90
+ (declare instance-of [[instance Class] --> [class Class]])
91
+
92
+ (define instance-of
93
+ [[class | Class] | _] -> Class
94
+ _ -> (error "not a class instance!"))