egison 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93830b57e70db21c121811db9cdb6dc290c8f1d4
4
- data.tar.gz: f03a022950af1034baa7f5f05ec8c46bbcdfd27e
3
+ metadata.gz: c0a67c9b1b9350d0d0c09b823f1b988626a5a100
4
+ data.tar.gz: 244276e1bb15b529bf0084c207f0e0735a640294
5
5
  SHA512:
6
- metadata.gz: 6dc21dd3b11e12c3db43dfec0631f922eb9da0e6873dbcc055777801746ba0d97a49d2fba8da89965044eaadda57aa3487930a2880834dc65b8f559b76638522
7
- data.tar.gz: 39c8fc34bfb2533991fa7b896a660523107a1a58fb51015d4b98b92228c90cbdffce909136e3ae9d5ca3e9c30b47d49bd90b8208425f392ac07f121f791968e4
6
+ metadata.gz: 9dbeac11189e83c9f9236c62dbbb4879a1137f368932021088e2472a4b503ad6dad0ead29be8095b53ca5bfab7d2214bfee866edab166d0b523989d91dfc34c0
7
+ data.tar.gz: 226cebb19768ea435db9ce4f420961c69a4160cfa9fb579535a55a631ad9e56d53975e41ea19df1e0ae6508d7928df9cb990c0e9ff21b2bad62a6b95e25061da
data/Makefile CHANGED
@@ -1,4 +1,7 @@
1
1
  all:
2
+ make compile
3
+ make test
4
+ compile:
2
5
  gem build egison.gemspec
3
6
  gem install egison-*.gem
4
7
 
@@ -19,30 +19,30 @@ module PatternMatch
19
19
  class MatchingStateStack
20
20
  attr_accessor :states
21
21
  attr_accessor :results
22
-
22
+
23
23
  def initialize(pat, tgt)
24
24
  @states = [MatchingState.new(pat, tgt)]
25
25
  @results = []
26
26
  end
27
27
 
28
28
  def match
29
- while !@states.empty? do
29
+ until @states.empty? do
30
30
  process
31
31
  end
32
32
  @results
33
33
  end
34
-
34
+
35
35
  def process
36
36
  state = @states.shift
37
37
  rets = state.process
38
38
  new_states = []
39
- rets.each { |ret|
40
- if ret.atoms.empty? then
41
- @results = @results + [ret.bindings]
39
+ rets.each do |ret|
40
+ if ret.atoms.empty?
41
+ @results += [ret.bindings]
42
42
  else
43
- new_states = new_states + [ret]
43
+ new_states += [ret]
44
44
  end
45
- }
45
+ end
46
46
  @states = new_states + @states
47
47
  end
48
48
  end
@@ -58,18 +58,18 @@ module PatternMatch
58
58
  def process
59
59
  atom = @atoms.shift
60
60
  rets = atom.first.match(atom.last, @bindings)
61
- rets.map { |new_atoms, new_bindings|
62
- new_state = self.clone
61
+ rets.map do |new_atoms, new_bindings|
62
+ new_state = clone
63
63
  new_state.atoms = new_atoms + new_state.atoms
64
- new_state.bindings = new_state.bindings + new_bindings
64
+ new_state.bindings += new_bindings
65
65
  new_state
66
- }
66
+ end
67
67
  end
68
68
  end
69
69
 
70
70
  class Pattern
71
71
  attr_accessor :quantified
72
-
72
+
73
73
  def initialize
74
74
  end
75
75
 
@@ -98,8 +98,8 @@ module PatternMatch
98
98
  end
99
99
 
100
100
  def match(tgt, bindings)
101
- if subpatterns.empty? then
102
- if tgt.empty? then
101
+ if subpatterns.empty?
102
+ if tgt.empty?
103
103
  return [[[], []]]
104
104
  else
105
105
  return []
@@ -107,19 +107,23 @@ module PatternMatch
107
107
  else
108
108
  subpatterns = @subpatterns.clone
109
109
  px = subpatterns.shift
110
- if px.quantified then
111
- if subpatterns.empty? then
110
+ if px.quantified
111
+ if subpatterns.empty?
112
112
  [[[[px.pattern, tgt]], []]]
113
113
  else
114
114
  unjoineds = @matcher.unjoin(tgt)
115
- unjoineds.map { |xs, ys| [[[px.pattern, xs], [PatternWithMatcher.new(@matcher, *subpatterns), ys]], []] }
115
+ unjoineds.map do |xs, ys|
116
+ [[[px.pattern, xs], [PatternWithMatcher.new(@matcher, *subpatterns), ys]], []]
117
+ end
116
118
  end
117
119
  else
118
- if tgt.empty? then
120
+ if tgt.empty?
119
121
  []
120
122
  else
121
123
  unconseds = @matcher.uncons(tgt)
122
- unconseds.map { |x, xs| [[[px, x], [PatternWithMatcher.new(@matcher, *subpatterns), xs]], []] }
124
+ unconseds.map do |x, xs|
125
+ [[[px, x], [PatternWithMatcher.new(@matcher, *subpatterns), xs]], []]
126
+ end
123
127
  end
124
128
  end
125
129
  end
@@ -158,7 +162,7 @@ module PatternMatch
158
162
 
159
163
  def match(tgt, bindings)
160
164
  val = with_bindings(@ctx, bindings, {:expr => @expr}) { eval expr }
