ludy 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +88 -57
- data/Manifest.txt +96 -0
- data/NOTICE +10 -23
- data/README +173 -10
- data/Rakefile +33 -0
- data/TODO +5 -0
- data/bin/ludy +11 -0
- data/lib/ludy/all.rb +3 -0
- data/lib/ludy/array/body.rb +9 -0
- data/lib/ludy/array/combine.rb +16 -0
- data/lib/ludy/array/combos.rb +23 -0
- data/lib/ludy/array/filter.rb +4 -0
- data/lib/ludy/array/foldl.rb +5 -0
- data/lib/ludy/array/foldr.rb +8 -0
- data/lib/ludy/array/reverse_map.rb +7 -0
- data/lib/ludy/array/rotate.rb +22 -0
- data/lib/ludy/array.rb +3 -0
- data/lib/ludy/blackhole.rb +17 -0
- data/lib/ludy/class/undef_all_methods.rb +9 -0
- data/lib/ludy/class.rb +3 -0
- data/lib/ludy/deprecated/aspect.rb +26 -0
- data/lib/ludy/deprecated/callstack.rb +24 -0
- data/lib/ludy/deprecated/curry.rb +29 -0
- data/lib/ludy/deprecated/rambda.rb +23 -0
- data/lib/ludy/deprecated/this.rb +14 -0
- data/lib/ludy/deprecated/untranspose.rb +12 -0
- data/lib/ludy/deprecated/unzip.rb +7 -0
- data/lib/ludy/{dice.rb → dices.rb} +18 -22
- data/lib/ludy/kernel/defun.rb +10 -0
- data/lib/ludy/kernel/ergo.rb +16 -0
- data/lib/ludy/kernel/id.rb +6 -0
- data/lib/ludy/kernel/if_else.rb +14 -0
- data/lib/ludy/kernel/m.rb +5 -0
- data/lib/ludy/kernel/public_send.rb +13 -0
- data/lib/ludy/kernel/singleton_method.rb +13 -0
- data/lib/ludy/kernel/tap.rb +10 -0
- data/lib/ludy/kernel.rb +3 -0
- data/lib/ludy/lazy.rb +9 -16
- data/lib/ludy/message_dispatcher.rb +58 -0
- data/lib/ludy/pattern_matcher.rb +41 -0
- data/lib/ludy/proc/bind.rb +21 -0
- data/lib/ludy/proc/chain.rb +17 -0
- data/lib/ludy/proc/compose.rb +9 -0
- data/lib/ludy/proc/curry.rb +39 -0
- data/lib/ludy/proc.rb +3 -0
- data/lib/ludy/symbol/curry.rb +10 -0
- data/lib/ludy/symbol/to_msg.rb +10 -0
- data/lib/ludy/symbol/to_proc.rb +7 -0
- data/lib/ludy/symbol.rb +3 -0
- data/lib/ludy/tasks/erb_cpp/attr_builder.rb +49 -0
- data/lib/ludy/tasks/erb_cpp/header_guard.rb +12 -0
- data/lib/ludy/tasks/erb_cpp/template_forward_parameters.rb +43 -0
- data/lib/ludy/tasks/erb_cpp.rb +35 -0
- data/lib/ludy/tasks.rb +3 -0
- data/lib/ludy/test/helper.rb +3 -0
- data/lib/ludy/variable.rb +9 -17
- data/lib/ludy/y_combinator.rb +3 -22
- data/lib/ludy/z_combinator.rb +2 -16
- data/lib/ludy.rb +74 -23
- data/lib/puzzle_generator/chain.rb +2 -2
- data/lib/puzzle_generator/chained_map.rb +7 -10
- data/lib/puzzle_generator/colored_map.rb +2 -2
- data/lib/puzzle_generator/map.rb +8 -12
- data/lib/puzzle_generator/misc.rb +5 -4
- data/lib/puzzle_generator/puzzle.rb +4 -4
- data/lib/puzzle_generator.rb +2 -2
- data/spec/ludy_spec.rb +22 -0
- data/tasks/annotations.rake +30 -0
- data/tasks/doc.rake +50 -0
- data/tasks/gem.rake +89 -0
- data/tasks/manifest.rake +41 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +151 -0
- data/tasks/spec.rake +40 -0
- data/tasks/svn.rake +44 -0
- data/tasks/test.rake +40 -0
- data/test/deprecated/callstack.rb +18 -0
- data/test/deprecated/curry.rb +34 -0
- data/test/deprecated/rambda.rb +15 -0
- data/test/{tc_this.rb → deprecated/this.rb} +2 -18
- data/test/{ts_ludy.rb → deprecated/ts_ludy.rb} +2 -17
- data/test/deprecated/unzip_and_untranspose.rb +13 -0
- data/test/{test_puzzle.rb → example_puzzle.rb} +3 -2
- data/test/test_all.rb +21 -0
- data/test/test_array.rb +47 -0
- data/test/test_class.rb +13 -0
- data/test/test_defun.rb +37 -0
- data/test/test_dices.rb +32 -0
- data/test/test_kernel.rb +36 -0
- data/test/test_lazy.rb +18 -0
- data/test/test_proc.rb +57 -0
- data/test/test_symbol.rb +15 -0
- data/test/test_variable.rb +29 -0
- data/test/test_y_combinator.rb +21 -0
- data/test/test_z_combinator.rb +20 -0
- metadata +134 -51
- data/lib/lib/amulti.rb +0 -40
- data/lib/lib/multi.rb +0 -139
- data/lib/lib/smulti.rb +0 -56
- data/lib/ludy/aspect.rb +0 -41
- data/lib/ludy/bind.rb +0 -31
- data/lib/ludy/callstack.rb +0 -39
- data/lib/ludy/curry.rb +0 -49
- data/lib/ludy/ludy_ext.rb +0 -145
- data/lib/ludy/rambda.rb +0 -42
- data/lib/ludy/this.rb +0 -34
- data/ludy.gemspec +0 -44
- data/test/tc_bind.rb +0 -29
- data/test/tc_callstack.rb +0 -34
- data/test/tc_curry.rb +0 -51
- data/test/tc_dice.rb +0 -48
- data/test/tc_lazy.rb +0 -34
- data/test/tc_ludy_ext.rb +0 -154
- data/test/tc_rambda.rb +0 -31
- data/test/tc_variable.rb +0 -45
- data/test/tc_y_combinator.rb +0 -37
- data/test/tc_z_combinator.rb +0 -36
data/test/tc_ludy_ext.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require 'test/unit'
|
18
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')
|
19
|
-
require_ludy 'ludy_ext'
|
20
|
-
|
21
|
-
class TestLudyExt < Test::Unit::TestCase
|
22
|
-
def test_object_tap
|
23
|
-
assert_equal '11', 10.tap{|i| assert_equal '10', i.to_s}.succ.to_s
|
24
|
-
end
|
25
|
-
def test_blackhole
|
26
|
-
assert_equal nil, nil.XD.Orz.zzz
|
27
|
-
end
|
28
|
-
def test_fixnum_collect
|
29
|
-
# a, b, c = 3.collect{|i| i}
|
30
|
-
a, b, c = (0..2).to_a
|
31
|
-
assert_equal 0, a
|
32
|
-
assert_equal 1, b
|
33
|
-
assert_equal 2, c
|
34
|
-
|
35
|
-
# array = 5.collect{Array.new}
|
36
|
-
array = Array.new(5).map{[]}
|
37
|
-
assert_equal 5, array.size
|
38
|
-
5.times{|y|
|
39
|
-
5.times{|x|
|
40
|
-
break if x == y
|
41
|
-
assert_not_equal array[x].object_id, array[y].object_id
|
42
|
-
}
|
43
|
-
assert_equal Array, array[y].class
|
44
|
-
}
|
45
|
-
end
|
46
|
-
def test_if
|
47
|
-
assert_equal "XD", (true ).if{"XD"}
|
48
|
-
assert (false).if{"XD"}.nil?
|
49
|
-
assert_equal "Orz", (false).if{"XD"}.else{"Orz"}
|
50
|
-
assert_equal "XD", (true ).if{"XD"}.else{"Orz"}
|
51
|
-
assert_equal "XD", (true ).if{"xd"}.upcase
|
52
|
-
assert (false).if{"xd"}.upcase.nil?
|
53
|
-
assert_equal "OTL", (false).if{"xd"}.else{"otl"}.upcase
|
54
|
-
assert_equal "XD", (true ).if{"xd"}.else{"otl"}.upcase
|
55
|
-
end
|
56
|
-
def test_filter
|
57
|
-
assert_equal [1,2,3], [1,18,29,9,4,3,2,1,3,7].filter{|i| i<=3}.sort.uniq
|
58
|
-
end
|
59
|
-
def test_folds
|
60
|
-
assert_equal 6, [1,2,3].foldl(:+.to_proc, 0)
|
61
|
-
assert_equal -6, [1,2,3].foldl(:-.to_proc, 0)
|
62
|
-
assert_equal 6, [1,2,3].foldr(:+.to_proc, 0)
|
63
|
-
assert_equal 2, [1,2,3].foldr(:-.to_proc, 0)
|
64
|
-
end
|
65
|
-
def test_proc_curry
|
66
|
-
multiply = lambda{|l,r| l*r}
|
67
|
-
|
68
|
-
double = multiply.curry[2]
|
69
|
-
assert_equal 8, double[4]
|
70
|
-
assert_equal 6, double[3]
|
71
|
-
|
72
|
-
xd = multiply['XD', 5]
|
73
|
-
assert_equal 'XDXDXDXDXD', xd
|
74
|
-
|
75
|
-
assert_equal 29, :+.to_proc.curry[18][11]
|
76
|
-
assert_equal (0..4).to_a, lambda{|a,b,c,d,e|[a,b,c,d,e]}.curry[0][1][2][3][4]
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_symbol_curry
|
80
|
-
a = [1,2,3]
|
81
|
-
assert_equal nil, a.find(&:==.curry[0])
|
82
|
-
assert_equal 2, a.find(&:==.curry[2])
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_proc_chain
|
86
|
-
f1 = lambda{|v| v+1}
|
87
|
-
assert_equal 5, f1[4]
|
88
|
-
|
89
|
-
f2 = lambda{|v| v+2}
|
90
|
-
assert_equal 6, f2[4]
|
91
|
-
|
92
|
-
f3 = f1.chain f2
|
93
|
-
assert_equal [6,7], f3[5]
|
94
|
-
|
95
|
-
f4 = f3.chain f1
|
96
|
-
assert_equal [2,3,2], f4[1]
|
97
|
-
|
98
|
-
f5 = f4.chain{|v|[10,11,v]}
|
99
|
-
assert_equal [1,2,1,10,11,0], f5[0]
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_proc_compose
|
103
|
-
f1 = lambda{|v| v+1}
|
104
|
-
f2 = lambda{|v| v*2}
|
105
|
-
f3 = f1.compose f2
|
106
|
-
assert_equal 21, f3[10]
|
107
|
-
|
108
|
-
f4 = lambda{|a,b| a*b}
|
109
|
-
f5 = lambda{|a,b| [a*b, a-b]}
|
110
|
-
f6 = f4.compose f5
|
111
|
-
assert_equal -30, f6[3,5]
|
112
|
-
|
113
|
-
f7 = lambda{|a| a*2}.compose f6.compose{|a,b| [b,a]}
|
114
|
-
assert_equal 60, f7[3,5]
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_symbol_to_msg
|
118
|
-
assert_equal [3, 7], [[1,2],[3,4]].map(&:'inject &:+'.to_msg)
|
119
|
-
assert_equal 29, :'to_i*2+9'.to_msg['10']
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_combine
|
123
|
-
assert_equal [4, 6], [1,2].combine([3,4])
|
124
|
-
assert_equal [9, 12], [1,2].combine([3,4], [5,6])
|
125
|
-
|
126
|
-
a = [[1,2],[3,4],[5,6]]
|
127
|
-
assert_equal [9, 12], a.inject(&:combine)
|
128
|
-
assert_equal [9, 12], a.shift.combine(*a)
|
129
|
-
|
130
|
-
a = [18,29]
|
131
|
-
a.combine! [12, 1]
|
132
|
-
assert_equal [30, 30], a
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_unzip_and_untranspose
|
136
|
-
a = [1,2,3]
|
137
|
-
b = %w{a b c}
|
138
|
-
assert_equal [a, b], a.zip(b).to_a.untranspose
|
139
|
-
assert_equal [a, b], [a, b].transpose.untranspose
|
140
|
-
assert_equal a, a.zip(b).to_a.unzip
|
141
|
-
|
142
|
-
c = [nil, false, true]
|
143
|
-
assert_equal [a, b, c], a.zip(b, c).to_a.untranspose
|
144
|
-
assert_equal [a, b, c], [a, b, c].transpose.untranspose
|
145
|
-
assert_equal a, a.zip(b, c).to_a.unzip
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_id_and_m
|
149
|
-
assert_equal 'XD', id('XD')
|
150
|
-
assert_equal 'Orz', 'Orz'.id
|
151
|
-
assert_equal [1,3], [1,3].map(&m(:id))
|
152
|
-
assert_equal [2,4], [2,4].map(&:id)
|
153
|
-
end
|
154
|
-
end
|
data/test/tc_rambda.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require 'test/unit'
|
18
|
-
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
-
require_ludy 'rambda'
|
20
|
-
|
21
|
-
class TestRambda < Test::Unit::TestCase
|
22
|
-
include Ludy
|
23
|
-
def test_rambda
|
24
|
-
assert_equal(3628800, rambda{|n| n==1 ? 1 : n*this[n-1]}[10])
|
25
|
-
assert_equal([1,1,2,3,5,8,13,21,34,55],
|
26
|
-
(0...10).map(&rambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}))
|
27
|
-
|
28
|
-
v = "can't refer v"
|
29
|
-
assert_raise(NameError){ rambda{v}.call }
|
30
|
-
end
|
31
|
-
end
|
data/test/tc_variable.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require 'test/unit'
|
18
|
-
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
-
require_ludy 'variable'
|
20
|
-
|
21
|
-
class TestVariable < Test::Unit::TestCase
|
22
|
-
include Ludy
|
23
|
-
class Qoo
|
24
|
-
def cool
|
25
|
-
'cool ~~~~'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_variable
|
30
|
-
x = var Qoo.new
|
31
|
-
y = x
|
32
|
-
|
33
|
-
assert_equal x.__obj__, y.__obj__
|
34
|
-
assert_equal Qoo, x.__obj__.class
|
35
|
-
assert_equal Qoo, x.class
|
36
|
-
|
37
|
-
assert_equal 'cool ~~~~', x.cool
|
38
|
-
assert_equal 'cool ~~~~', y.cool
|
39
|
-
|
40
|
-
x.__obj__ = nil
|
41
|
-
|
42
|
-
assert x.nil?
|
43
|
-
assert y.nil?
|
44
|
-
end
|
45
|
-
end
|
data/test/tc_y_combinator.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require 'test/unit'
|
18
|
-
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
-
require_ludy 'y_combinator'
|
20
|
-
|
21
|
-
include Ludy # why should this be here?
|
22
|
-
|
23
|
-
class TestYCombinator < Test::Unit::TestCase
|
24
|
-
def test_y_combinator
|
25
|
-
fact_ = lambda{|this|
|
26
|
-
lambda{|n| n==1 ? 1 : n*this[n-1]}
|
27
|
-
}
|
28
|
-
fact = Y[fact_]
|
29
|
-
assert_equal(3628800, fact[10])
|
30
|
-
|
31
|
-
fib_ = lambda{|this|
|
32
|
-
lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}
|
33
|
-
}
|
34
|
-
fib = Y[fib_]
|
35
|
-
assert_equal([1,1,2,3,5,8,13,21,34,55], (0...10).map(&fib))
|
36
|
-
end
|
37
|
-
end
|
data/test/tc_z_combinator.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require 'test/unit'
|
18
|
-
require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
|
19
|
-
require_ludy 'z_combinator'
|
20
|
-
|
21
|
-
class TestZCombinator < Test::Unit::TestCase
|
22
|
-
include Ludy
|
23
|
-
def test_z_combinator
|
24
|
-
fact_ = lambda{|this|
|
25
|
-
lambda{|n| n==1 ? 1 : n*this[n-1]}
|
26
|
-
}
|
27
|
-
fact = Z[fact_]
|
28
|
-
assert_equal(3628800, fact[10])
|
29
|
-
|
30
|
-
fib_ = lambda{|this|
|
31
|
-
lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}
|
32
|
-
}
|
33
|
-
fib = Z[fib_]
|
34
|
-
assert_equal([1,1,2,3,5,8,13,21,34,55], (0...10).map(&fib))
|
35
|
-
end
|
36
|
-
end
|