klam 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4771dd4730c8a1d51d856e142bd5cf4565623996
4
+ data.tar.gz: 4d3745f65978183e00d3ad3f1682cec74f4b5efc
5
+ SHA512:
6
+ metadata.gz: 951c7347c2c432a9f39bfd6ab8f24ee782b1a2b42e82e1dbd1c394a84d86300e99892cc0d4bae7400ae74ae77183ecb294d87f62b1605cbf66b32b2217250e08
7
+ data.tar.gz: 4acc417beb7d6f3cec557493a5f92a88d29776689c444860a91922840ec2d91b1bd4b3336cd082808ed62b8cb37db15ae2ac8267156cf9ad80d318897b017bb9
@@ -0,0 +1,18 @@
1
+ Relase History
2
+ ==============
3
+
4
+ v0.0.3 -- January 28, 2015
5
+ --------------------------
6
+ New Features
7
+ ~~~~~~~~~~~~
8
+ * Added `rb-const` and `rb-send` primitives
9
+
10
+ v0.0.2 -- January 7, 2015
11
+ -------------------------
12
+ Bug Fixes
13
+ ~~~~~~~~~
14
+ * Added bounds checking for absvectors
15
+
16
+ v0.0.1 -- January 3, 2015
17
+ -------------------------
18
+ Initial Release
@@ -92,6 +92,9 @@ Primitive Functions of Kl]:
92
92
  Ruby Interoperation
93
93
  ~~~~~~~~~~~~~~~~~~~
94
94
  * Invoking Kl functions from Ruby
95
+ * Invoking Ruby methods from Kl
96
+ ** Without blocks
97
+ * Dereferencing Ruby constances from Kl
95
98
  * Ruby \<\-> Kl converters
96
99
  ** Array \<\-> List
97
100
 
@@ -100,6 +103,5 @@ Not Yet Implemented
100
103
 
101
104
  Ruby Interoperation
102
105
  ~~~~~~~~~~~~~~~~~~~
103
- * Invoking Ruby functions from Kl
104
- * Ruby \<\-> Kl converters
105
- ** Array \<\-> Absvector
106
+ * Invoking Ruby methods from Kl
107
+ ** With blocks
@@ -11,7 +11,7 @@ module Klam
11
11
  end
12
12
 
13
13
  rator_arity = arity(rator)
14
- if rator_arity == -1 || rator_arity == rands.length
14
+ if rator_arity < 0 || rator_arity == rands.length
15
15
  converted_rands.unshift(rator)
16
16
  elsif rator_arity > rands.length
17
17
  # Partial application
@@ -101,9 +101,9 @@ module Klam
101
101
  rands_rb = rands.map { |rand| emit_ruby(rand) }
102
102
 
103
103
  if rator.kind_of?(Symbol)
104
- # Application of a function defined in the environment. At this point
105
- # partial application and currying has been taken care of, so a
106
- # simple send suffices.
104
+ # Application of a function defined in the environment. At this
105
+ # point partial application and currying have been taken care of,
106
+ # so a simple send suffices.
107
107
  render_string('__send__($1)', [rator_rb] + rands_rb)
108
108
  else
109
109
  render_string('__apply($1)', [rator_rb] + rands_rb)
@@ -22,6 +22,7 @@ module Klam
22
22
  def initialize(environment)
23
23
  @environment = environment
24
24
  @generator = Klam::VariableGenerator.new
25
+ @ruby_interop_syntax_enabled = false
25
26
  end
26
27
 
27
28
  def compile(kl)
@@ -41,6 +42,18 @@ module Klam
41
42
  apply_stages(stages, kl)
42
43
  end
43
44
 
45
+ def enable_ruby_interop_syntax!
46
+ @ruby_interop_syntax_enabled = true
47
+ end
48
+
49
+ def disable_ruby_interop_syntax!
50
+ @ruby_interop_syntax_enabled = false
51
+ end
52
+
53
+ def ruby_interop_syntax_enabled?
54
+ @ruby_interop_syntax_enabled
55
+ end
56
+
44
57
  private
45
58
 
46
59
  def apply_stages(stages, kl)
@@ -11,6 +11,7 @@ module Klam
11
11
  include ::Klam::Primitives::Streams
12
12
  include ::Klam::Primitives::Time
