recur 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.rdoc +53 -0
- data/Rakefile +23 -0
- data/lib/recur/tailrec.rb +30 -0
- data/lib/recur/version.rb +3 -0
- data/lib/recur.rb +4 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Dario Rexin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= recur
|
2
|
+
|
3
|
+
* http://github.com/drexin/recur
|
4
|
+
|
5
|
+
== Description:
|
6
|
+
|
7
|
+
Adds tail recursion to every ruby interpreter.
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
sudo gem install recur
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
require 'recur'
|
16
|
+
|
17
|
+
class Foo
|
18
|
+
include TailRec
|
19
|
+
|
20
|
+
tailrec # mark this method as tail recursive
|
21
|
+
def fac x, y=1
|
22
|
+
if(x <= 0)
|
23
|
+
y
|
24
|
+
else
|
25
|
+
recur x-1, x*y # recur calls the method recursively, without building a stack
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
== License:
|
31
|
+
|
32
|
+
The MIT License
|
33
|
+
|
34
|
+
Copyright (c) 2010 Dario Rexin
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
37
|
+
a copy of this software and associated documentation files (the
|
38
|
+
"Software"), to deal in the Software without restriction, including
|
39
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
40
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
41
|
+
permit persons to whom the Software is furnished to do so, subject to
|
42
|
+
the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be
|
45
|
+
included in all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
48
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
49
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
50
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
51
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
52
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
53
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# To change this template, choose Tools | Templates
|
3
|
+
# and open the template in the editor.
|
4
|
+
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rake'
|
8
|
+
require 'rake/clean'
|
9
|
+
require 'rake/rdoctask'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
12
|
+
Rake::RDocTask.new do |rdoc|
|
13
|
+
files =['LICENSE', 'lib/**/*.rb']
|
14
|
+
rdoc.rdoc_files.add(files)
|
15
|
+
rdoc.title = "recur Docs"
|
16
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
17
|
+
rdoc.options << '--line-numbers'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run all specs"
|
21
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
22
|
+
t.rspec_opts = ["--color"]
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module TailRec
|
2
|
+
def recur *args
|
3
|
+
[:__recur__] + args
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.included base
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def tailrec
|
12
|
+
@tailrec = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_added name
|
16
|
+
if @tailrec
|
17
|
+
@tailrec = false
|
18
|
+
alias_method "__recur_#{name}__", name
|
19
|
+
define_method name do |*args|
|
20
|
+
res = recur *args
|
21
|
+
while(res.kind_of?(Array) && res.first == :__recur__) do
|
22
|
+
res = send("__recur_#{__method__}__".to_sym, *res.drop(1))
|
23
|
+
end
|
24
|
+
res
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/recur.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dario Rexin
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-06 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Tail recursion for every ruby interpreter.
|
22
|
+
email: dario.rexin@r3-tech.de
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- Rakefile
|
33
|
+
- lib/recur/tailrec.rb
|
34
|
+
- lib/recur/version.rb
|
35
|
+
- lib/recur.rb
|
36
|
+
- README.rdoc
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/drexin/recur
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: "#{s.name}-#{s.version}"
|
69
|
+
test_files: []
|
70
|
+
|