egison 0.4.0 → 0.5.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/README.md +6 -2
- data/lib/egison/core.rb +9 -16
- data/lib/egison/lazyarray.rb +1 -1
- data/lib/egison/matcher-core.rb +42 -38
- data/lib/egison/matcher.rb +98 -96
- data/lib/egison/version.rb +1 -1
- data/spec/sample/join_stream_spec.rb +35 -0
- data/spec/sample/stream_spec.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94a489dfeb3722cf74e46e867076fec46fb389b7
|
4
|
+
data.tar.gz: 9b115c122986dd02864a4b25a7754273f4eadd9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 896c6d1ad74e28517083ae6cfea6465895f1af804c5fbf51da7c291b51f16effdc120e0a50e5325b61273490e71ebd71b1e46924e3eb34ff2906c0eca2cd12f6
|
7
|
+
data.tar.gz: bb189940c54dcb19358b5d30b2e94b48d3e262fb2ec22f0c6e7e28299a0ed2853f50e935090f0f45d70266b82e351bfab15e7cdde854e87c4422b752c3aaf7ef
|
data/README.md
CHANGED
@@ -258,7 +258,11 @@ You can find more demonstrations in the [`sample`](https://github.com/egison/egi
|
|
258
258
|
## About Egison
|
259
259
|
|
260
260
|
If you get to love the above pattern-matching, please try [the Egison programming language](http://www.egison.org), too.
|
261
|
-
|
261
|
+
<<<<<<< HEAD
|
262
|
+
Egison is the pattern-matching oriented, purely functional programming language.
|
263
|
+
=======
|
264
|
+
Egison is the pattern-matching oriented purely functional programming language.
|
265
|
+
>>>>>>> 39ede8d0f3300244c240fce2d8069dda3a2f065e
|
262
266
|
Actually, the original pattern-matching system of Egison is more powerful.
|
263
267
|
For example, we can do following things in the original Egison.
|
264
268
|
|
@@ -269,7 +273,7 @@ There is a new programming world!
|
|
269
273
|
|
270
274
|
## Contact
|
271
275
|
|
272
|
-
If you get interested in this Gem, please
|
276
|
+
If you get interested in this Gem, please contact [Satoshi Egi](http://www.egison.org/~egi/) or tweet to [@Egison_Lang](https://twitter.com/Egison_Lang).
|
273
277
|
|
274
278
|
## LICENSE
|
275
279
|
|
data/lib/egison/core.rb
CHANGED
@@ -50,33 +50,26 @@ module PatternMatch
|
|
50
50
|
|
51
51
|
class MatchingStateStream
|
52
52
|
def initialize(pat, tgt)
|
53
|
-
@
|
53
|
+
@state = MatchingState.new(pat, tgt)
|
54
54
|
@processes = []
|
55
55
|
end
|
56
56
|
|
57
57
|
def match(&block)
|
58
|
-
|
59
|
-
@processes
|
60
|
-
|
61
|
-
unless @processes.empty?
|
62
|
-
process(@processes.shift, &block)
|
63
|
-
end
|
64
|
-
unless @states.empty?
|
65
|
-
state = @states.shift
|
66
|
-
process(Egison::LazyArray.new(state.process_stream), &block)
|
67
|
-
end
|
58
|
+
@processes << Egison::LazyArray.new(@state.process_stream)
|
59
|
+
until @processes.empty?
|
60
|
+
process(@processes.shift, &block)
|
68
61
|
end
|
69
62
|
end
|
70
63
|
|
71
64
|
def process(process_iter, &block)
|
72
65
|
unless process_iter.empty?
|
73
|
-
@processes << process_iter
|
74
66
|
ret = process_iter.shift
|
75
67
|
if ret.atoms.empty?
|
76
68
|
block.(ret.bindings)
|
77
69
|
else
|
78
|
-
@
|
70
|
+
@processes << Egison::LazyArray.new(ret.process_stream)
|
79
71
|
end
|
72
|
+
@processes << process_iter
|
80
73
|
end
|
81
74
|
end
|
82
75
|
end
|
@@ -332,7 +325,7 @@ module PatternMatch
|
|
332
325
|
uscore = Wildcard.new()
|
333
326
|
class << uscore
|
334
327
|
def [](*args)
|
335
|
-
List.call(*args)
|
328
|
+
Egison::List.call(*args)
|
336
329
|
end
|
337
330
|
end
|
338
331
|
uscore
|
@@ -417,11 +410,11 @@ module PatternMatch
|
|
417
410
|
ctx = @ctx
|
418
411
|
tgt = @tgt
|
419
412
|
mstack = MatchingStateStream.new(pat,tgt)
|
420
|
-
::Enumerator.new
|
413
|
+
::Egison::LazyArray.new(::Enumerator.new{|y|
|
421
414
|
mstack.match do |bindings|
|
422
415
|
y << with_bindings(ctx, bindings, &block)
|
423
416
|
end
|
424
|
-
|
417
|
+
})
|
425
418
|
rescue PatternNotMatch
|
426
419
|
end
|
427
420
|
end
|
data/lib/egison/lazyarray.rb
CHANGED
@@ -150,7 +150,7 @@ module Egison
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def inspect
|
153
|
-
"\#<#{self.class.name}#{@terminated ? @cache.inspect : "[#{@cache.join(', ')}...]"}>"
|
153
|
+
"\#<#{self.class.name}#{@terminated ? @cache.inspect : "[#{@cache.map(&:inspect).join(', ')}...]"}>"
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
data/lib/egison/matcher-core.rb
CHANGED
@@ -24,54 +24,58 @@ class Class
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
class
|
31
|
-
def uncons(val)
|
32
|
-
accept_array_only(val)
|
33
|
-
val2 = val.clone
|
34
|
-
x = val2.shift
|
35
|
-
[[x, val2]]
|
27
|
+
module Egison
|
28
|
+
extend self
|
29
|
+
|
30
|
+
class List
|
36
31
|
end
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
class << List
|
34
|
+
def uncons(val)
|
35
|
+
accept_array_only(val)
|
36
|
+
val2 = val.clone
|
37
|
+
x = val2.shift
|
38
|
+
[[x, val2]]
|
41
39
|
end
|
42
|
-
val2 = val.clone
|
43
|
-
x = val2.shift
|
44
|
-
block.([x, val2])
|
45
|
-
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
rets = [[xs, ys]]
|
53
|
-
until val2.empty? do
|
41
|
+
def uncons_stream(val, &block)
|
42
|
+
if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
|
43
|
+
val = test_conv_lazy_array(val)
|
44
|
+
end
|
45
|
+
val2 = val.clone
|
54
46
|
x = val2.shift
|
55
|
-
|
56
|
-
xs += [x]
|
57
|
-
rets += [[xs, ys]]
|
47
|
+
block.([x, val2])
|
58
48
|
end
|
59
|
-
rets
|
60
|
-
end
|
61
49
|
|
62
|
-
|
63
|
-
|
64
|
-
|
50
|
+
def unjoin(val)
|
51
|
+
accept_array_only(val)
|
52
|
+
val2 = val.clone
|
53
|
+
xs = []
|
54
|
+
ys = val2.clone
|
55
|
+
rets = [[xs, ys]]
|
56
|
+
until val2.empty? do
|
57
|
+
x = val2.shift
|
58
|
+
ys = val2.clone
|
59
|
+
xs += [x]
|
60
|
+
rets += [[xs, ys]]
|
61
|
+
end
|
62
|
+
rets
|
65
63
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
|
65
|
+
def unjoin_stream(val, &block)
|
66
|
+
if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
|
67
|
+
val = test_conv_lazy_array(val)
|
68
|
+
end
|
69
|
+
val2 = val.clone
|
70
|
+
xs = []
|
72
71
|
ys = val2.clone
|
73
|
-
xs += [x]
|
74
72
|
block.([xs, ys])
|
73
|
+
until val2.empty?
|
74
|
+
x = val2.shift
|
75
|
+
ys = val2.clone
|
76
|
+
xs += [x]
|
77
|
+
block.([xs, ys])
|
78
|
+
end
|
75
79
|
end
|
76
80
|
end
|
77
81
|
end
|
data/lib/egison/matcher.rb
CHANGED
@@ -3,123 +3,125 @@ require 'egison/lazyarray'
|
|
3
3
|
require 'egison/matcher-core'
|
4
4
|
require 'set'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Egison
|
7
|
+
extend self
|
8
|
+
|
9
|
+
class Multiset
|
10
|
+
end
|
8
11
|
|
9
|
-
class << Multiset
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
class << Multiset
|
13
|
+
def uncons(val)
|
14
|
+
accept_array_only(val)
|
15
|
+
match_all(val) do
|
16
|
+
with(List.(*_hs, _x, *_ts)) do
|
17
|
+
[x, hs + ts]
|
18
|
+
end
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
stream = match_stream(val) {
|
24
|
-
with(List.(*_hs, _x, *_ts)) do
|
25
|
-
[x, hs + ts]
|
22
|
+
def uncons_stream(val, &block)
|
23
|
+
if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
|
24
|
+
val = test_conv_lazy_array(val)
|
26
25
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
stream = match_stream(val) {
|
27
|
+
with(List.(*_hs, _x, *_ts)) do
|
28
|
+
[x, hs + ts]
|
29
|
+
end
|
30
|
+
}
|
31
|
+
stream.each(&block)
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
ys = val2.clone
|
36
|
-
rets = [[xs, ys]]
|
37
|
-
if val2.empty?
|
38
|
-
rets
|
39
|
-
else
|
40
|
-
x = val2.shift
|
34
|
+
def unjoin(val)
|
35
|
+
accept_array_only(val)
|
36
|
+
val2 = val.clone
|
37
|
+
xs = []
|
41
38
|
ys = val2.clone
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
rets = [[xs, ys]]
|
40
|
+
if val2.empty?
|
41
|
+
rets
|
42
|
+
else
|
43
|
+
x = val2.shift
|
44
|
+
ys = val2.clone
|
45
|
+
rets2 = unjoin(ys)
|
46
|
+
rets = (rets2.map { |xs2, ys2| [xs2, [x] + ys2] }) + (rets2.map { |xs2, ys2| [[x] + xs2, ys2] })
|
47
|
+
rets
|
48
|
+
end
|
45
49
|
end
|
46
|
-
end
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
ys = val2.clone
|
55
|
-
if val2.empty?
|
56
|
-
block.([xs, ys])
|
57
|
-
else
|
58
|
-
x = val2.shift
|
51
|
+
def unjoin_stream(val, &block)
|
52
|
+
if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
|
53
|
+
val = test_conv_lazy_array(val)
|
54
|
+
end
|
55
|
+
val2 = val.clone
|
56
|
+
xs = []
|
59
57
|
ys = val2.clone
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
block.([xs, ys])
|
59
|
+
unless val2.empty?
|
60
|
+
x = val2.shift
|
61
|
+
ys = val2.clone
|
62
|
+
unjoin_stream(ys) do |xs2, ys2|
|
63
|
+
block.([xs2, [x] + ys2]) unless xs2.empty?
|
64
|
+
block.([[x] + xs2, ys2])
|
65
|
+
end
|
66
|
+
end
|
65
67
|
end
|
66
68
|
end
|
67
|
-
end
|
68
69
|
|
69
|
-
class << Set
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
class << Set
|
71
|
+
def uncons(val)
|
72
|
+
accept_array_only(val)
|
73
|
+
match_all(val) do
|
74
|
+
with(List.(*_, _x, *_)) do
|
75
|
+
[x, val]
|
76
|
+
end
|
75
77
|
end
|
76
78
|
end
|
77
|
-
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
stream = match_stream(val) {
|
84
|
-
with(List.(*_, _x, *_)) do
|
85
|
-
[x, val]
|
80
|
+
def uncons_stream(val, &block)
|
81
|
+
if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
|
82
|
+
val = test_conv_lazy_array(val)
|
86
83
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
val2 = val.clone
|
94
|
-
xs = []
|
95
|
-
ys = val2.clone
|
96
|
-
rets = [[xs, ys]]
|
97
|
-
if val2.empty?
|
98
|
-
rets
|
99
|
-
else
|
100
|
-
x = val2.shift
|
101
|
-
ys2 = val2.clone
|
102
|
-
rets2 = unjoin(ys2)
|
103
|
-
rets = (rets2.map { |xs2, _| [xs2, ys] }) + (rets2.map { |xs2, ys2| [[x] + xs2, ys] })
|
104
|
-
rets
|
84
|
+
stream = match_stream(val) {
|
85
|
+
with(List.(*_, _x, *_)) do
|
86
|
+
[x, val]
|
87
|
+
end
|
88
|
+
}
|
89
|
+
stream.each(&block)
|
105
90
|
end
|
106
|
-
end
|
107
91
|
|
108
|
-
|
109
|
-
|
110
|
-
|
92
|
+
def unjoin(val)
|
93
|
+
accept_array_only(val)
|
94
|
+
val2 = val.clone
|
95
|
+
xs = []
|
96
|
+
ys = val2.clone
|
97
|
+
rets = [[xs, ys]]
|
98
|
+
if val2.empty?
|
99
|
+
rets
|
100
|
+
else
|
101
|
+
x = val2.shift
|
102
|
+
ys2 = val2.clone
|
103
|
+
rets2 = unjoin(ys2)
|
104
|
+
rets = (rets2.map { |xs2, _| [xs2, ys] }) + (rets2.map { |xs2, ys2| [[x] + xs2, ys] })
|
105
|
+
rets
|
106
|
+
end
|
111
107
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
108
|
+
|
109
|
+
def unjoin_stream(val, &block)
|
110
|
+
if !(val.kind_of?(Array) || val.kind_of?(Egison::LazyArray))
|
111
|
+
val = test_conv_lazy_array(val)
|
112
|
+
end
|
113
|
+
val2 = val.clone
|
114
|
+
xs = []
|
115
|
+
ys = val2.clone
|
116
116
|
block.([xs, ys])
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
117
|
+
unless val2.empty?
|
118
|
+
x = val2.shift
|
119
|
+
ys2 = val2.clone
|
120
|
+
unjoin_stream(ys2) do |xs2, _|
|
121
|
+
block.([xs2, ys]) unless xs2.empty?
|
122
|
+
block.([[x] + xs2, ys])
|
123
|
+
end
|
124
|
+
end
|
123
125
|
end
|
124
126
|
end
|
125
127
|
end
|
data/lib/egison/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'egison'
|
3
|
+
|
4
|
+
include Egison
|
5
|
+
|
6
|
+
def nats
|
7
|
+
(1..Float::INFINITY)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "sample" do
|
11
|
+
describe "join_stream.rb" do
|
12
|
+
# (take 30 (match-all nats (list integer) [<join $hs <join $ts _>> [hs ts]]))
|
13
|
+
# => {[{} {}] [{} {1}] [{1} {}] [{} {1 2}] [{1} {2}] [{1 2} {}] [{} {1 2 3}] [{1} {2 3}] [{1 2} {3}] [{1 2 3} {}] [{} {1 2 3 4}] [{1} {2 3 4}] [{1 2} {3 4}] [{1 2 3} {4}] [{1 2 3 4} {}] [{} {1 2 3 4 5}] [{1} {2 3 4 5}] [{1 2} {3 4 5}] [{1 2 3} {4 5}] [{1 2 3 4} {5}] [{1 2 3 4 5} {}] [{} {1 2 3 4 5 6}] [{1} {2 3 4 5 6}] [{1 2} {3 4 5 6}] [{1 2 3} {4 5 6}] [{1 2 3 4} {5 6}] [{1 2 3 4 5} {6}] [{1 2 3 4 5 6} {}] [{} {1 2 3 4 5 6 7}] [{1} {2 3 4 5 6 7}]}
|
14
|
+
# v- same result as above
|
15
|
+
it %q{match_stream(nats) { with(List.(*_hs, *_ts, *_)) { [hs, ts] } }.take(30)} do
|
16
|
+
expect(match_stream(nats) { with(List.(*_hs, *_ts, *_)) { [hs, ts] } }.take(30)).to eq \
|
17
|
+
[[[], []], [[], [1]], [[1], []], [[], [1, 2]], [[1], [2]], [[1, 2], []], [[], [1, 2, 3]], [[1], [2, 3]], [[1, 2], [3]], [[1, 2, 3], []], [[], [1, 2, 3, 4]], [[1], [2, 3, 4]], [[1, 2], [3, 4]], [[1, 2, 3], [4]], [[1, 2, 3, 4], []], [[], [1, 2, 3, 4, 5]], [[1], [2, 3, 4, 5]], [[1, 2], [3, 4, 5]], [[1, 2, 3], [4, 5]], [[1, 2, 3, 4], [5]], [[1, 2, 3, 4, 5], []], [[], [1, 2, 3, 4, 5, 6]], [[1], [2, 3, 4, 5, 6]], [[1, 2], [3, 4, 5, 6]], [[1, 2, 3], [4, 5, 6]], [[1, 2, 3, 4], [5, 6]], [[1, 2, 3, 4, 5], [6]], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6, 7]], [[1], [2, 3, 4, 5, 6, 7]]]
|
18
|
+
end
|
19
|
+
# (take 30 (match-all nats (multiset integer) [<join $hs <join $ts _>> [hs ts]]))
|
20
|
+
# => {[{} {}] [{} {1}] [{1} {}] [{} {2}] [{1} {2}] [{2} {}] [{} {3}] [{1} {3}] [{2} {1}] [{3} {}] [{} {4}] [{1} {4}] [{2} {3}] [{3} {1}] [{4} {}] [{} {5}] [{1} {5}] [{2} {4}] [{3} {2}] [{4} {1}] [{5} {}] [{} {6}] [{1} {6}] [{2} {5}] [{3} {4}] [{4} {2}] [{5} {1}] [{6} {}] [{} {7}] [{1} {7}]}
|
21
|
+
# v- diffrent result as above, but natural
|
22
|
+
it %q{match_stream(nats) { with(Multiset.(*_hs, *_ts, *_)) { [hs, ts] } }.take(30)} do
|
23
|
+
expect(match_stream(nats) { with(Multiset.(*_hs, *_ts, *_)) { [hs, ts] } }.take(30)).to eq \
|
24
|
+
[[[], []], [[], [1]], [[1], []], [[], [2]], [[1], [2]], [[2], []], [[], [1, 2]], [[1], [3]], [[2], [1]], [[1, 2], []], [[], [3]], [[1], [2, 3]], [[2], [3]], [[1, 2], [3]], [[3], []], [[], [1, 3]], [[1], [4]], [[2], [1, 3]], [[1, 2], [4]], [[3], [1]], [[1, 3], []], [[], [2, 3]], [[1], [2, 4]], [[2], [4]], [[1, 2], [3, 4]], [[3], [2]], [[1, 3], [2]], [[2, 3], []], [[], [1, 2, 3]], [[1], [3, 4]]]
|
25
|
+
end
|
26
|
+
# (take 30 (match-all nats (set integer) [<join $hs <join $ts _>> [hs ts]]))
|
27
|
+
# => {[{} {}] [{} {1}] [{1} {}] [{} {2}] [{1} {1}] [{2} {}] [{} {3}] [{1} {2}] [{2} {1}] [{3} {}] [{} {1 2}] [{1} {3}] [{2} {2}] [{3} {1}] [{1 2} {}] [{} {4}] [{1} {1 2}] [{2} {3}] [{3} {2}] [{1 2} {1}] [{4} {}] [{} {1 3}] [{1} {4}] [{2} {1 2}] [{3} {3}] [{1 2} {2}] [{4} {1}] [{1 3} {}] [{} {2 1}] [{1} {1 3}]}
|
28
|
+
# v- diffrent result as above, but natural
|
29
|
+
it %q{match_stream(nats) { with(Set.(*_hs, *_ts, *_)) { [hs, ts] } }.take(30)} do
|
30
|
+
expect(match_stream(nats) { with(Set.(*_hs, *_ts, *_)) { [hs, ts] } }.take(30)).to eq \
|
31
|
+
[[[], []], [[], [1]], [[1], []], [[], [2]], [[1], [1]], [[2], []], [[], [1, 2]], [[1], [2]], [[2], [1]], [[1, 2], []], [[], [3]], [[1], [1, 2]], [[2], [2]], [[1, 2], [1]], [[3], []], [[], [1, 3]], [[1], [3]], [[2], [1, 2]], [[1, 2], [2]], [[3], [1]], [[1, 3], []], [[], [2, 3]], [[1], [1, 3]], [[2], [3]], [[1, 2], [1, 2]], [[3], [2]], [[1, 3], [1]], [[2, 3], []], [[], [1, 2, 3]], [[1], [2, 3]]]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/spec/sample/stream_spec.rb
CHANGED
@@ -34,10 +34,32 @@ describe "sample" do
|
|
34
34
|
[[1, 2], [1, 3], [2, 1], [1, 4], [2, 3], [3, 1], [1, 5], [2, 4], [3, 2], [4, 1]]
|
35
35
|
end
|
36
36
|
|
37
|
+
# (take 20 (match-all nats (multiset integer) [<cons $m <cons $n _>> [m n]]))
|
38
|
+
it %q{match_stream(nats){ with(Multiset.(_m, _n, *_)) { [m, n] } }.take(20)} do
|
39
|
+
expect(match_stream(nats){ with(Multiset.(_m, _n, *_)) { [m, n] } }.take(20)).to eq \
|
40
|
+
[[1, 2], [1, 3], [2, 1], [1, 4], [2, 3], [3, 1], [1, 5], [2, 4], [3, 2], [4, 1],
|
41
|
+
[1, 6], [2, 5], [3, 4], [4, 2], [5, 1], [1, 7], [2, 6], [3, 5], [4, 3], [5, 2]]
|
42
|
+
end
|
43
|
+
|
37
44
|
# (take 10 (match-all nats (set integer) [<cons $m <cons $n _>> [m n]]))
|
38
45
|
it %q{match_stream(nats){ with(Set.(_m, _n, *_)) { [m, n] } }.take(10)} do
|
39
46
|
expect(match_stream(nats){ with(Set.(_m, _n, *_)) { [m, n] } }.take(10)).to eq \
|
40
47
|
[[1, 1], [1, 2], [2, 1], [1, 3], [2, 2], [3, 1], [1, 4], [2, 3], [3, 2], [4, 1]]
|
41
48
|
end
|
49
|
+
|
50
|
+
# (take 20 (match-all nats (set integer) [<cons $m <cons $n _>> [m n]]))
|
51
|
+
it %q{match_stream(nats){ with(Set.(_m, _n, *_)) { [m, n] } }.take(20)} do
|
52
|
+
expect(match_stream(nats){ with(Set.(_m, _n, *_)) { [m, n] } }.take(20)).to eq \
|
53
|
+
[[1, 1], [1, 2], [2, 1], [1, 3], [2, 2], [3, 1], [1, 4], [2, 3], [3, 2], [4, 1],
|
54
|
+
[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [1, 6], [2, 5], [3, 4], [4, 3], [5, 2]]
|
55
|
+
end
|
56
|
+
|
57
|
+
# assign to a variable, execute twice (or more), then obtain the same results. (for twin-primes)
|
58
|
+
it %q{assign to a variable, execute twice (or more), then obtain the same results. (for twin-primes)} do
|
59
|
+
tp = twin_primes
|
60
|
+
tp.take(10) # discard
|
61
|
+
expect(tp.take(10)).to eq \
|
62
|
+
[[3, 5], [5, 7], [11, 13], [17, 19], [29, 31], [41, 43], [59, 61], [71, 73], [101, 103], [107, 109]]
|
63
|
+
end
|
42
64
|
end
|
43
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: egison
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Satoshi Egi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- spec/lib/egison_spec.rb
|
84
84
|
- spec/sample/combination_spec.rb
|
85
85
|
- spec/sample/join_spec.rb
|
86
|
+
- spec/sample/join_stream_spec.rb
|
86
87
|
- spec/sample/poker_hands_spec.rb
|
87
88
|
- spec/sample/set_spec.rb
|
88
89
|
- spec/sample/stream_spec.rb
|