ludy 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/CHANGES +88 -57
  2. data/Manifest.txt +96 -0
  3. data/NOTICE +10 -23
  4. data/README +173 -10
  5. data/Rakefile +33 -0
  6. data/TODO +5 -0
  7. data/bin/ludy +11 -0
  8. data/lib/ludy/all.rb +3 -0
  9. data/lib/ludy/array/body.rb +9 -0
  10. data/lib/ludy/array/combine.rb +16 -0
  11. data/lib/ludy/array/combos.rb +23 -0
  12. data/lib/ludy/array/filter.rb +4 -0
  13. data/lib/ludy/array/foldl.rb +5 -0
  14. data/lib/ludy/array/foldr.rb +8 -0
  15. data/lib/ludy/array/reverse_map.rb +7 -0
  16. data/lib/ludy/array/rotate.rb +22 -0
  17. data/lib/ludy/array.rb +3 -0
  18. data/lib/ludy/blackhole.rb +17 -0
  19. data/lib/ludy/class/undef_all_methods.rb +9 -0
  20. data/lib/ludy/class.rb +3 -0
  21. data/lib/ludy/deprecated/aspect.rb +26 -0
  22. data/lib/ludy/deprecated/callstack.rb +24 -0
  23. data/lib/ludy/deprecated/curry.rb +29 -0
  24. data/lib/ludy/deprecated/rambda.rb +23 -0
  25. data/lib/ludy/deprecated/this.rb +14 -0
  26. data/lib/ludy/deprecated/untranspose.rb +12 -0
  27. data/lib/ludy/deprecated/unzip.rb +7 -0
  28. data/lib/ludy/{dice.rb → dices.rb} +18 -22
  29. data/lib/ludy/kernel/defun.rb +10 -0
  30. data/lib/ludy/kernel/ergo.rb +16 -0
  31. data/lib/ludy/kernel/id.rb +6 -0
  32. data/lib/ludy/kernel/if_else.rb +14 -0
  33. data/lib/ludy/kernel/m.rb +5 -0
  34. data/lib/ludy/kernel/public_send.rb +13 -0
  35. data/lib/ludy/kernel/singleton_method.rb +13 -0
  36. data/lib/ludy/kernel/tap.rb +10 -0
  37. data/lib/ludy/kernel.rb +3 -0
  38. data/lib/ludy/lazy.rb +9 -16
  39. data/lib/ludy/message_dispatcher.rb +58 -0
  40. data/lib/ludy/pattern_matcher.rb +41 -0
  41. data/lib/ludy/proc/bind.rb +21 -0
  42. data/lib/ludy/proc/chain.rb +17 -0
  43. data/lib/ludy/proc/compose.rb +9 -0
  44. data/lib/ludy/proc/curry.rb +39 -0
  45. data/lib/ludy/proc.rb +3 -0
  46. data/lib/ludy/symbol/curry.rb +10 -0
  47. data/lib/ludy/symbol/to_msg.rb +10 -0
  48. data/lib/ludy/symbol/to_proc.rb +7 -0
  49. data/lib/ludy/symbol.rb +3 -0
  50. data/lib/ludy/tasks/erb_cpp/attr_builder.rb +49 -0
  51. data/lib/ludy/tasks/erb_cpp/header_guard.rb +12 -0
  52. data/lib/ludy/tasks/erb_cpp/template_forward_parameters.rb +43 -0
  53. data/lib/ludy/tasks/erb_cpp.rb +35 -0
  54. data/lib/ludy/tasks.rb +3 -0
  55. data/lib/ludy/test/helper.rb +3 -0
  56. data/lib/ludy/variable.rb +9 -17
  57. data/lib/ludy/y_combinator.rb +3 -22
  58. data/lib/ludy/z_combinator.rb +2 -16
  59. data/lib/ludy.rb +74 -23
  60. data/lib/puzzle_generator/chain.rb +2 -2
  61. data/lib/puzzle_generator/chained_map.rb +7 -10
  62. data/lib/puzzle_generator/colored_map.rb +2 -2
  63. data/lib/puzzle_generator/map.rb +8 -12
  64. data/lib/puzzle_generator/misc.rb +5 -4
  65. data/lib/puzzle_generator/puzzle.rb +4 -4
  66. data/lib/puzzle_generator.rb +2 -2
  67. data/spec/ludy_spec.rb +22 -0
  68. data/tasks/annotations.rake +30 -0
  69. data/tasks/doc.rake +50 -0
  70. data/tasks/gem.rake +89 -0
  71. data/tasks/manifest.rake +41 -0
  72. data/tasks/rubyforge.rake +57 -0
  73. data/tasks/setup.rb +151 -0
  74. data/tasks/spec.rake +40 -0
  75. data/tasks/svn.rake +44 -0
  76. data/tasks/test.rake +40 -0
  77. data/test/deprecated/callstack.rb +18 -0
  78. data/test/deprecated/curry.rb +34 -0
  79. data/test/deprecated/rambda.rb +15 -0
  80. data/test/{tc_this.rb → deprecated/this.rb} +2 -18
  81. data/test/{ts_ludy.rb → deprecated/ts_ludy.rb} +2 -17
  82. data/test/deprecated/unzip_and_untranspose.rb +13 -0
  83. data/test/{test_puzzle.rb → example_puzzle.rb} +3 -2
  84. data/test/test_all.rb +21 -0
  85. data/test/test_array.rb +47 -0
  86. data/test/test_class.rb +13 -0
  87. data/test/test_defun.rb +37 -0
  88. data/test/test_dices.rb +32 -0
  89. data/test/test_kernel.rb +36 -0
  90. data/test/test_lazy.rb +18 -0
  91. data/test/test_proc.rb +57 -0
  92. data/test/test_symbol.rb +15 -0
  93. data/test/test_variable.rb +29 -0
  94. data/test/test_y_combinator.rb +21 -0
  95. data/test/test_z_combinator.rb +20 -0
  96. metadata +134 -51
  97. data/lib/lib/amulti.rb +0 -40
  98. data/lib/lib/multi.rb +0 -139
  99. data/lib/lib/smulti.rb +0 -56
  100. data/lib/ludy/aspect.rb +0 -41
  101. data/lib/ludy/bind.rb +0 -31
  102. data/lib/ludy/callstack.rb +0 -39
  103. data/lib/ludy/curry.rb +0 -49
  104. data/lib/ludy/ludy_ext.rb +0 -145
  105. data/lib/ludy/rambda.rb +0 -42
  106. data/lib/ludy/this.rb +0 -34
  107. data/ludy.gemspec +0 -44
  108. data/test/tc_bind.rb +0 -29
  109. data/test/tc_callstack.rb +0 -34
  110. data/test/tc_curry.rb +0 -51
  111. data/test/tc_dice.rb +0 -48
  112. data/test/tc_lazy.rb +0 -34
  113. data/test/tc_ludy_ext.rb +0 -154
  114. data/test/tc_rambda.rb +0 -31
  115. data/test/tc_variable.rb +0 -45
  116. data/test/tc_y_combinator.rb +0 -37
  117. data/test/tc_z_combinator.rb +0 -36
