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/CHANGES
CHANGED
@@ -1,95 +1,126 @@
|
|
1
|
+
= ludy changes history
|
1
2
|
|
2
|
-
|
3
|
-
ludy TODO
|
4
|
-
multi
|
5
|
-
chain travel
|
6
|
-
method hook
|
3
|
+
== ludy 0.1.0, 2008.01.08
|
7
4
|
|
8
|
-
|
9
|
-
|
5
|
+
* directory structure rearranged
|
6
|
+
now you would like to require something like:
|
7
|
+
require 'ludy/proc/bind'
|
8
|
+
require 'ludy/lazy'
|
9
|
+
require 'ludy/kernel/defun'
|
10
|
+
require 'puzzle_generator'
|
11
|
+
...
|
12
|
+
the load path is now manipulated by ludy.rb, with require guard,
|
13
|
+
to make sure that all .rb is only required once. (all the same require path.)
|
10
14
|
|
11
|
-
|
15
|
+
* you can now:
|
16
|
+
require 'ludy/kernel' # for all kernel method
|
17
|
+
require 'ludy/all' # for all ludy things
|
12
18
|
|
13
|
-
|
14
|
-
ludy 0.0.8, 2007.12.06
|
19
|
+
* there's no require_ludy anymore.
|
15
20
|
|
16
|
-
1.
|
21
|
+
* project skeleton is now built through Mr Bones 1.3.0, see NOTICE
|
22
|
+
|
23
|
+
* many things are now deprecated. they are hard to implemented correctly,
|
24
|
+
or useless, or easy to be replaced, or for some other reasons.
|
25
|
+
|
26
|
+
* ludy is now compatible with ruby 1.9. and a few ruby 1.9's features are
|
27
|
+
now added in ludy to help improve compatibility between ruby versions.
|
28
|
+
|
29
|
+
* ludy executable is added. it simply call rake with ludy tasks, so:
|
30
|
+
$ ludy test # to run all tests
|
31
|
+
$ ludy doc # generate rdoc
|
32
|
+
$ ludy # see all ludy tasks
|
33
|
+
|
34
|
+
* ludy_ext.rb is split into many other .rb
|
35
|
+
|
36
|
+
* C++ ERB meta-programming is added.
|
37
|
+
|
38
|
+
* multi re-implementation is done. the new one is called defun.
|
39
|
+
it supports overloading(ad-hoc polymorphism), multi-method,
|
40
|
+
pattern matching, and perhaps others?
|
41
|
+
|
42
|
+
* rdoc support is added.
|
43
|
+
|
44
|
+
* http://ludy.rubyforge.org would now insist on the latest rdoc.
|
45
|
+
|
46
|
+
* Array#reverse_map, Array#body, Array#rotate, Array#combos, etc. is added.
|
47
|
+
|
48
|
+
== ludy 0.0.9, 2008.01.07
|
49
|
+
|
50
|
+
* Proc#bind added, see test/tc_bind.rb
|
51
|
+
|
52
|
+
== ludy 0.0.8, 2007.12.06
|
53
|
+
|
54
|
+
* ludy_ext:
|
17
55
|
added:
|
18
|
-
|
19
|
-
|
56
|
+
* Array#untranspose!
|
57
|
+
* Array#unzip!
|
20
58
|
|
21
59
|
changed:
|
22
|
-
|
60
|
+
* Kernel#curry support Symbol
|
23
61
|
|
24
|
-
|
62
|
+
* puzzle_generator added...
|
25
63
|
|
26
|
-
|
27
|
-
ludy 0.0.7, 2007.10.08
|
64
|
+
== ludy 0.0.7, 2007.10.08
|
28
65
|
|
29
|
-
|
66
|
+
* ludy_ext:
|
30
67
|
added:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
68
|
+
* Array#untranspose
|
69
|
+
* Array#unzip
|
70
|
+
* Array#combine!
|
71
|
+
* Object#m
|
72
|
+
* Kernel#id
|
36
73
|
|
37
|
-
|
38
|
-
ludy 0.0.6, 2007.09.15
|
74
|
+
== ludy 0.0.6, 2007.09.15
|
39
75
|
|
40
|
-
|
76
|
+
* ludy_ext:
|
41
77
|
added:
|
42
|
-
|
78
|
+
* Array#combine
|
43
79
|
|
44
80
|
moved:
|
45
|
-
|
81
|
+
* move Symbol#to_proc to Symbol#to_msg,
|
46
82
|
and take back the original Symbol#to_proc implementation.
|
47
83
|
|
48
|
-
|
84
|
+
* change the way we require
|
49
85
|
|
50
|
-
|
51
|
-
ludy 0.0.5, 2007.09.15
|
86
|
+
== ludy 0.0.5, 2007.09.15
|
52
87
|
|
53
|
-
i forgot what i'd done... (days ago)
|
54
|
-
but sure there's Symbol#to_proc and Symbol#to_msg,
|
55
|
-
also, please read unit test.
|
88
|
+
i forgot what i'd done... (days ago)
|
89
|
+
but sure there's Symbol#to_proc and Symbol#to_msg,
|
90
|
+
also, please read unit test.
|
56
91
|
|
57
|
-
|
58
|
-
ludy 0.0.4, 2007.08.12
|
92
|
+
== ludy 0.0.4, 2007.08.12
|
59
93
|
|
60
|
-
|
94
|
+
* ludy_ext:
|
61
95
|
renamed:
|
62
|
-
|
96
|
+
* Proc#curry => Proc#__curry__
|
63
97
|
|
64
98
|
added:
|
65
|
-
|
99
|
+
* Kernel#curry
|
66
100
|
|
67
|
-
strongly suggest that use Kernel#curry instead of Proc#__curry__,
|
68
|
-
see unit test for usage and changes
|
101
|
+
strongly suggest that use Kernel#curry instead of Proc#__curry__,
|
102
|
+
see unit test for usage and changes
|
69
103
|
|
70
|
-
|
71
|
-
ludy 0.0.3, 2007.08.07
|
104
|
+
== ludy 0.0.3, 2007.08.07
|
72
105
|
|
73
|
-
|
106
|
+
* ludy_ext:
|
74
107
|
added:
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
108
|
+
* Proc#curry
|
109
|
+
* Proc#compose
|
110
|
+
* Proc#chain
|
111
|
+
* Symbol#to_proc
|
112
|
+
* Array#foldl
|
113
|
+
* Array#foldr
|
114
|
+
* Array#filter
|
82
115
|
|
83
116
|
removed:
|
84
|
-
|
117
|
+
* Fixnum#collect # see tc_ludy_ext.rb#test_fixnum_collect for reason
|
85
118
|
|
86
119
|
info:
|
87
|
-
|
120
|
+
* ruby2ruby has NilClass#method_missing return nil,
|
88
121
|
so i can't just make it return blackhole
|
89
122
|
|
90
|
-
|
123
|
+
* module Curry:
|
91
124
|
see test/tc_curry.rb for usage
|
92
125
|
|
93
|
-
see unit test for usage
|
94
|
-
|
95
|
-
==============================
|
126
|
+
see unit test for usage
|
data/Manifest.txt
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
CHANGES
|
2
|
+
LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
NOTICE
|
5
|
+
README
|
6
|
+
Rakefile
|
7
|
+
TODO
|
8
|
+
bin/ludy
|
9
|
+
lib/ludy.rb
|
10
|
+
lib/ludy/all.rb
|
11
|
+
lib/ludy/array.rb
|
12
|
+
lib/ludy/array/body.rb
|
13
|
+
lib/ludy/array/combine.rb
|
14
|
+
lib/ludy/array/combos.rb
|
15
|
+
lib/ludy/array/filter.rb
|
16
|
+
lib/ludy/array/foldl.rb
|
17
|
+
lib/ludy/array/foldr.rb
|
18
|
+
lib/ludy/array/reverse_map.rb
|
19
|
+
lib/ludy/array/rotate.rb
|
20
|
+
lib/ludy/blackhole.rb
|
21
|
+
lib/ludy/class.rb
|
22
|
+
lib/ludy/class/undef_all_methods.rb
|
23
|
+
lib/ludy/deprecated/aspect.rb
|
24
|
+
lib/ludy/deprecated/callstack.rb
|
25
|
+
lib/ludy/deprecated/curry.rb
|
26
|
+
lib/ludy/deprecated/rambda.rb
|
27
|
+
lib/ludy/deprecated/this.rb
|
28
|
+
lib/ludy/deprecated/untranspose.rb
|
29
|
+
lib/ludy/deprecated/unzip.rb
|
30
|
+
lib/ludy/dices.rb
|
31
|
+
lib/ludy/kernel.rb
|
32
|
+
lib/ludy/kernel/defun.rb
|
33
|
+
lib/ludy/kernel/ergo.rb
|
34
|
+
lib/ludy/kernel/id.rb
|
35
|
+
lib/ludy/kernel/if_else.rb
|
36
|
+
lib/ludy/kernel/m.rb
|
37
|
+
lib/ludy/kernel/public_send.rb
|
38
|
+
lib/ludy/kernel/singleton_method.rb
|
39
|
+
lib/ludy/kernel/tap.rb
|
40
|
+
lib/ludy/lazy.rb
|
41
|
+
lib/ludy/message_dispatcher.rb
|
42
|
+
lib/ludy/pattern_matcher.rb
|
43
|
+
lib/ludy/proc.rb
|
44
|
+
lib/ludy/proc/bind.rb
|
45
|
+
lib/ludy/proc/chain.rb
|
46
|
+
lib/ludy/proc/compose.rb
|
47
|
+
lib/ludy/proc/curry.rb
|
48
|
+
lib/ludy/symbol.rb
|
49
|
+
lib/ludy/symbol/curry.rb
|
50
|
+
lib/ludy/symbol/to_msg.rb
|
51
|
+
lib/ludy/symbol/to_proc.rb
|
52
|
+
lib/ludy/tasks.rb
|
53
|
+
lib/ludy/tasks/erb_cpp.rb
|
54
|
+
lib/ludy/tasks/erb_cpp/attr_builder.rb
|
55
|
+
lib/ludy/tasks/erb_cpp/header_guard.rb
|
56
|
+
lib/ludy/tasks/erb_cpp/template_forward_parameters.rb
|
57
|
+
lib/ludy/test/helper.rb
|
58
|
+
lib/ludy/variable.rb
|
59
|
+
lib/ludy/y_combinator.rb
|
60
|
+
lib/ludy/z_combinator.rb
|
61
|
+
lib/puzzle_generator.rb
|
62
|
+
lib/puzzle_generator/chain.rb
|
63
|
+
lib/puzzle_generator/chained_map.rb
|
64
|
+
lib/puzzle_generator/colored_map.rb
|
65
|
+
lib/puzzle_generator/map.rb
|
66
|
+
lib/puzzle_generator/misc.rb
|
67
|
+
lib/puzzle_generator/puzzle.rb
|
68
|
+
spec/ludy_spec.rb
|
69
|
+
tasks/annotations.rake
|
70
|
+
tasks/doc.rake
|
71
|
+
tasks/gem.rake
|
72
|
+
tasks/manifest.rake
|
73
|
+
tasks/rubyforge.rake
|
74
|
+
tasks/setup.rb
|
75
|
+
tasks/spec.rake
|
76
|
+
tasks/svn.rake
|
77
|
+
tasks/test.rake
|
78
|
+
test/deprecated/callstack.rb
|
79
|
+
test/deprecated/curry.rb
|
80
|
+
test/deprecated/rambda.rb
|
81
|
+
test/deprecated/this.rb
|
82
|
+
test/deprecated/ts_ludy.rb
|
83
|
+
test/deprecated/unzip_and_untranspose.rb
|
84
|
+
test/example_puzzle.rb
|
85
|
+
test/test_all.rb
|
86
|
+
test/test_array.rb
|
87
|
+
test/test_class.rb
|
88
|
+
test/test_defun.rb
|
89
|
+
test/test_dices.rb
|
90
|
+
test/test_kernel.rb
|
91
|
+
test/test_lazy.rb
|
92
|
+
test/test_proc.rb
|
93
|
+
test/test_symbol.rb
|
94
|
+
test/test_variable.rb
|
95
|
+
test/test_y_combinator.rb
|
96
|
+
test/test_z_combinator.rb
|
data/NOTICE
CHANGED
@@ -1,26 +1,13 @@
|
|
1
|
+
= notice for other stuffs
|
1
2
|
|
2
|
-
|
3
|
+
* this project skeleton is built through Mr Bones 1.3.0:
|
4
|
+
gem install bones
|
5
|
+
http://codeforpeople.rubyforge.org/bones/
|
3
6
|
|
4
|
-
|
5
|
-
|
7
|
+
* for puzzle_generator, Ruby Facets is needed:
|
8
|
+
gem install facets
|
9
|
+
http://facets.rubyforge.org/
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Programs under lib/lib/* are not licensed under Apache License 2.0,
|
11
|
-
instead they all licensed under the license they originated.
|
12
|
-
Some of them were modified by Lin Jen-Shin (author of ludy).
|
13
|
-
See each file for more information.
|
14
|
-
|
15
|
-
*file which is modified.
|
16
|
-
|
17
|
-
== prgorams belows belong to
|
18
|
-
Christopher Cyll and licensed under MIT license ==
|
19
|
-
|
20
|
-
http://multi.rubyforge.org/
|
21
|
-
http://rubyforge.org/projects/multi/
|
22
|
-
|
23
|
-
lib/lib/amulti.rb
|
24
|
-
lib/lib/multi.rb
|
25
|
-
lib/lib/smulti.rb
|
26
|
-
==
|
11
|
+
* defun is re-implemented gem multi:
|
12
|
+
gem install multi
|
13
|
+
http://multi.rubyforge.org/
|
data/README
CHANGED
@@ -1,17 +1,180 @@
|
|
1
|
+
= ludy 0.1.0
|
2
|
+
by Lin Jen-Shin (a.k.a. godfat 真常)
|
3
|
+
strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org
|
4
|
+
http://ludy.rubyforge.org
|
5
|
+
http://godfat.org
|
1
6
|
|
2
|
-
|
3
|
-
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library.
|
4
10
|
|
5
|
-
|
11
|
+
== FEATURES:
|
6
12
|
|
7
|
-
|
8
|
-
|
13
|
+
* ludy standard library extension
|
14
|
+
* puzzle_generator
|
15
|
+
* c++ erb meta-programming
|
9
16
|
|
10
|
-
|
17
|
+
== SYNOPSIS:
|
11
18
|
|
12
|
-
|
19
|
+
please see unit test for all examples.
|
13
20
|
|
14
|
-
|
15
|
-
|
21
|
+
$ ludy test # run all ludy tests
|
22
|
+
$ ludy # see all tasks related to ludy
|
16
23
|
|
17
|
-
|
24
|
+
please don't run any task about release... contact me first
|
25
|
+
if you would like to make changes into official ludy release.
|
26
|
+
|
27
|
+
require 'ludy/all' # for all ludy things
|
28
|
+
require 'ludy/kernel' # for all kernel methods
|
29
|
+
require 'ludy/tasks' # for all ludy tasks
|
30
|
+
require 'ludy/proc/curry' # for proc's method curry
|
31
|
+
|
32
|
+
you can make any change and then $ ludy gem:install on your local machine.
|
33
|
+
below is some example extracted from unit test.
|
34
|
+
|
35
|
+
curry:
|
36
|
+
require 'ludy/proc/curry'
|
37
|
+
assert_equal 29, :+.to_proc.curry[18][11]
|
38
|
+
|
39
|
+
bind:
|
40
|
+
require 'ludy/proc/bind'
|
41
|
+
assert_equal [9,8,7], ([1,2,3].map &(lambda{|lhs, rhs| lhs-rhs}.bind 10, :_1))
|
42
|
+
|
43
|
+
defun:
|
44
|
+
require 'ludy/kernel/defun'
|
45
|
+
defun :fact, 0 do |n|
|
46
|
+
1
|
47
|
+
end
|
48
|
+
|
49
|
+
defun :fact, Integer do |n|
|
50
|
+
n * fact(n-1)
|
51
|
+
end
|
52
|
+
|
53
|
+
assert_equal 3628800, fact(10)
|
54
|
+
|
55
|
+
defun :f, Integer do |n| 1; end
|
56
|
+
defun :f, String do |n| '2'; end
|
57
|
+
defun(:f, Integer, Integer) do |n,g| 3; end
|
58
|
+
|
59
|
+
assert_equal 1, f(10)
|
60
|
+
assert_equal '2', f('')
|
61
|
+
assert_equal 3, f(1,1)
|
62
|
+
assert_raise NoMethodError do f('1', 2); end
|
63
|
+
|
64
|
+
lazy:
|
65
|
+
require 'ludy/lazy'
|
66
|
+
Y = lambda{|f|
|
67
|
+
lambda{|x| lazy{f[x[x]]} }[lambda{|x| lazy{f[x[x]]} }]
|
68
|
+
}
|
69
|
+
|
70
|
+
y_combinator:
|
71
|
+
require 'ludy/y_combinator'
|
72
|
+
fact = Y[lambda{|this|
|
73
|
+
lambda{|n| n==1 ? 1 : n*this[n-1]}
|
74
|
+
}]
|
75
|
+
assert_equal(3628800, fact[10])
|
76
|
+
|
77
|
+
|
78
|
+
ludy tasks:
|
79
|
+
|
80
|
+
|
81
|
+
header_guard:
|
82
|
+
require 'ludy/tasks/erb_cpp/header_guard'
|
83
|
+
PROJ = 'header_sample' # remember to set project name
|
84
|
+
|
85
|
+
# in utils/SimpleTest.hpp.erb
|
86
|
+
<%= header_guard %>
|
87
|
+
|
88
|
+
# run preprocessing task
|
89
|
+
$ rake erb:preprocessing
|
90
|
+
|
91
|
+
# produce:
|
92
|
+
#ifndef _HEADER_SAMPLE_UTILS_SIMPLETEST_
|
93
|
+
#define _HEADER_SAMPLE_UTILS_SIMPLETEST_
|
94
|
+
|
95
|
+
attr_builder:
|
96
|
+
require 'ludy/tasks/erb_cpp' # it would require all erb_cpp tasks.
|
97
|
+
|
98
|
+
# in MapSetting.hpp.erb
|
99
|
+
class MapSetting{
|
100
|
+
<%= accessor :int, :frequency %>
|
101
|
+
<%= accessor :double, :speed, :damage_factor %>
|
102
|
+
<%= reader :int, :width, :height, :size %>
|
103
|
+
};
|
104
|
+
|
105
|
+
# run preprocessing task
|
106
|
+
$ rake erb:preprocessing
|
107
|
+
|
108
|
+
# produce:
|
109
|
+
class MapSetting{
|
110
|
+
public:
|
111
|
+
int frequency() const{ return frequency_; }
|
112
|
+
public:
|
113
|
+
MapSetting& frequency(int const& new_frequency){ frequency_ = new_frequency; return *this; }
|
114
|
+
private:
|
115
|
+
int frequency_;
|
116
|
+
|
117
|
+
public:
|
118
|
+
double speed() const{ return speed_; }
|
119
|
+
double damage_factor() const{ return damage_factor_; }
|
120
|
+
public:
|
121
|
+
MapSetting& speed(double const& new_speed){ speed_ = new_speed; return *this; }
|
122
|
+
MapSetting& damage_factor(double const& new_damage_factor){ damage_factor_ = new_damage_factor; return *this; }
|
123
|
+
private:
|
124
|
+
double speed_, damage_factor_;
|
125
|
+
|
126
|
+
public:
|
127
|
+
int width() const{ return width_; }
|
128
|
+
int height() const{ return height_; }
|
129
|
+
int size() const{ return size_; }
|
130
|
+
private:
|
131
|
+
int width_, height_, size_;
|
132
|
+
};
|
133
|
+
|
134
|
+
template_forward_parameters:
|
135
|
+
require 'ludy/tasks/erb_cpp/template_forward_parameters'
|
136
|
+
|
137
|
+
# in test.hpp.erb
|
138
|
+
<% for_template_parameters_within(1..5, []){ |args_list| %>
|
139
|
+
template <%= template_parameters args_list %>
|
140
|
+
static element_type create(<%= forward_parameters args_list %>){
|
141
|
+
return element_type(SPool::Instance().construct(<%= arguments args_list %>), Deleter());
|
142
|
+
}
|
143
|
+
<% } %>
|
144
|
+
|
145
|
+
# run preprocessing task
|
146
|
+
$ rake erb:preprocessing
|
147
|
+
|
148
|
+
# one of the produce: (can't list all...)
|
149
|
+
template <class T0, class T1, class T2, class T3>
|
150
|
+
static element_type create(T0 const& a, T1 const& b, T2 & c, T3 const& d){
|
151
|
+
return element_type(SPool::Instance().construct(a, b, c, d), Deleter());
|
152
|
+
}
|
153
|
+
|
154
|
+
== REQUIREMENTS:
|
155
|
+
|
156
|
+
* ruby 1.8/1.9 (1.9 is prefered...)
|
157
|
+
* rake
|
158
|
+
* gem facets if you are using puzzle_generator
|
159
|
+
|
160
|
+
== INSTALL:
|
161
|
+
|
162
|
+
* sudo gem install ludy
|
163
|
+
|
164
|
+
== LICENSE:
|
165
|
+
|
166
|
+
Apache License 2.0
|
167
|
+
|
168
|
+
Copyright (c) 2008, Lin Jen-Shin (a.k.a. godfat 真常)
|
169
|
+
|
170
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
171
|
+
you may not use this file except in compliance with the License.
|
172
|
+
You may obtain a copy of the License at
|
173
|
+
|
174
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
175
|
+
|
176
|
+
Unless required by applicable law or agreed to in writing, software
|
177
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
178
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
179
|
+
See the License for the specific language governing permissions and
|
180
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
+
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
+
# are where the options are used.
|
4
|
+
|
5
|
+
load 'tasks/setup.rb'
|
6
|
+
|
7
|
+
ensure_in_path 'lib'
|
8
|
+
require 'ludy'
|
9
|
+
|
10
|
+
task :default do
|
11
|
+
sh 'rake --tasks'
|
12
|
+
end
|
13
|
+
|
14
|
+
PROJ.name = 'ludy'
|
15
|
+
PROJ.summary = 'Aims to extend Ruby standard library, providing some useful tools that\'s not existed in the standard library.'
|
16
|
+
PROJ.authors = 'Lin Jen-Shin (a.k.a. godfat 真常)'
|
17
|
+
PROJ.email = 'strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org'
|
18
|
+
PROJ.url = 'http://ludy.rubyforge.org/'
|
19
|
+
PROJ.description = paragraphs_of('README', 1).join("\n\n")
|
20
|
+
PROJ.changes = paragraphs_of('CHANGES', 0..1).join("\n\n")
|
21
|
+
PROJ.rubyforge_name = 'ludy'
|
22
|
+
|
23
|
+
PROJ.version = '0.1.0'
|
24
|
+
PROJ.exclude << '.DS_Store' << '^tmp'
|
25
|
+
PROJ.dependencies << 'rake'
|
26
|
+
|
27
|
+
PROJ.rdoc_main = 'README'
|
28
|
+
PROJ.rdoc_exclude << 'deprecated' << 'Manifest' << 'Rakefile' << 'tmp$' << '^tmp'
|
29
|
+
PROJ.rdoc_include << '\w+'
|
30
|
+
|
31
|
+
PROJ.spec_opts << '--color'
|
32
|
+
|
33
|
+
# EOF
|
data/TODO
ADDED
data/bin/ludy
ADDED
data/lib/ludy/all.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require 'ludy/symbol/to_proc'
|
3
|
+
|
4
|
+
class Array
|
5
|
+
# [1,2,3].combine [2,4,6]
|
6
|
+
# => [3,6,9]
|
7
|
+
#
|
8
|
+
# [1,2].combine [1,2], [1,2]
|
9
|
+
# => [3,6]
|
10
|
+
#
|
11
|
+
# ['a','b'].combine ['b','a']
|
12
|
+
# => ['ab','ba']
|
13
|
+
def combine *target; zip(*target).map{|i|i.inject(&:+)}; end
|
14
|
+
# in-place version of combine
|
15
|
+
def combine! *target; replace combine(*target); end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'ludy/array/reverse_map'
|
3
|
+
require 'ludy/symbol/to_proc'
|
4
|
+
require 'ludy/array/foldr'
|
5
|
+
|
6
|
+
class Array
|
7
|
+
# for each combos
|
8
|
+
# [[0,1],[2,3]].combos
|
9
|
+
# => [[0,2],[0,3],[1,2],[1,3]]
|
10
|
+
def combos
|
11
|
+
result = []
|
12
|
+
radixs = reverse_map(&:size)
|
13
|
+
inject(1){|r, i| r * i.size}.times{ |step|
|
14
|
+
result << foldr(lambda{ |i, r|
|
15
|
+
radix = radixs[r.size]
|
16
|
+
r.unshift i[step % radix]
|
17
|
+
step /= radix unless radix.nil?
|
18
|
+
r
|
19
|
+
}, [])
|
20
|
+
}
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
# rotate right with size.
|
4
|
+
# if the size is negative, rotate left.
|
5
|
+
# [1,2,3].rotate
|
6
|
+
# => [3,1,2]
|
7
|
+
#
|
8
|
+
# [1,2,3].rotate -1
|
9
|
+
# => [2,3,1]
|
10
|
+
#
|
11
|
+
# [1,2,3].rotate 2
|
12
|
+
# => [2,3,1]
|
13
|
+
def rotate size = 1
|
14
|
+
head = size > 0 ? last(size) : self[(-size)..-1]
|
15
|
+
tail = self - head
|
16
|
+
head + tail
|
17
|
+
end
|
18
|
+
# in-place version of rotate
|
19
|
+
def rotate!
|
20
|
+
replace rotate
|
21
|
+
end
|
22
|
+
end
|
data/lib/ludy/array.rb
ADDED