13
13
  include ::Klam::Primitives::Arithmetic
14
+ include ::Klam::Primitives::Interop
14
15
 
15
16
  def initialize
16
17
  # The global assignments namespace. Errors are thrown here in the
@@ -29,6 +30,8 @@ module Klam
29
30
  # methods.
30
31
  @eigenclass = class << self; self; end
31
32
 
33
+ @compiler = ::Klam::Compiler.new(self)
34
+
32
35
  # The open primitive depends on having *home-directory* assigned.
33
36
  set(:"*home-directory*", ::Dir.pwd)
34
37
  end
@@ -8,8 +8,7 @@ module Klam
8
8
  remove_method :equal
9
9
 
10
10
  def eval_kl(form)
11
- compiler = Klam::Compiler.new(self)
12
- code = compiler.compile(form)
11
+ code = @compiler.compile(form)
13
12
  instance_eval code
14
13
  end
15
14
  alias_method :"eval-kl", :eval_kl
@@ -0,0 +1,30 @@
1
+ module Klam
2
+ module Primitives
3
+ # Primitives for interoperation with the host Ruby environment.
4
+ # These are not official KLambda primitives.
5
+ module Interop
6
+ def rb_send(obj, method_name, *args)
7
+ obj.send(method_name, *args)
8
+ end
9
+ alias_method :"rb-send", :rb_send
10
+ remove_method :rb_send
11
+
12
+ if RUBY_VERSION < '2.'
13
+ def rb_const(name)
14
+ parts = name.to_s.split('::')
15
+ parts.shift if parts.first.empty?
16
+ parts.reduce(::Module) do |m, x|
17
+ m.const_get(x)
18
+ end
19
+ end
20
+ else
21
+ def rb_const(name)
22
+ ::Module.const_get(name)
23
+ end
24
+ end
25
+
26
+ alias_method :"rb-const", :rb_const
27
+ remove_method :rb_const
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Klam
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'extension: Ruby interop primitives', :type => :functional do
4
+ describe 'rb-send' do
5
+ it 'invokes a method on a Ruby object, passing the provided args' do
6
+ expect_kl('(rb-send "def" prepend "abc")').to eq('abcdef')
7
+ end
8
+ end
9
+
10
+ describe 'rb-const' do
11
+ it 'looks up the named constant in the Ruby environment' do
12
+ expect_kl('(rb-const "::Math::PI")').to eq(Math::PI)
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,102 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Greg Spurrier
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-01-07 00:00:00.000000000 Z
11
+ date: 2015-01-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '10.4'
22
- - - ! '>='
20
+ - - ">="
23
21
  - !ruby/object:Gem::Version
24
22
  version: '10.4'
25
23
  type: :development
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
- - - ~>
27
+ - - "~>"
31
28
  - !ruby/object:Gem::Version
32
29
  version: '10.4'
33
- - - ! '>='
30
+ - - ">="
34
31
  - !ruby/object:Gem::Version
35
32
  version: '10.4'
36
33
  - !ruby/object:Gem::Dependency
37
34
  name: rspec
38
35
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
- - - ~>
37
+ - - "~>"
42
38
  - !ruby/object:Gem::Version
43
39
  version: '3.1'
44
- - - ! '>='
40
+ - - ">="
45
41
  - !ruby/object:Gem::Version
46
42
  version: 3.1.0
47
43
  type: :development
48
44
  prerelease: false
49
45
  version_requirements: !ruby/object:Gem::Requirement
50
- none: false
51
46
  requirements:
52
- - - ~>
47
+ - - "~>"
53
48
  - !ruby/object:Gem::Version
54
49
  version: '3.1'
55
- - - ! '>='
50
+ - - ">="
56
51
  - !ruby/object:Gem::Version
57
52
  version: 3.1.0
58
53
  - !ruby/object:Gem::Dependency
59
54
  name: rspec-autotest
60
55
  requirement: !ruby/object:Gem::Requirement
61
- none: false
62
56
  requirements:
63
- - - ~>
57
+ - - "~>"
64
58
  - !ruby/object:Gem::Version
65
59
  version: '1.0'
66
- - - ! '>='
60
+ - - ">="
67
61
  - !ruby/object:Gem::Version
68
62
  version: 1.0.0
69
63
  type: :development
70
64
  prerelease: false
71
65
  version_requirements: !ruby/object:Gem::Requirement
72
- none: false
73
66
  requirements:
74
- - - ~>
67
+ - - "~>"
75
68
  - !ruby/object:Gem::Version
76
69
  version: '1.0'
77
- - - ! '>='
70
+ - - ">="
78
71
  - !ruby/object:Gem::Version
79
72
  version: 1.0.0
80
73
  - !ruby/object:Gem::Dependency
81
74
  name: ZenTest
82
75
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
76
  requirements:
85
- - - ~>
77
+ - - "~>"
86
78
  - !ruby/object:Gem::Version
87
79
  version: '4.11'
88
- - - ! '>='
80
+ - - ">="
89
81
  - !ruby/object:Gem::Version
90
82
  version: '4.11'
91
83
  type: :development
92
84
  prerelease: false
93
85
  version_requirements: !ruby/object:Gem::Requirement
94
- none: false
95
86
  requirements:
96
- - - ~>
87
+ - - "~>"
97
88
  - !ruby/object:Gem::Version
98
89
  version: '4.11'
99
- - - ! '>='
90
+ - - ">="
100
91
  - !ruby/object:Gem::Version
101
92
  version: '4.11'
102
93
  description: Klam is a Ruby implementation of Kl, the small Lisp on top of which the
@@ -107,10 +98,11 @@ executables: []
107
98
  extensions: []
108
99
  extra_rdoc_files: []
109
100
  files:
110
- - .gitignore
111
- - .rspec
112
- - .travis.yml
101
+ - ".gitignore"
102
+ - ".rspec"
103
+ - ".travis.yml"
113
104
  - Gemfile
105
+ - HISTORY.asciidoc
114
106
  - LICENSE.txt
115
107
  - PROGRESS.asciidoc
116
108
  - README.asciidoc
@@ -144,6 +136,7 @@ files:
144
136
  - lib/klam/primitives/boolean_operations.rb
145
137
  - lib/klam/primitives/error_handling.rb
146
138
  - lib/klam/primitives/generic_functions.rb
139
+ - lib/klam/primitives/interop.rb
147
140
  - lib/klam/primitives/lists.rb
148
141
  - lib/klam/primitives/streams.rb
149
142
  - lib/klam/primitives/strings.rb
@@ -158,6 +151,7 @@ files:
158
151
  - spec/functional/application_spec.rb
159
152
  - spec/functional/atoms_spec.rb
160
153
  - spec/functional/extensions/do_spec.rb
154
+ - spec/functional/extensions/interop_spec.rb
161
155
  - spec/functional/primitives/assignments_spec.rb
162
156
  - spec/functional/primitives/boolean_operations_spec.rb
163
157
  - spec/functional/primitives/error_handling_spec.rb
@@ -185,32 +179,32 @@ files:
185
179
  homepage: https://github.com/gregspurrier/klam
186
180
  licenses:
187
181
  - MIT
182
+ metadata: {}
188
183
  post_install_message:
189
184
  rdoc_options: []
190
185
  require_paths:
191
186
  - lib
192
187
  required_ruby_version: !ruby/object:Gem::Requirement
193
- none: false
194
188
  requirements:
195
- - - ! '>='
189
+ - - ">="
196
190
  - !ruby/object:Gem::Version
197
191
  version: 1.9.3
198
192
  required_rubygems_version: !ruby/object:Gem::Requirement
199
- none: false
200
193
  requirements:
201
- - - ! '>='
194
+ - - ">="
202
195
  - !ruby/object:Gem::Version
203
196
  version: '0'
204
197
  requirements: []
205
198
  rubyforge_project:
206
- rubygems_version: 1.8.23
199
+ rubygems_version: 2.4.5
207
200
  signing_key:
208
- specification_version: 3
201
+ specification_version: 4
209
202
  summary: Klam is a Ruby implementation of the Kl.
210
203
  test_files:
211
204
  - spec/functional/application_spec.rb
212
205
  - spec/functional/atoms_spec.rb
213
206
  - spec/functional/extensions/do_spec.rb
207
+ - spec/functional/extensions/interop_spec.rb
214
208
  - spec/functional/primitives/assignments_spec.rb
215
209
  - spec/functional/primitives/boolean_operations_spec.rb
216
210
  - spec/functional/primitives/error_handling_spec.rb