pure 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + "/common"
2
+
3
+ LAZY_SPEC_COUNTER = Struct.new(:value).new
4
+
5
+ describe "laziness" do
6
+ it "should be lazy" do
7
+ LAZY_SPEC_COUNTER.value = 0
8
+
9
+ mod = pure do
10
+ def square(n)
11
+ n*n
12
+ end
13
+
14
+ def n
15
+ LAZY_SPEC_COUNTER.value += 1
16
+ 3
17
+ end
18
+ end.compute :square, :threads => 4
19
+
20
+ LAZY_SPEC_COUNTER.value.should == 1
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + "/common"
2
+
3
+ describe "parse engine" do
4
+ it "should be queryable" do
5
+ pure do
6
+ def f
7
+ end
8
+ end
9
+ lambda {
10
+ Pure.parser
11
+ }.should_not raise_error
12
+ end
13
+
14
+ it "should be swappable" do
15
+ previous = Pure.parser
16
+ begin
17
+ Pure.parser = "ruby_parser"
18
+ Pure.parser.should == "ruby_parser"
19
+ ensure
20
+ Pure.parser = previous
21
+ end
22
+ end
23
+
24
+ it "should have a default unless Method#parameters available" do
25
+ Pure.parser = nil
26
+ pure do
27
+ def f
28
+ end
29
+ end.compute(:f, 3)
30
+ if Method.instance_methods.include?(:parameters)
31
+ Pure.parser.should == nil
32
+ else
33
+ Pure.parser.should_not == nil
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ require 'pathname'
2
+ require 'tempfile'
3
+
4
+ here = Pathname(__FILE__).dirname
5
+ require here + "common"
6
+ root = here + ".."
7
+ readme = root + "README.rdoc"
8
+ lib = root + "lib"
9
+
10
+ describe readme do
11
+ $LOAD_PATH.unshift root + "devel"
12
+ require "jumpstart/ruby"
13
+ ["Synopsis"].each { |section|
14
+ describe section do
15
+ it "should run as claimed" do
16
+ contents = readme.read
17
+
18
+ code = %{
19
+ $LOAD_PATH.unshift "#{lib.expand_path}"
20
+ require 'rubygems'
21
+ } + contents.match(%r!== #{section}.*?\n(.*?)^\S!m)[1]
22
+
23
+ expected = code.scan(%r!\# => (.*?)\n!).flatten.join("\n")
24
+
25
+ Tempfile.open("pure-readme") { |file|
26
+ file.puts code
27
+ file.close
28
+ result = `"#{Jumpstart::Ruby::EXECUTABLE}" "#{file.path}"`
29
+ raise unless $?.exitstatus
30
+ result.chomp.should == expected
31
+ }
32
+ end
33
+ end
34
+ }
35
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + "/common"
2
+
3
+ describe "splat (*) argument in pure function" do
4
+ describe "with `def'" do
5
+ it "should raise error" do
6
+ lambda {
7
+ pure do
8
+ def f(a, b, *stuff)
9
+ stuff
10
+ end
11
+ end
12
+ }.should raise_error(Pure::PurePrivate::SplatError)
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + "/common"
2
+
3
+ describe "subsequent `def' definitions" do
4
+ it "should be accepted" do
5
+ mod = pure do
6
+ def f
7
+ 33
8
+ end
9
+ end
10
+
11
+ mod.compute(:f, 4).should == 33
12
+
13
+ mod.module_eval do
14
+ def g
15
+ 44
16
+ end
17
+ end
18
+
19
+ mod.compute(:g, 4).should == 44
20
+ end
21
+ end
22
+
23
+ describe "subsequent `fun' definitions" do
24
+ it "should be accepted" do
25
+ mod = pure do
26
+ fun :f do
27
+ 33
28
+ end
29
+ end
30
+
31
+ mod.compute(:f, 4).should == 33
32
+
33
+ mod.module_eval do
34
+ fun :g do
35
+ 44
36
+ end
37
+ end
38
+
39
+ mod.compute(:g, 4).should == 44
40
+ end
41
+ end
42
+
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + "/common"
2
+ require 'benchmark'
3
+
4
+ describe "timed example" do
5
+ before :all do
6
+ @mod = pure do
7
+ def root(a, b)
8
+ end
9
+
10
+ def a
11
+ sleep(0.25)
12
+ end
13
+
14
+ def b
15
+ sleep(0.25)
16
+ end
17
+ end
18
+ @compute = lambda { |n|
19
+ @mod.compute :root, n
20
+ }
21
+ end
22
+
23
+ it "should run with 1 thread" do
24
+ Benchmark.measure { @compute.call(1) }.real.should be_close(0.5, 0.1)
25
+ end
26
+
27
+ it "should be 2x faster with 2 threads" do
28
+ Benchmark.measure { @compute.call(2) }.real.should be_close(0.25, 0.05)
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James M. Lawrence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-21 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: comp_tree
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.7.6
24
+ version:
25
+ description: +Pure+ is an importation of the pure functional paradigm into Ruby.
26
+ email:
27
+ - quixoticsycophant@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.rdoc
34
+ files:
35
+ - CHANGES.rdoc
36
+ - MANIFEST
37
+ - README.rdoc
38
+ - Rakefile
39
+ - devel/jumpstart.rb
40
+ - devel/jumpstart/lazy_attribute.rb
41
+ - devel/jumpstart/ruby.rb
42
+ - devel/jumpstart/simple_installer.rb
43
+ - install.rb
44
+ - lib/pure.rb
45
+ - lib/pure/pure_private/creator.rb
46
+ - lib/pure/pure_private/driver.rb
47
+ - lib/pure/pure_private/error.rb
48
+ - lib/pure/pure_private/extractor.rb
49
+ - lib/pure/pure_private/extractor_ripper.rb
50
+ - lib/pure/pure_private/extractor_ruby_parser.rb
51
+ - lib/pure/pure_private/function_database.rb
52
+ - lib/pure/pure_private/singleton_features.rb
53
+ - lib/pure/pure_private/util.rb
54
+ - spec/basic_spec.rb
55
+ - spec/combine_spec.rb
56
+ - spec/common.rb
57
+ - spec/error_spec.rb
58
+ - spec/fun_spec.rb
59
+ - spec/lazy_spec.rb
60
+ - spec/parser_spec.rb
61
+ - spec/readme_spec.rb
62
+ - spec/splat_spec.rb
63
+ - spec/subseqent_spec.rb
64
+ - spec/timed_spec.rb
65
+ has_rdoc: true
66
+ homepage: http://purefunctional.rubyforge.org
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --main
70
+ - README.rdoc
71
+ - --title
72
+ - "pure: Language-level support for automatic parallelism and lazy evaluation."
73
+ - --exclude
74
+ - CHANGES.rdoc
75
+ - --exclude
76
+ - MANIFEST
77
+ - --exclude
78
+ - README.rdoc
79
+ - --exclude
80
+ - Rakefile
81
+ - --exclude
82
+ - devel/jumpstart.rb
83
+ - --exclude
84
+ - devel/jumpstart/lazy_attribute.rb
85
+ - --exclude
86
+ - devel/jumpstart/ruby.rb
87
+ - --exclude
88
+ - devel/jumpstart/simple_installer.rb
89
+ - --exclude
90
+ - install.rb
91
+ - --exclude
92
+ - spec/basic_spec.rb
93
+ - --exclude
94
+ - spec/combine_spec.rb
95
+ - --exclude
96
+ - spec/common.rb
97
+ - --exclude
98
+ - spec/error_spec.rb
99
+ - --exclude
100
+ - spec/fun_spec.rb
101
+ - --exclude
102
+ - spec/lazy_spec.rb
103
+ - --exclude
104
+ - spec/parser_spec.rb
105
+ - --exclude
106
+ - spec/readme_spec.rb
107
+ - --exclude
108
+ - spec/splat_spec.rb
109
+ - --exclude
110
+ - spec/subseqent_spec.rb
111
+ - --exclude
112
+ - spec/timed_spec.rb
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: "0"
120
+ version:
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: "0"
126
+ version:
127
+ requirements: []
128
+
129
+ rubyforge_project: purefunctional
130
+ rubygems_version: 1.3.1
131
+ signing_key:
132
+ specification_version: 2
133
+ summary: Language-level support for automatic parallelism and lazy evaluation.
134
+ test_files: []
135
+