@@ -0,0 +1,13 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/class/undef_all_methods'
4
+
5
+ class TestClass < Test::Unit::TestCase
6
+ class C; end
7
+ def test_undef_all_methods
8
+ c = C.new
9
+ assert c.respond_to?(:to_s)
10
+ C.undef_all_methods
11
+ # then? how to test?
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/kernel/defun'
4
+
5
+ class TestDefun < Test::Unit::TestCase
6
+ def test_fact
7
+ defun :fact, 0 do |n|
8
+ 1
9
+ end
10
+
11
+ defun :fact, Integer do |n|
12
+ n * fact(n-1)
13
+ end
14
+
15
+ assert_equal 3628800, fact(10)
16
+ end
17
+
18
+ def test_overloading
19
+ defun :f, Integer do |n| 1; end
20
+ defun :f, String do |n| '2'; end
21
+ defun(:f, Integer, Integer) do |n,g| 3; end
22
+
23
+ assert_equal 1, f(10)
24
+ assert_equal '2', f('')
25
+ assert_equal 3, f(1,1)
26
+ assert_raise NoMethodError do f('1', 2); end
27
+ end
28
+
29
+ def test_more
30
+ defun(:more, 3, Object){3}
31
+ defun(:more, Object, String){|o,s|s}
32
+ assert_equal 'a', more(1,'a')
33
+ # because [3, '2'] matches [3, Object]
34
+ assert_equal 3, more(3,'2')
35
+ assert_equal 3, more(3,nil)
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/dices'
4
+
5
+ class TestDices < Test::Unit::TestCase
6
+ include Ludy
7
+ def test_dices
8
+ 50.times{ assert((1..20).include?(1.roll)) }
9
+ 50.times{ assert((2..40).include?(2.roll)) }
10
+ 50.times{ assert((3..18).include?(3.roll(6))) }
11
+
12
+ _4d20 = 4.dices
13
+ assert_equal 4, _4d20.min
14
+ assert_equal 4*20, _4d20.max
15
+ 50.times{ assert((4..80).include?(_4d20.roll)) }
16
+
17
+ _5d12 = 5.dices 12
18
+ assert_equal 5, _5d12.min
19
+ assert_equal 5*12, _5d12.max
20
+ 50.times{ assert((5..60).include?(_5d12.roll)) }
21
+
22
+ ds = DiceSet.new _4d20, _5d12
23
+ assert_equal _4d20.min+_5d12.min, ds.min
24
+ assert_equal _4d20.max+_5d12.max, ds.max
25
+ 50.times{ assert((ds.min..ds.max).include?(ds.roll)) }
26
+
27
+ du = DiceSet.new ds, 6.dices(6)
28
+ assert_equal ds.min+6, du.min
29
+ assert_equal ds.max+36, du.max
30
+ 50.times{ assert((du.min..du.max).include?(du.roll)) }
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/kernel'
4
+
5
+ class TestKernel < Test::Unit::TestCase
6
+ class C
7
+ def pub; 'pub'; end
8
+ def method_missing msg, *args, &block; args.unshift(msg.to_s.upcase).join(' '); end
9
+ private; def pri; 'pri'; end
10
+ end
11
+ def test_public_send
12
+ c = C.new
13
+ assert_equal 'pub', c.public_send(:pub)
14
+ assert_equal 'PRI', c.public_send(:pri)
15
+ assert_equal 'XD', c.public_send(:xd)
16
+ end
17
+ def test_tap
18
+ assert_equal '11', 10.tap{|i| assert_equal '10', i.to_s}.succ.to_s
19
+ end
20
+ def test_if
21
+ assert_equal "XD", (true ).if{"XD"}
22
+ assert false.if{"XD"}.nil?
23
+ assert_equal "Orz", (false).if{"XD"}.else{"Orz"}
24
+ assert_equal "XD", (true ).if{"XD"}.else{"Orz"}
25
+ assert_equal "XD", (true ).if{"xd"}.upcase
26
+ assert false.if{"xd"}.upcase.nil?
27
+ assert_equal "OTL", (false).if{"xd"}.else{"otl"}.upcase
28
+ assert_equal "XD", (true ).if{"xd"}.else{"otl"}.upcase
29
+ end
30
+ def test_id_and_m
31
+ assert_equal 'XD', id('XD')
32
+ assert_equal 'Orz', 'Orz'.id
33
+ assert_equal [1,3], [1,3].map(&m(:id))
34
+ assert_equal [2,4], [2,4].map(&:id)
35
+ end
36
+ end
data/test/test_lazy.rb ADDED
@@ -0,0 +1,18 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/lazy'
4
+
5
+ class TestLazy < Test::Unit::TestCase
6
+ include Ludy
7
+ def setup; @data = 0; end
8
+ def get; @data += 1; end
9
+ def test_lazy
10
+ assert_equal 0, @data
11
+ v = lazy{get}
12
+ assert_equal 0, @data
13
+ assert_equal 1, v
14
+ assert_equal '1', v.to_s
15
+ assert_equal 1, v
16
+ assert_equal '1', v.to_s
17
+ end
18
+ end
data/test/test_proc.rb ADDED
@@ -0,0 +1,57 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/proc'
4
+
5
+ class TestProc < Test::Unit::TestCase
6
+ def test_bind
7
+ assert_equal [9,8,7], ([1,2,3].map(&lambda{|lhs, rhs| lhs-rhs}.bind(10, :_1)))
8
+ assert_equal [3,2,1], (lambda{|a,b,c| [a,b,c]}.bind :_3, :_2, :_1)[1,2,3]
9
+ assert_equal [1,9,3], (lambda{|a,b,c| [a,b,c]}.bind :_1, 9, :_3)[1,2,3]
10
+ assert_equal [9,2,3], (lambda{|a,b,c| [a,b,c]}.bind 9)[2,3]
11
+ assert_equal [9,4,2], (lambda{|a,b,c| [a,b,c]}.bind 9, :_3)[2,3,4]
12
+ end
13
+ def test_curry
14
+ multiply = lambda{|l,r| l*r}
15
+
16
+ double = multiply.curry[2]
17
+ assert_equal 8, double[4]
18
+ assert_equal 6, double[3]
19
+
20
+ xd = multiply['XD', 5]
21
+ assert_equal 'XDXDXDXDXD', xd
22
+
23
+ assert_equal 29, :+.to_proc.curry[18][11]
24
+ assert_equal((0..4).to_a, lambda{|a,b,c,d,e|[a,b,c,d,e]}.curry[0][1][2][3][4])
25
+ end
26
+ def test_compose
27
+ f1 = lambda{|v| v+1}
28
+ f2 = lambda{|v| v*2}
29
+ f3 = f1.compose f2
30
+ assert_equal 21, f3[10]
31
+
32
+ f4 = lambda{|a,b| a*b}
33
+ f5 = lambda{|a,b| [a*b, a-b]}
34
+ f6 = f4.compose f5
35
+ assert_equal(-30, f6[3,5])
36
+
37
+ f7 = lambda{|a| a*2}.compose f6.compose{|a,b| [b,a]}
38
+ assert_equal 60, f7[3,5]
39
+ end
40
+ def test_chain
41
+ f1 = lambda{|v| v+1}
42
+ assert_equal 5, f1[4]
43
+
44
+ f2 = lambda{|v| v+2}
45
+ assert_equal 6, f2[4]
46
+
47
+ f3 = f1.chain f2
48
+ assert_equal [6,7], f3[5]
49
+
50
+ f4 = f3.chain f1
51
+ assert_equal [2,3,2], f4[1]
52
+
53
+ f5 = f4.chain{|v|[10,11,v]}
54
+ assert_equal [1,2,1,10,11,0], f5[0]
55
+ end
56
+ end
57
+
@@ -0,0 +1,15 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/symbol'
4
+
5
+ class TestSymbol < Test::Unit::TestCase
6
+ def test_curry
7
+ a = [1,2,3]
8
+ assert_equal nil, a.find(&:==.curry[0])
9
+ assert_equal 2, a.find(&:==.curry[2])
10
+ end
11
+ def test_to_msg
12
+ assert_equal [3, 7], [[1,2],[3,4]].map(&:'inject(&:+)'.to_msg)
13
+ assert_equal 29, :'to_i*2+9'.to_msg['10']
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/variable'
4
+
5
+ class TestVariable < Test::Unit::TestCase
6
+ include Ludy
7
+ class Qoo
8
+ def cool
9
+ 'cool ~~~~'
10
+ end
11
+ end
12
+
13
+ def test_variable
14
+ x = var Qoo.new
15
+ y = x
16
+
17
+ assert_equal x.__obj__, y.__obj__
18
+ assert_equal Qoo, x.__obj__.class
19
+ assert_equal Qoo, x.class
20
+
21
+ assert_equal 'cool ~~~~', x.cool
22
+ assert_equal 'cool ~~~~', y.cool
23
+
24
+ x.__obj__ = nil
25
+
26
+ assert x.nil?
27
+ assert y.nil?
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/y_combinator'
4
+
5
+ include Ludy # why should this be here?
6
+
7
+ class TestYCombinator < Test::Unit::TestCase
8
+ def test_y_combinator
9
+ fact_ = lambda{|this|
10
+ lambda{|n| n==1 ? 1 : n*this[n-1]}
11
+ }
12
+ fact = Y[fact_]
13
+ assert_equal(3628800, fact[10])
14
+
15
+ fib_ = lambda{|this|
16
+ lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}
17
+ }
18
+ fib = Y[fib_]
19
+ assert_equal([1,1,2,3,5,8,13,21,34,55], (0...10).map(&fib))
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ludy/test/helper')
3
+ require 'ludy/z_combinator'
4
+
5
+ class TestZCombinator < Test::Unit::TestCase
6
+ include Ludy
7
+ def test_z_combinator
8
+ fact_ = lambda{|this|
9
+ lambda{|n| n==1 ? 1 : n*this[n-1]}
10
+ }
11
+ fact = Z[fact_]
12
+ assert_equal(3628800, fact[10])
13
+
14
+ fib_ = lambda{|this|
15
+ lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}
16
+ }
17
+ fib = Z[fib_]
18
+ assert_equal([1,1,2,3,5,8,13,21,34,55], (0...10).map(&fib))
19
+ end
20
+ end
metadata CHANGED
@@ -1,78 +1,150 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ludy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Lin Jen-Shin(a.k.a. godfat)
7
+ - "Lin Jen-Shin (a.k.a. godfat \xE7\x9C\x9F\xE5\xB8\xB8)"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-07 00:00:00 +08:00
12
+ date: 2008-01-09 00:00:00 +08:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description:
17
- email: "strip number: 135godfat7911@246godfat.890org"
18
- executables: []
19
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: "== DESCRIPTION: Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library."
25
+ email: "strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org"
26
+ executables:
27
+ - ludy
20
28
  extensions: []
21
29
 
22
- extra_rdoc_files: []
23
-
30
+ extra_rdoc_files:
31
+ - CHANGES
32
+ - LICENSE
33
+ - NOTICE
34
+ - README
35
+ - TODO
36
+ - bin/ludy
37
+ - tasks/annotations.rake
38
+ - tasks/doc.rake
39
+ - tasks/gem.rake
40
+ - tasks/manifest.rake
41
+ - tasks/rubyforge.rake
42
+ - tasks/spec.rake
43
+ - tasks/svn.rake
44
+ - tasks/test.rake
24
45
  files:
25
- - lib/lib
26
- - lib/lib/amulti.rb
27
- - lib/lib/multi.rb
28
- - lib/lib/smulti.rb
29
- - lib/ludy
30
- - lib/ludy/aspect.rb
31
- - lib/ludy/bind.rb
32
- - lib/ludy/callstack.rb
33
- - lib/ludy/curry.rb
34
- - lib/ludy/dice.rb
46
+ - CHANGES
47
+ - LICENSE
48
+ - Manifest.txt
49
+ - NOTICE
50
+ - README
51
+ - Rakefile
52
+ - TODO
53
+ - bin/ludy
54
+ - lib/ludy.rb
55
+ - lib/ludy/all.rb
56
+ - lib/ludy/array.rb
57
+ - lib/ludy/array/body.rb
58
+ - lib/ludy/array/combine.rb
59
+ - lib/ludy/array/combos.rb
60
+ - lib/ludy/array/filter.rb
61
+ - lib/ludy/array/foldl.rb
62
+ - lib/ludy/array/foldr.rb
63
+ - lib/ludy/array/reverse_map.rb
64
+ - lib/ludy/array/rotate.rb
65
+ - lib/ludy/blackhole.rb
66
+ - lib/ludy/class.rb
67
+ - lib/ludy/class/undef_all_methods.rb
68
+ - lib/ludy/deprecated/aspect.rb
69
+ - lib/ludy/deprecated/callstack.rb
70
+ - lib/ludy/deprecated/curry.rb
71
+ - lib/ludy/deprecated/rambda.rb
72
+ - lib/ludy/deprecated/this.rb
73
+ - lib/ludy/deprecated/untranspose.rb
74
+ - lib/ludy/deprecated/unzip.rb
75
+ - lib/ludy/dices.rb
76
+ - lib/ludy/kernel.rb
77
+ - lib/ludy/kernel/defun.rb
78
+ - lib/ludy/kernel/ergo.rb
79
+ - lib/ludy/kernel/id.rb
80
+ - lib/ludy/kernel/if_else.rb
81
+ - lib/ludy/kernel/m.rb
82
+ - lib/ludy/kernel/public_send.rb
83
+ - lib/ludy/kernel/singleton_method.rb
84
+ - lib/ludy/kernel/tap.rb
35
85
  - lib/ludy/lazy.rb
36
- - lib/ludy/ludy_ext.rb
37
- - lib/ludy/rambda.rb
38
- - lib/ludy/this.rb
86
+ - lib/ludy/message_dispatcher.rb
87
+ - lib/ludy/pattern_matcher.rb
88
+ - lib/ludy/proc.rb
89
+ - lib/ludy/proc/bind.rb
90
+ - lib/ludy/proc/chain.rb
91
+ - lib/ludy/proc/compose.rb
92
+ - lib/ludy/proc/curry.rb
93
+ - lib/ludy/symbol.rb
94
+ - lib/ludy/symbol/curry.rb
95
+ - lib/ludy/symbol/to_msg.rb
96
+ - lib/ludy/symbol/to_proc.rb
97
+ - lib/ludy/tasks.rb
98
+ - lib/ludy/tasks/erb_cpp.rb
99
+ - lib/ludy/tasks/erb_cpp/attr_builder.rb
100
+ - lib/ludy/tasks/erb_cpp/header_guard.rb
101
+ - lib/ludy/tasks/erb_cpp/template_forward_parameters.rb
102
+ - lib/ludy/test/helper.rb
39
103
  - lib/ludy/variable.rb
40
104
  - lib/ludy/y_combinator.rb
41
105
  - lib/ludy/z_combinator.rb
