ludy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,8 +1,21 @@
1
1
 
2
2
  ==============================
3
- ludy 0.0.3, 2007.08
3
+ ludy 0.0.4, 2007.08.12
4
+
5
+ 1. ludy_ext:
6
+ renamed:
7
+ 1. Proc#curry => Proc#__curry__
4
8
 
5
- ludy_ext:
9
+ added:
10
+ 1. Kernel#curry
11
+
12
+ strongly suggest that use Kernel#curry instead of Proc#__curry__,
13
+ see unit test for usage and changes
14
+
15
+ ==============================
16
+ ludy 0.0.3, 2007.08.07
17
+
18
+ 1. ludy_ext:
6
19
  added:
7
20
  1. Proc#curry
8
21
  2. Proc#compose
@@ -19,8 +32,9 @@ ludy_ext:
19
32
  1. ruby2ruby has NilClass#method_missing return nil,
20
33
  so i can't just make it return blackhole
21
34
 
22
- 4. module Curry
35
+ 2. module Curry:
23
36
  see test/tc_curry.rb for usage
24
37
 
25
38
  see unit test for usage
39
+
26
40
  ==============================
data/lib/ludy/curry.rb CHANGED
@@ -32,7 +32,7 @@ module Ludy
32
32
  if args.size == method(:#{m}).arity
33
33
  self.__send__ :#{m}, *args, &block
34
34
  else
35
- method(:c#{m}).to_proc.curry *args
35
+ method(:c#{m}).to_proc.send :__curry__, *args
36
36
  end
37
37
  end
38
38
  END
@@ -42,3 +42,7 @@ module Ludy
42
42
  end
43
43
 
44
44
  end
45
+
46
+ =begin
47
+ method(:#{m}).to_proc.curry.call *args, &block
48
+ =end
data/lib/ludy/ludy_ext.rb CHANGED
@@ -63,7 +63,7 @@ end
63
63
  =end
64
64
 
65
65
  class Symbol
66
- def to_proc; lambda{|*args| args.shift.__send__ self, *args }; end
66
+ def to_proc; lambda{|*args| args.shift.__send__ self, *args}; end
67
67
  end
68
68
 
69
69
  class Array
@@ -78,9 +78,11 @@ class Array
78
78
  end
79
79
 
80
80
  class Proc
81
- def curry *pre
81
+ def __curry__ *pre
82
82
  lambda{ |*post| self[*(pre + post)] }
83
83
  end
84
+
85
+ # missing traversal of chain
84
86
  def chain *procs, &block
85
87
  procs << block if block
86
88
  lambda{ |*args|
@@ -100,3 +102,33 @@ class Proc
100
102
  }
101
103
  end
102
104
  end
105
+
106
+ module Kernel
107
+ def curry
108
+ class << self
109
+ alias_method :orig_call, :call
110
+ def call *args, &block
111
+ if self.arity == -1
112
+ begin # let's try if arguments are ready
113
+ # is there any better way to determine this?
114
+ # it's hard to detect correct arity value when
115
+ # Symbol#to_proc happened
116
+ # e.g., :message_that_you_never_know.to_proc.arity => ?
117
+ # i'd tried put hacks in Symbol#to_proc, but it's
118
+ # difficult to implement in correct way
119
+ # i would try it again in other day
120
+ self.__send__ :orig_call, *args, &block
121
+ rescue ArgumentError # oops, let's curry it
122
+ method(:call).to_proc.__send__ :__curry__, *args
123
+ end
124
+ elsif args.size == self.arity
125
+ self.__send__ :orig_call, *args, &block
126
+ else
127
+ method(:call).to_proc.__send__ :__curry__, *args
128
+ end
129
+ end
130
+ alias_method :[], :call
131
+ end
132
+ self
133
+ end
134
+ end
data/ludy.gemspec CHANGED
@@ -18,7 +18,7 @@ require 'rubygems'
18
18
 
19
19
  spec = Gem::Specification.new{|s|
20
20
  s.name = 'ludy'
21
- s.version = '0.0.3'
21
+ s.version = '0.0.4'
22
22
  s.author = 'Lin Jen-Shin(a.k.a. godfat)'
23
23
  s.email = 'strip number: 135godfat7911@246gmail.890com'
24
24
  s.homepage = 'http://ludy.rubyforge.org/'
@@ -0,0 +1 @@
1
+ local ci?
data/test/tc_curry.rb CHANGED
@@ -30,7 +30,7 @@ class TestCurry < Test::Unit::TestCase
30
30
  func1 = [1,2,3].cfoldr[:-.to_proc]
31
31
  assert_equal 2, func1[0]
32
32
 
33
- assert_equal [8,10,12], [4,5,6].cmap(&:*.to_proc.curry(2))
33
+ assert_equal [8,10,12], [4,5,6].cmap(&:*.to_proc.curry[2])
34
34
 
35
35
  result = [2,3,4,5,6]
36
36
  func2 = result.ctest_curry[2]
data/test/tc_ludy_ext.rb CHANGED
@@ -64,14 +64,15 @@ class TestLudyExt < Test::Unit::TestCase
64
64
  def test_proc_curry
65
65
  multiply = lambda{|l,r| l*r}
66
66
 
67
- double = multiply.curry 2
67
+ double = multiply.curry[2]
68
68
  assert_equal 8, double[4]
69
69
  assert_equal 6, double[3]
70
70
 
71
- xd = multiply.curry 'XD', 5
72
- assert_equal 'XDXDXDXDXD', xd.call
71
+ xd = multiply['XD', 5]
72
+ assert_equal 'XDXDXDXDXD', xd
73
73
 
74
- assert_equal 29, :+.to_proc.curry(18)[11]
74
+ assert_equal 29, :+.to_proc.curry[18][11]
75
+ assert_equal (0..4).to_a, lambda{|a,b,c,d,e|[a,b,c,d,e]}.curry[0][1][2][3][4]
75
76
  end
76
77
 
77
78
  def test_proc_chain
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ludy
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.3
7
- date: 2007-08-07 00:00:00 +08:00
6
+ version: 0.0.4
7
+ date: 2007-08-12 00:00:00 +08:00
8
8
  summary: Aims to extend Ruby standard library, providing some useful tools that's not existed in the standard library.
9
9
  require_paths:
10
10
  - lib
@@ -62,6 +62,7 @@ files:
62
62
  - ludy.gemspec
63
63
  - NOTICE
64
64
  - README
65
+ - svk-commit8wxPX.tmp
65
66
  - test
66
67
  test_files:
67
68
  - test/ts_ludy.rb