rb_delimcc 0.0.2

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.
Files changed (4) hide show
  1. data/LICENSE +25 -0
  2. data/examples/testcc.rb +56 -0
  3. data/lib/delimcc.rb +44 -0
  4. metadata +64 -0
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2010, Steffen Siering
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of Steffen Siering nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
@@ -0,0 +1,56 @@
1
+
2
+ require 'rubygems'
3
+
4
+ require 'delimcc'
5
+ include DelimCC
6
+
7
+ p 'test 1'
8
+ tmp = reset { 2 * shift { |k| k.call(k.call(k.call 4)) }} + 1
9
+ p tmp # 33
10
+
11
+ p 'test 2'
12
+ reset do
13
+ p 1
14
+ end
15
+ # => 1
16
+
17
+ p 'test 3'
18
+ reset do
19
+ p 1
20
+ shift {}
21
+ p 2
22
+ end
23
+ # => 1
24
+
25
+ p 'test 4'
26
+ reset do
27
+ p 1
28
+ shift {
29
+ p 2
30
+ }
31
+ p 3
32
+ end
33
+ # => 1, 2
34
+
35
+ p 'test 5'
36
+ reset do
37
+ p 1
38
+ shift { |k|
39
+ k.call nil
40
+ p 2
41
+ }
42
+ p 3
43
+ end
44
+ # => 1, 3, 2
45
+
46
+ p 'test 6'
47
+ reset do
48
+ p 1
49
+ shift { |k|
50
+ k.call nil
51
+ k.call nil
52
+ p 2
53
+ }
54
+ p 3
55
+ end
56
+ # => 1, 3, 3, 2
data/lib/delimcc.rb ADDED
@@ -0,0 +1,44 @@
1
+
2
+ module DelimCC
3
+ def metacc_get
4
+ tmp = Thread.current["__meta_cc__"]
5
+ if !tmp
6
+ proc { raise "not within a reset statement" }
7
+ else
8
+ tmp
9
+ end
10
+ end
11
+
12
+ def metacc_set(&meta_cont)
13
+ Thread.current["__meta_cc__"] = meta_cont
14
+ end
15
+
16
+
17
+ def abortcc(&blk)
18
+ value = blk.call
19
+ metacc_get.call value
20
+ end
21
+
22
+ def reset(&blk)
23
+ callcc do |cont|
24
+ meta_cont = metacc_get
25
+ metacc_set {|value|
26
+ metacc_set &meta_cont
27
+ cont.call value
28
+ }
29
+ abortcc &blk
30
+ end
31
+ end
32
+
33
+ def shift(&blk)
34
+ callcc do |cont|
35
+ abortcc do
36
+ blk.call proc {|value|
37
+ reset { cont.call value }
38
+ }
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_delimcc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Steffen Siering
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-24 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: steffen <dot> siering -> gmail <dot> com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/delimcc.rb
31
+ - examples/testcc.rb
32
+ - LICENSE
33
+ has_rdoc: true
34
+ homepage: http://github.com/urso/rb_delimcc
35
+ licenses:
36
+ - BDS3
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.6
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: delimited continuations for ruby
63
+ test_files: []
64
+