42
- - lib/ludy.rb
43
- - lib/puzzle_generator
106
+ - lib/puzzle_generator.rb
44
107
  - lib/puzzle_generator/chain.rb
45
108
  - lib/puzzle_generator/chained_map.rb
46
109
  - lib/puzzle_generator/colored_map.rb
47
110
  - lib/puzzle_generator/map.rb
48
111
  - lib/puzzle_generator/misc.rb
49
112
  - lib/puzzle_generator/puzzle.rb
50
- - lib/puzzle_generator.rb
51
- - test/tc_bind.rb
52
- - test/tc_callstack.rb
53
- - test/tc_curry.rb
54
- - test/tc_dice.rb
55
- - test/tc_lazy.rb
56
- - test/tc_ludy_ext.rb
57
- - test/tc_rambda.rb
58
- - test/tc_this.rb
59
- - test/tc_variable.rb
60
- - test/tc_y_combinator.rb
61
- - test/tc_z_combinator.rb
62
- - test/test_puzzle.rb
63
- - test/ts_ludy.rb
64
- - CHANGES
65
- - lib
66
- - LICENSE
67
- - ludy.gemspec
68
- - NOTICE
69
- - README
70
- - test
71
- has_rdoc: false
113
+ - spec/ludy_spec.rb
114
+ - tasks/annotations.rake
115
+ - tasks/doc.rake
116
+ - tasks/gem.rake
117
+ - tasks/manifest.rake
118
+ - tasks/rubyforge.rake
119
+ - tasks/setup.rb
120
+ - tasks/spec.rake
121
+ - tasks/svn.rake
122
+ - tasks/test.rake
123
+ - test/deprecated/callstack.rb
124
+ - test/deprecated/curry.rb
125
+ - test/deprecated/rambda.rb
126
+ - test/deprecated/this.rb
127
+ - test/deprecated/ts_ludy.rb
128
+ - test/deprecated/unzip_and_untranspose.rb
129
+ - test/example_puzzle.rb
130
+ - test/test_all.rb
131
+ - test/test_array.rb
132
+ - test/test_class.rb
133
+ - test/test_defun.rb
134
+ - test/test_dices.rb
135
+ - test/test_kernel.rb
136
+ - test/test_lazy.rb
137
+ - test/test_proc.rb
138
+ - test/test_symbol.rb
139
+ - test/test_variable.rb
140
+ - test/test_y_combinator.rb
141
+ - test/test_z_combinator.rb
142
+ has_rdoc: true
72
143
  homepage: http://ludy.rubyforge.org/