161
- if val.__send__(:===, tgt) then
165
+ if val.__send__(:===, tgt)
162
166
  [[[], []]]
163
167
  else
164
168
  []
@@ -192,7 +196,7 @@ module PatternMatch
192
196
  end
193
197
 
194
198
  def binding_module(obj)
195
- m = obj.singleton_class.ancestors.find {|i| i.kind_of?(BindingModule) }
199
+ m = obj.singleton_class.ancestors.find { |i| i.kind_of?(BindingModule) }
196
200
  unless m
197
201
  m = BindingModule.new
198
202
  obj.singleton_class.class_eval do
@@ -209,7 +213,7 @@ module PatternMatch
209
213
 
210
214
  class PatternCollection < Pattern
211
215
  attr_accessor :pattern
212
-
216
+
213
217
  def initialize(pat)
214
218
  super()
215
219
  @quantified = true
@@ -272,7 +276,7 @@ module PatternMatch
272
276
  undefined
273
277
  end
274
278
  end
275
-
279
+
276
280
  def ___(*vals)
277
281
  case vals.length
278
282
  when 0
@@ -302,7 +306,7 @@ module PatternMatch
302
306
  end
303
307
 
304
308
  def binding_module(obj)
305
- m = obj.singleton_class.ancestors.find {|i| i.kind_of?(BindingModule) }
309
+ m = obj.singleton_class.ancestors.find { |i| i.kind_of?(BindingModule) }
306
310
  unless m
307
311
  m = BindingModule.new
308
312
  obj.singleton_class.class_eval do
@@ -323,7 +327,7 @@ module PatternMatch
323
327
  tgt = @tgt
324
328
  mstack = MatchingStateStack.new(pat,tgt)
325
329
  mstack.match
326
- if mstack.results.empty? then
330
+ if mstack.results.empty?
327
331
  nil
328
332
  else
329
333
  ret = with_bindings(ctx, mstack.results.first, &block)
@@ -332,7 +336,7 @@ module PatternMatch
332
336
  rescue PatternNotMatch
333
337
  end
334
338
  end
335
-
339
+
336
340
  class PatternNotMatch < Exception; end
337
341
  class PatternMatchError < StandardError; end
338
342
  class NoMatchingPatternError < PatternMatchError; end
@@ -365,8 +369,7 @@ module Kernel
365
369
  env.instance_eval(&block)
366
370
  end
367
371
  end
368
-
369
- alias match_single match
370
372
 
373
+ alias match_single match
371
374
  end
372
375
 
@@ -31,11 +31,11 @@ class << List
31
31
  xs = []
32
32
  ys = val2.clone
33
33
  rets = [[xs, ys]]
34
- while !val2.empty? do
34
+ until val2.empty? do
35
35
  x = val2.shift
36
36
  ys = val2.clone
37
- xs = xs + [x]
38
- rets = rets + [[xs, ys]]
37
+ xs += [x]
38
+ rets += [[xs, ys]]
39
39
  end
40
40
  rets
41
41
  end
@@ -1,5 +1,6 @@
1
1
  require 'egison/core'
2
2
  require 'egison/matcher-core'
3
+ require 'set'
3
4
 
4
5
  class Multiset
5
6
  end
@@ -13,28 +14,25 @@ class << Multiset
13
14
  end
14
15
  end
15
16
  end
16
-
17
+
17
18
  def unjoin(val)
18
19
  accept_array_only(val)
19
20
  val2 = val.clone
20
21
  xs = []
21
22
  ys = val2.clone
22
23
  rets = [[xs, ys]]
23
- if !val2.empty? then
24
+ if val2.empty?
25
+ rets
26
+ else
24
27
  x = val2.shift
25
28
  ys = val2.clone
26
29
  rets2 = unjoin(ys)
27
- rets = (rets2.map {|xs2, ys2| [xs2, [x]+ys2]}) + (rets2.map {|xs2, ys2| [[x]+xs2, ys2]})
28
- rets
29
- else
30
+ rets = (rets2.map { |xs2, ys2| [xs2, [x] + ys2] }) + (rets2.map { |xs2, ys2| [[x] + xs2, ys2] })
30
31
  rets
31
32
  end
32
33
  end
33
34
  end
34
35
 
35
- class Set
36
- end
37
-
38
36
  class << Set
39
37
  def uncons(val)
40
38
  accept_array_only(val)
@@ -44,20 +42,20 @@ class << Set
44
42
  end
45
43
  end
46
44
  end
47
-
45
+
48
46
  def unjoin(val)
49
47
  accept_array_only(val)
50
48
  val2 = val.clone
51
49
  xs = []
52
50
  ys = val2.clone
53
51
  rets = [[xs, ys]]
54
- if !val2.empty? then
52
+ if val2.empty?
53
+ rets
54
+ else
55
55
  x = val2.shift
56
56
  ys2 = val2.clone
57
57
  rets2 = unjoin(ys2)
58
- rets = (rets2.map {|xs2, _| [xs2, ys]}) + (rets2.map {|xs2, ys2| [[x]+xs2, ys]})
59
- rets
60
- else
58
+ rets = (rets2.map { |xs2, _| [xs2, ys] }) + (rets2.map { |xs2, ys2| [[x] + xs2, ys] })
61
59
  rets
62
60
  end
63
61
  end
@@ -1,3 +1,3 @@
1
1
  module Egison
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  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.2.0
4
+ version: 0.2.1
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-05-28 00:00:00.000000000 Z
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake