godfat-ludy 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/CHANGES +226 -0
  2. data/LICENSE +201 -0
  3. data/NOTICE +21 -0
  4. data/README +212 -0
  5. data/Rakefile +56 -0
  6. data/TODO +21 -0
  7. data/bin/ludy +11 -0
  8. data/lib/ludy.rb +74 -0
  9. data/lib/ludy/all.rb +3 -0
  10. data/lib/ludy/array.rb +3 -0
  11. data/lib/ludy/array/body.rb +9 -0
  12. data/lib/ludy/array/choice.rb +16 -0
  13. data/lib/ludy/array/combine.rb +17 -0
  14. data/lib/ludy/array/combos.rb +35 -0
  15. data/lib/ludy/array/count.rb +9 -0
  16. data/lib/ludy/array/filter.rb +4 -0
  17. data/lib/ludy/array/foldl.rb +5 -0
  18. data/lib/ludy/array/foldr.rb +8 -0
  19. data/lib/ludy/array/head.rb +4 -0
  20. data/lib/ludy/array/map_with_index.rb +8 -0
  21. data/lib/ludy/array/pad.rb +13 -0
  22. data/lib/ludy/array/product.rb +16 -0
  23. data/lib/ludy/array/rotate.rb +21 -0
  24. data/lib/ludy/array/tail.rb +8 -0
  25. data/lib/ludy/blackhole.rb +17 -0
  26. data/lib/ludy/class.rb +3 -0
  27. data/lib/ludy/class/undef_all_methods.rb +9 -0
  28. data/lib/ludy/deprecated/aspect.rb +26 -0
  29. data/lib/ludy/deprecated/callstack.rb +24 -0
  30. data/lib/ludy/deprecated/curry.rb +29 -0
  31. data/lib/ludy/deprecated/rambda.rb +23 -0
  32. data/lib/ludy/deprecated/this.rb +14 -0
  33. data/lib/ludy/deprecated/untranspose.rb +12 -0
  34. data/lib/ludy/deprecated/unzip.rb +7 -0
  35. data/lib/ludy/dices.rb +66 -0
  36. data/lib/ludy/hash.rb +3 -0
  37. data/lib/ludy/hash/reverse_merge.rb +11 -0
  38. data/lib/ludy/helpers/check_box.rb +24 -0
  39. data/lib/ludy/kernel.rb +3 -0
  40. data/lib/ludy/kernel/deep_copy.rb +8 -0
  41. data/lib/ludy/kernel/defun.rb +10 -0
  42. data/lib/ludy/kernel/ergo.rb +16 -0
  43. data/lib/ludy/kernel/id.rb +8 -0
  44. data/lib/ludy/kernel/if_else.rb +14 -0
  45. data/lib/ludy/kernel/m.rb +5 -0
  46. data/lib/ludy/kernel/maybe.rb +9 -0
  47. data/lib/ludy/kernel/public_send.rb +15 -0
  48. data/lib/ludy/kernel/singleton_method.rb +15 -0
  49. data/lib/ludy/kernel/tap.rb +12 -0
  50. data/lib/ludy/lazy.rb +32 -0
  51. data/lib/ludy/list.rb +21 -0
  52. data/lib/ludy/message_dispatcher.rb +57 -0
  53. data/lib/ludy/namespace.rb +71 -0
  54. data/lib/ludy/paginator.rb +145 -0
  55. data/lib/ludy/pattern_matcher.rb +41 -0
  56. data/lib/ludy/proc.rb +3 -0
  57. data/lib/ludy/proc/bind.rb +21 -0
  58. data/lib/ludy/proc/chain.rb +17 -0
  59. data/lib/ludy/proc/compose.rb +9 -0
  60. data/lib/ludy/proc/curry.rb +42 -0
  61. data/lib/ludy/symbol.rb +3 -0
  62. data/lib/ludy/symbol/curry.rb +10 -0
  63. data/lib/ludy/symbol/to_msg.rb +10 -0
  64. data/lib/ludy/symbol/to_proc.rb +9 -0
  65. data/lib/ludy/tasks.rb +3 -0
  66. data/lib/ludy/tasks/common.rb +7 -0
  67. data/lib/ludy/tasks/preprocess_cpp.rb +70 -0
  68. data/lib/ludy/tasks/preprocess_cpp/attr_builder.rb +49 -0
  69. data/lib/ludy/tasks/preprocess_cpp/debug_hook.rb +36 -0
  70. data/lib/ludy/tasks/preprocess_cpp/header_guard.rb +17 -0
  71. data/lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb +45 -0
  72. data/lib/ludy/timer.rb +30 -0
  73. data/lib/ludy/variable.rb +29 -0
  74. data/lib/ludy/version.rb +9 -0
  75. data/lib/ludy/y_combinator.rb +11 -0
  76. data/lib/ludy/z_combinator.rb +11 -0
  77. data/lib/puzzle_generator.rb +53 -0
  78. data/lib/puzzle_generator/chain.rb +35 -0
  79. data/lib/puzzle_generator/chained_map.rb +113 -0
  80. data/lib/puzzle_generator/colored_map.rb +59 -0
  81. data/lib/puzzle_generator/map.rb +126 -0
  82. data/lib/puzzle_generator/misc.rb +137 -0
  83. data/lib/puzzle_generator/puzzle.rb +65 -0
  84. data/ludy.gemspec +25 -0
  85. data/spec/ludy_spec.rb +30 -0
  86. data/spec/spec_helper.rb +17 -0
  87. data/tasks/ann.rake +81 -0
  88. data/tasks/bones.rake +21 -0
  89. data/tasks/gem.rake +126 -0
  90. data/tasks/git.rake +41 -0
  91. data/tasks/manifest.rake +49 -0
  92. data/tasks/notes.rake +28 -0
  93. data/tasks/post_load.rake +39 -0
  94. data/tasks/rdoc.rake +51 -0
  95. data/tasks/rubyforge.rake +57 -0
  96. data/tasks/setup.rb +268 -0
  97. data/tasks/spec.rake +55 -0
  98. data/tasks/svn.rake +48 -0
  99. data/tasks/test.rake +38 -0
  100. data/test/deprecated/callstack.rb +18 -0
  101. data/test/deprecated/curry.rb +34 -0
  102. data/test/deprecated/rambda.rb +15 -0
  103. data/test/deprecated/this.rb +69 -0
  104. data/test/deprecated/ts_ludy.rb +26 -0
  105. data/test/deprecated/unzip_and_untranspose.rb +13 -0
  106. data/test/example_puzzle.rb +178 -0
  107. data/test/helper.rb +3 -0
  108. data/test/ludy/test_array.rb +63 -0
  109. data/test/ludy/test_class.rb +13 -0
  110. data/test/ludy/test_defun.rb +37 -0
  111. data/test/ludy/test_dices.rb +32 -0
  112. data/test/ludy/test_hash.rb +13 -0
  113. data/test/ludy/test_kernel.rb +36 -0
  114. data/test/ludy/test_lazy.rb +18 -0
  115. data/test/ludy/test_paginator.rb +84 -0
  116. data/test/ludy/test_proc.rb +58 -0
  117. data/test/ludy/test_require_all.rb +21 -0
  118. data/test/ludy/test_symbol.rb +15 -0
  119. data/test/ludy/test_variable.rb +39 -0
  120. data/test/ludy/test_y_combinator.rb +21 -0
  121. data/test/ludy/test_z_combinator.rb +20 -0
  122. data/test/multiruby.sh +2 -0
  123. metadata +252 -0
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Look in the tasks/setup.rb file for the various options that can be
3
+ # configured in this Rakefile. The .rake files in the tasks directory
4
+ # are where the options are used.
5
+ load 'tasks/setup.rb'
6
+
7
+ ensure_in_path 'lib'
8
+ require 'ludy'
9
+ require 'ludy/tasks'
10
+
11
+ CLEAN.include Dir['**/*.rbc']
12
+
13
+ task :default do
14
+ Rake.application.options.show_task_pattern = /./
15
+ Rake.application.display_tasks_and_comments
16
+ end
17
+
18
+ namespace :gem do
19
+ desc 'create ludy.gemspec'
20
+ task 'gemspec' do
21
+ puts 'rake gem:debug > ludy.gemspec'
22
+ File.open('ludy.gemspec', 'w'){|spec| spec << `rake gem:debug`.sub(/.*/, '')}
23
+ end
24
+ end
25
+
26
+ namespace :git do
27
+ desc 'push to rubyforge and github'
28
+ task 'push' do
29
+ sh 'git push rubyforge master'
30
+ puts
31
+ sh 'git push github master'
32
+ end
33
+ end
34
+
35
+ PROJ.name = 'ludy'
36
+ PROJ.authors = 'Lin Jen-Shin (a.k.a. godfat 真常)'
37
+ PROJ.email = 'strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org'
38
+ PROJ.url = 'http://ludy.rubyforge.org/'
39
+ PROJ.description = PROJ.summary = paragraphs_of('README', 'description').join("\n\n")
40
+ PROJ.changes = paragraphs_of('CHANGES', 0..1).join("\n\n")
41
+ PROJ.rubyforge.name = 'ludy'
42
+ PROJ.version = paragraphs_of('README', 0).first.split("\n").first[7..-1]
43
+
44
+ PROJ.gem.executables = 'bin/ludy'
45
+ PROJ.gem.files = []
46
+ Dir.glob('**/*'){ |file| PROJ.gem.files << file if file !~ /^pkg|^tmp|^doc/ }
47
+
48
+ PROJ.rdoc.main = 'README'
49
+ PROJ.rdoc.exclude << 'Manifest' << 'Rakefile' << 'tmp$' << '^tmp'
50
+ PROJ.rdoc.include << '\w+'
51
+ PROJ.rdoc.opts << '--diagram' if !WIN32 and `which dot` =~ %r/\/dot/
52
+ PROJ.rdoc.opts << '--charset=utf-8' << '--inline-source' << '--line-numbers' << '--promiscuous'
53
+
54
+ PROJ.spec.opts << '--color'
55
+
56
+ # EOF
data/TODO ADDED
@@ -0,0 +1,21 @@
1
+ = ludy todo list
2
+
3
+ * chain travel
4
+ * method hook
5
+ * more rdoc
6
+
7
+ * list comprehension List[lambda{|x,y|[x,y*2]}, (0..1), (2..3), lambda{|x,y|x!=y}]
8
+ * better namespace
9
+ * extract Array's methods to Enumerable
10
+
11
+ * table showing, with pad.
12
+ * rails multiple layout
13
+
14
+ * better manifest creating
15
+
16
+ * better bin/ludy support
17
+
18
+ * refactor tasks...
19
+ * make switch between template engine easier
20
+
21
+ * <del>rails paginator, change model class, change opts...</del>
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), '..', 'lib', 'ludy'))
5
+
6
+ # Put your code here
7
+
8
+ Dir.chdir Ludy.path
9
+ puts `rake #{ARGV.join(' ')}`
10
+
11
+ # EOF
@@ -0,0 +1,74 @@
1
+ # $Id$
2
+
3
+ # Equivalent to a header guard in C/C++
4
+ # Used to prevent the class/module from being loaded more than once
5
+ unless defined? LudyHeaderGuard
6
+
7
+ module LudyHeaderGuard # :nodoc:
8
+ end
9
+
10
+ module Ludy
11
+
12
+ # :stopdoc:
13
+ VERSION = '0.1.13'
14
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
15
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
16
+ $LOAD_PATH << LIBPATH
17
+ # :startdoc:
18
+
19
+ # Returns the version string for the library.
20
+ #
21
+ def self.version
22
+ VERSION
23
+ end
24
+
25
+ # Returns the library path for the module. If any arguments are given,
26
+ # they will be joined to the end of the libray path using
27
+ # <tt>File.join</tt>.
28
+ #
29
+ def self.libpath( *args )
30
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
31
+ end
32
+
33
+ # Returns the lpath for the module. If any arguments are given,
34
+ # they will be joined to the end of the path using
35
+ # <tt>File.join</tt>.
36
+ #
37
+ def self.path( *args )
38
+ args.empty? ? PATH : ::File.join(PATH, *args)
39
+ end
40
+
41
+ # Utility method used to rquire all files ending in .rb that lie in the
42
+ # directory below this file that has the same name as the filename passed
43
+ # in. Optionally, a specific _directory_ name can be passed in such that
44
+ # the _filename_ does not have to be equivalent to the directory.
45
+ #
46
+ def self.require_all_libs_relative_to( fname, dir = nil )
47
+ dir ||= ::File.basename(fname, '.*')
48
+ search_me = ::File.expand_path(
49
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
50
+
51
+ Dir.glob(search_me).sort.each {|rb| require rb}
52
+ end
53
+
54
+ # require all files in the dir, only work for ludy.
55
+ # i.e., Ludy.require_all_in 'proc' => require 'ludy/proc/*.rb'
56
+ def self.require_all_in dir
57
+ require 'rubygems'
58
+ require 'rake'
59
+ Dir.glob("#{LIBPATH}ludy/#{dir}/*.rb").each{ |i|
60
+ require(if dir == '.'
61
+ i.pathmap('ludy/%n')
62
+ else
63
+ i.pathmap("ludy/#{dir}/%n")
64
+ end)
65
+ }
66
+ end
67
+
68
+ end # module Ludy
69
+
70
+ # Ludy.require_all_libs_relative_to __FILE__
71
+
72
+ end # unless defined?
73
+
74
+ # EOF
@@ -0,0 +1,3 @@
1
+
2
+ require 'ludy'
3
+ Ludy.require_all_in '.'
@@ -0,0 +1,3 @@
1
+
2
+ require 'ludy'
3
+ Ludy.require_all_in 'array'
@@ -0,0 +1,9 @@
1
+
2
+ class Array
3
+ # strip the last element
4
+ # [1,2,3].body
5
+ # => [1,2]
6
+ def body
7
+ self[0..-2]
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+
2
+ require 'ludy/version'
3
+
4
+ class Array
5
+ # it would be defined if RUBY_VERSION < '1.9.0', see rdoc in ruby 1.9
6
+ def choice
7
+ self[rand(size)]
8
+ end if Ludy::ruby_before '1.9.0'
9
+ # the choosen element would be deleted. return the choosen
10
+ def choice!
11
+ i = rand size
12
+ r = self[i]
13
+ self.delete_at i
14
+ r
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+
2
+ require 'ludy/symbol/to_proc'
3
+
4
+ class Array
5
+ # example:
6
+ # [1,2,3].combine [2,4,6]
7
+ # => [3,6,9]
8
+ #
9
+ # [1,2].combine [1,2], [1,2]
10
+ # => [3,6]
11
+ #
12
+ # ['a','b'].combine ['b','a']
13
+ # => ['ab','ba']
14
+ def combine *target; zip(*target).map{|i|i.inject(&:+)}; end
15
+ # inplace version of combine
16
+ def combine! *target; replace combine(*target); end
17
+ end
@@ -0,0 +1,35 @@
1
+
2
+ require 'ludy/version'
3
+
4
+ class Array
5
+ if Ludy::ruby_before '1.9.0'
6
+ require 'ludy/array/foldr'
7
+ require 'ludy/symbol/to_proc' if Ludy::ruby_before '1.9.0'
8
+ # for each combos
9
+ # [[0,1],[2,3]].combos
10
+ # => [[0,2],[0,3],[1,2],[1,3]]
11
+ def combos
12
+ result = []
13
+ radixs = reverse.map(&:size)
14
+ inject(1){|r, i| r * i.size}.times{ |step|
15
+ result << foldr(lambda{ |i, r|
16
+ radix = radixs[r.size]
17
+ r.unshift i[step % radix]
18
+ step /= radix unless radix.nil?
19
+ r
20
+ }, [])
21
+ }
22
+ result
23
+ end
24
+ else
25
+ require 'ludy/array/tail'
26
+ # for each combos
27
+ # [[0,1],[2,3]].combos
28
+ # => [[0,2],[0,3],[1,2],[1,3]]
29
+ # simply:
30
+ # array.first.product *array.tail
31
+ def combos
32
+ first.product(*tail)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+
2
+ require 'ludy/version'
3
+
4
+ class Array
5
+ # it would be defined if RUBY_VERSION < '1.9.0', see rdoc in ruby 1.9
6
+ def count t
7
+ inject(0){|r,i| i==t ? r+=1 : r}
8
+ end
9
+ end if Ludy::ruby_before '1.9.0'
@@ -0,0 +1,4 @@
1
+
2
+ class Array
3
+ alias_method :filter, :select
4
+ end
@@ -0,0 +1,5 @@
1
+
2
+ class Array
3
+ # fold from left to right (it just like inject)
4
+ def foldl func, init; inject init, &func; end
5
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Array
3
+ # fold from right to left
4
+ def foldr func, init
5
+ reverse_each{ |i| init = func[i, init] }
6
+ init
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class Array
3
+ alias_method :head, :first
4
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Array
3
+ # just like each_with_index
4
+ def map_with_index
5
+ i = -1
6
+ map{ |e| i+=1; yield e, i; }
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+
2
+ class Array
3
+ # ensure the size is at least n, pad with n, default nil
4
+ def pad n, t = nil
5
+ return self if n <= size
6
+ self + [t]*(n-size)
7
+ end
8
+ # inplace version of pad
9
+ def pad! n, t = nil
10
+ return self if n <= size
11
+ concat([t]*(n-size))
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+
2
+ require 'ludy/version'
3
+
4
+ if Ludy::ruby_before '1.9.0'
5
+ begin
6
+ require 'facets/enumerable/combos'
7
+ rescue LoadError
8
+ require 'ludy/array/combos'
9
+ end
10
+ class Array
11
+ # it would be defined if RUBY_VERSION < '1.9.0', see rdoc in ruby 1.9
12
+ def product *args
13
+ args.unshift(self).combos
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
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 n = 1
14
+ return self if empty? or n == 0
15
+ self[-n..-1] + self[0...-n]
16
+ end
17
+ # inplace version of rotate
18
+ def rotate!
19
+ replace rotate
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class Array
3
+ # simply call
4
+ # array[1..-1]
5
+ def tail
6
+ self[1..-1]
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+
2
+ require 'ludy/class/undef_all_methods'
3
+ require 'singleton'
4
+
5
+ module Ludy
6
+ # a blackhole would eat any message it received.
7
+ class Blackhole
8
+ undef_all_methods
9
+ include Singleton
10
+ def method_missing msg, *args, &block
11
+ self
12
+ end
13
+ def nil?
14
+ true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+
2
+ require 'ludy'
3
+ Ludy.require_all_in 'class'
@@ -0,0 +1,9 @@
1
+
2
+ class Class
3
+ # undefine all instance methods, used for delegation class
4
+ def undef_all_methods
5
+ instance_methods.each{ |m|
6
+ undef_method m unless (m =~ /^__/ || m.to_sym == :object_id || m.to_sym == :public_send )
7
+ }
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module Ludy
3
+
4
+
5
+ end
6
+
7
+ module Kernel
8
+ def cut target, &block
9
+ (class << target; self; end)
10
+ end
11
+ end
12
+
13
+ class Name
14
+ def name
15
+ 'name'
16
+ end
17
+ end
18
+
19
+ cut Name do
20
+ def name
21
+ "<#{super}>"
22
+ end
23
+ def g
24
+ '??'
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+
2
+ module Ludy
3
+ # TRACE_EVENT = 0
4
+ # TRACE_FILE = 1
5
+ # TRACE_LINE = 2
6
+ # TRACE_MSG = 3
7
+ # TRACE_BINDING = 4
8
+ # TRACE_CLASS = 5
9
+
10
+ def callstack levels = -1
11
+ st = Thread.current[:callstack]
12
+ if levels then st && st[levels - 2] else st end
13
+ end
14
+ module_function :callstack
15
+ end # of Ludy
16
+
17
+ set_trace_func lambda{ |*args|
18
+ case args[0]
19
+ when /call$/
20
+ (Thread.current[:callstack] ||= []).push args
21
+ when /return$/
22
+ (Thread.current[:callstack] ||= []).pop
23
+ end
24
+ }