klam 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/HISTORY.asciidoc +7 -0
- data/PROGRESS.asciidoc +1 -8
- data/lib/klam/cons.rb +9 -0
- data/lib/klam/primitives/interop.rb +55 -0
- data/lib/klam/version.rb +1 -1
- data/spec/functional/extensions/interop_spec.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e940a2764ea2672c7456f86bcac1607254edac
|
4
|
+
data.tar.gz: 3160eb40bd0f415fe39842345dcb21a0511a4a5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1f82664a88d71b4edcb4deeb4b59d7a4c60117b542881cbcc12d9135b6f871b906f923580f899a48c3f43cc5bf703c8a8cc58a21ab79106118687380c6861c
|
7
|
+
data.tar.gz: 9bf5e5d5e40188fc7dfd7a3de28557bfc64d579f46ede0cd9991300090b3fc1cbbff8b2939a9b9805576586544bfcb7770e02ea6fb17b9dab9662da31d9f14f7
|
data/HISTORY.asciidoc
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
Relase History
|
2
2
|
==============
|
3
3
|
|
4
|
+
v0.0.4 -- January 30, 2015
|
5
|
+
--------------------------
|
6
|
+
New Features
|
7
|
+
~~~~~~~~~~~~
|
8
|
+
* `Klam::Cons` is now enumerable
|
9
|
+
* Added `rb-send-block` primitive
|
10
|
+
|
4
11
|
v0.0.3 -- January 28, 2015
|
5
12
|
--------------------------
|
6
13
|
New Features
|
data/PROGRESS.asciidoc
CHANGED
@@ -94,14 +94,7 @@ Ruby Interoperation
|
|
94
94
|
* Invoking Kl functions from Ruby
|
95
95
|
* Invoking Ruby methods from Kl
|
96
96
|
** Without blocks
|
97
|
+
** With blocks
|
97
98
|
* Dereferencing Ruby constances from Kl
|
98
99
|
* Ruby \<\-> Kl converters
|
99
100
|
** Array \<\-> List
|
100
|
-
|
101
|
-
Not Yet Implemented
|
102
|
-
-------------------
|
103
|
-
|
104
|
-
Ruby Interoperation
|
105
|
-
~~~~~~~~~~~~~~~~~~~
|
106
|
-
* Invoking Ruby methods from Kl
|
107
|
-
** With blocks
|
data/lib/klam/cons.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Klam
|
2
2
|
class Cons
|
3
|
+
include Enumerable
|
3
4
|
attr_reader :hd, :tl
|
4
5
|
|
5
6
|
def initialize(hd, tl)
|
@@ -14,5 +15,13 @@ module Klam
|
|
14
15
|
def hash
|
15
16
|
[@hd, @tl].hash
|
16
17
|
end
|
18
|
+
|
19
|
+
def each
|
20
|
+
x = self
|
21
|
+
until x == Klam::Primitives::Lists::EMPTY_LIST
|
22
|
+
yield x.hd
|
23
|
+
x = x.tl
|
24
|
+
end
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
@@ -9,6 +9,20 @@ module Klam
|
|
9
9
|
alias_method :"rb-send", :rb_send
|
10
10
|
remove_method :rb_send
|
11
11
|
|
12
|
+
def rb_send_block(obj, method_name, blk_arity, blk, *args)
|
13
|
+
if blk.instance_of?(::Symbol)
|
14
|
+
# The caller won't take advantage of the currying, but we already
|
15
|
+
# are tracking the curried form. This also allows for paritial
|
16
|
+
# application of the named function, which could be interesting.
|
17
|
+
blk = @curried_methods[blk]
|
18
|
+
else
|
19
|
+
blk = ::Klam::Primitives::Interop.uncurry(blk, blk_arity)
|
20
|
+
end
|
21
|
+
obj.send(method_name, *args, &blk)
|
22
|
+
end
|
23
|
+
alias_method :"rb-send-block", :rb_send_block
|
24
|
+
remove_method :rb_send_block
|
25
|
+
|
12
26
|
if RUBY_VERSION < '2.'
|
13
27
|
def rb_const(name)
|
14
28
|
parts = name.to_s.split('::')
|
@@ -25,6 +39,47 @@ module Klam
|
|
25
39
|
|
26
40
|
alias_method :"rb-const", :rb_const
|
27
41
|
remove_method :rb_const
|
42
|
+
|
43
|
+
class << self
|
44
|
+
def uncurry(blk, blk_arity)
|
45
|
+
case blk_arity
|
46
|
+
when 0
|
47
|
+
uncurry0(blk)
|
48
|
+
when 1
|
49
|
+
blk
|
50
|
+
when 2
|
51
|
+
uncurry2(blk)
|
52
|
+
when 3
|
53
|
+
uncurry2(blk)
|
54
|
+
when 4
|
55
|
+
uncurry2(blk)
|
56
|
+
when 5
|
57
|
+
uncurry2(blk)
|
58
|
+
else
|
59
|
+
::Kernel.raise ::Klam::Error, "unsupported arity: #{blk_arity}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def uncurry0(blk)
|
64
|
+
-> { blk.call(:NIL) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def uncurry2(blk)
|
68
|
+
-> a, b { blk.call(a).call(b) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def uncurry3(blk)
|
72
|
+
-> a, b, c { blk.call(a).call(b).call(c) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def uncurry4(blk)
|
76
|
+
-> a, b, c, d { blk.call(a).call(b).call(c).call(d) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def uncurry5(blk)
|
80
|
+
-> a, b, c, d, e { blk.call(a).call(b).call(c).call(d).call(e) }
|
81
|
+
end
|
82
|
+
end
|
28
83
|
end
|
29
84
|
end
|
30
85
|
end
|
data/lib/klam/version.rb
CHANGED
@@ -7,6 +7,29 @@ describe 'extension: Ruby interop primitives', :type => :functional do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
describe 'rb-send-block' do
|
11
|
+
it 'invokes a method on a Ruby object, passing the provided block' do
|
12
|
+
code = '(rb-send-block (cons 1 (cons 2 ())) map 1 (lambda X (* 2 X)))'
|
13
|
+
expect_kl(code).to eq([2, 4])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'supports blocks with arity greater than 1' do
|
17
|
+
eval_kl('(set vec (absvector 2))')
|
18
|
+
result = eval_kl <<-EOKL
|
19
|
+
(let V (absvector 2)
|
20
|
+
(do (rb-send-block (cons 1 (cons 2 ())) each_with_index 2
|
21
|
+
(lambda X (lambda Y (address-> V Y X))))
|
22
|
+
V))
|
23
|
+
EOKL
|
24
|
+
expect(result).to eq([1, 2])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'supports symbols as blocks' do
|
28
|
+
eval_kl('(set vec (absvector 2))')
|
29
|
+
expect_kl('(rb-send-block (cons 1 (cons 2())) map 1 str)').to eq(%w{1 2})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
10
33
|
describe 'rb-const' do
|
11
34
|
it 'looks up the named constant in the Ruby environment' do
|
12
35
|
expect_kl('(rb-const "::Math::PI")').to eq(Math::PI)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Spurrier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|