73
144
  post_install_message:
74
- rdoc_options: []
75
-
145
+ rdoc_options:
146
+ - --main
147
+ - README
76
148
  require_paths:
77
149
  - lib
78
150
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -95,4 +167,15 @@ signing_key:
95
167
  specification_version: 2
96
168
  summary: Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library.
97
169
  test_files:
98
- - test/ts_ludy.rb
170
+ - test/test_all.rb
171
+ - test/test_array.rb
172
+ - test/test_class.rb
173
+ - test/test_defun.rb
174
+ - test/test_dices.rb
175
+ - test/test_kernel.rb
176
+ - test/test_lazy.rb
177
+ - test/test_proc.rb
178
+ - test/test_symbol.rb
179
+ - test/test_variable.rb
180
+ - test/test_y_combinator.rb
181
+ - test/test_z_combinator.rb
data/lib/lib/amulti.rb DELETED
@@ -1,40 +0,0 @@
1
- # = amulti.rb - Array destructuring multiple dispatch for Ruby
2
- #
3
- # Copyright 2005, Christopher Cyll
4
- # mailto: christopher at gmail dot com
5
- #
6
- # == Example
7
- #
8
- # === Array Dispatch (using 'amulti') ===
9
- #
10
-
11
- require 'multi'
12
-
13
- def amulti(method_name, *patterns, &body)
14
- Multi::DISPATCHER.add(Multi::ArrayDispatch, self, method_name, patterns, body)
15
- end
16
-
17
- module Multi
18
- class ArrayDispatch < Dispatch
19
- def initialize(patterns, body)
20
- @count = patterns.size
21
- super(patterns, body)
22
- end
23
-
24
- def match?(params)
25
- return false if params.size != 1
26
- # Call .to_a here?
27
- array = params.first
28
- return false if ! array.kind_of?(Array)
29
- return false if array.size < @count
30
- return super(array[0, @count])
31
- end
32
-
33
- def call(params, block)
34
- array = params.first
35
- use = array[0, @count]
36
- use.push(array[@count..-1])
37
- super(use, block)
38
- end
39
- end
40
- end
data/lib/lib/multi.rb DELETED
@@ -1,139 +0,0 @@
1
- # = multi.rb - Multiple Dispatch and Pattern Matching for Ruby
2
- #
3
- # Copyright 2005, Christopher Cyll
4
- # mailto: christopher at gmail dot com
5
- #
6
- # == Example
7
- #
8
- # === Factorial Function
9
- #
10
- # require 'multi'
11
- # multi(:fac, 0) { 1 }
12
- # multi(:fac, Integer) {|x| x * fac(x-1)}
13
- # fac(5) ==> 120
14
- #
15
- # === List Reversal Function
16
- #
17
- # require 'multi'
18
- # multi(:reverse, []) { [] }
19
- # multi(:reverse, Array) {|list| [list.pop] + reverse(list) }
20
- # reverse([1,2,3]) ==> [3,2,1]
21
- #
22
- # === Method Dispatch
23
- #
24
- # require 'multi'
25
- # class Foo
26
- # multi(:hiya, 0) {|x| "Zero: #{x}" }
27
- # multi(:hiya, Integer) {|x| "Int: #{x}" }
28
- # multi(:hiya, String) {|x| "Str: #{x}" }
29
- # end
30
- #
31
- # f = Foo.new()
32
- # f.hiya(0) ==> "Zero: 0"
33
- # f.hiya(5) ==> "Int: 5"
34
- # f.hiya("hello") ==> "Str: hello"
35
- #
36
- # === Match Any ( _ in Haskell/ML) using Object
37
- #
38
- # require 'multi'
39
- # multi(:baz, 3, Object) { 3 }
40
- # multi(:baz, Object, String) {|o, str| str }
41
- # baz(3, "three") ==> 3
42
- # baz(2, "two") ==> "two"
43
- #
44
- # === Guards Using lambda/Proc
45
- #
46
- # multi(:gt2, lambda {|x| x > 2 }) {|x| x }
47
- # multi(:gt2, Object) { 0 }
48
- # gt2(1) ==> 0
49
- # gt2(4) ==> 4
50
- #
51
- # === Returning Values From Multimethods
52
- #
53
- # multi(:evenify, Integer) do |x|
54
- # next x if x % 2 == 0 # Return x using 'next'
55
- # x += 1
56
- # next x
57
- # end
58
- # evenify(4) ==> 4
59
- # evenify(5) ==> 6
60
- #
61
- # === Declare a clause of a multimethod
62
- #
63
- # multi(:method_name, types_literals_or_guards) do |parameter1, parameter2|
64
- # # code here!
65
- # end
66
-
67
- def multi(method_name, *patterns, &body)
68
- Multi::DISPATCHER.add(Multi::Dispatch, self, method_name, patterns, body)
69
- end
70
-
71
- module Multi
72
- class Dispatch
73
- def initialize(patterns, body)
74
- @patterns = patterns
75
- @body = body
76
- end
77
-
78
- def match?(params)
79
- pairs = params.zip(@patterns)
80
- return pairs.all? do |param, pattern|
81
- if pattern.kind_of?(Class)
82
- param.kind_of?(pattern)
83
- elsif pattern.instance_of?(Proc)
84
- begin
85
- pattern.call(param)
86
- rescue
87
- false
88
- end
89
- elsif pattern.instance_of?(Regexp)
90
- pattern.match(param)
91
- else
92
- param == pattern
93
- end
94
- end
95
- end
96
-
97
- def call(params, block)
98
- @body.call(*params, &block)
99
- end
100
- end
101
-
102
- class Dispatcher
103
- def initialize
104
- @map = {}
105
- end
106
-
107
- def add(type, obj, method_name, patterns, body)
108
- method_name = method_name.id2name if method_name.kind_of?(Symbol)
109
- body = patterns.pop if body.nil?
110
-
111
- # Using the object_id() is pretty sleazy, but it gives us faster
112
- # lookup than object.equal? and searching
113
- key = [obj.object_id(), method_name]
114
- @map[key] ||= []
115
- @map[key].push(type.new(patterns, body))
116
-
117
- # Tried to use send(:define, ...) but Procs can't have &blocks
118
- if ! obj.methods.include?(method_name)
119
- obj.instance_eval <<-"DONE"
120
- def #{method_name}(*params, &block)
121
- Multi::DISPATCHER.call(self, \"#{method_name}\", params, block)
122
- end
123
- DONE
124
- end
125
- end
126
-
127
- def call(obj, method_name, params, block)
128
- dispatches = @map[[obj.object_id, method_name]]
129
- dispatch = dispatches.find{|dispatch| dispatch.match?(params) }
130
- if dispatch.nil?
131
- printed_params = params.map{|param| param.inspect}.join(', ')
132
- raise "No match for #{obj}.#{method_name}(#{printed_params})"
133
- end
134
- dispatch.call(params, block)
135
- end
136
- end
137
-
138
- DISPATCHER = Dispatcher.new()
139
- end