rubylisp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rubylisp +5 -1
- data/lib/rubylisp/function.rb +5 -5
- data/lib/rubylisp/parser.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb83eafd57c37cbb7ef8e45248b31ec8aed7b124
|
4
|
+
data.tar.gz: e9660c1b0bf3b359b18d0ff10af7b21790ef32cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6023b05ca6246ea48b013ff1449063925b77d164aa938682d4601a8a7197d00260a582e9bc3d4acc71b14e9517b70259bc09d0557641d1c1722c9cd4050d85cb
|
7
|
+
data.tar.gz: 8a4dcc8eec4c6c0bf60c17a15ee195aa08ca8a4a18fd0080622a0cf0676d56b64be890efd9eff4e781bce4d576f445112b718008ef8a6bd875bba1d43cb23afb
|
data/bin/rubylisp
CHANGED
@@ -9,6 +9,10 @@ puts 'RubyLisp REPL'
|
|
9
9
|
parser = Lisp::Parser.new
|
10
10
|
|
11
11
|
while line = Readline.readline('> ', true)
|
12
|
-
|
12
|
+
begin
|
13
|
+
puts parser.parse_and_eval(line)
|
14
|
+
rescue Exception => ex
|
15
|
+
puts "ERROR: #{ex}"
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
data/lib/rubylisp/function.rb
CHANGED
@@ -2,18 +2,18 @@ module Lisp
|
|
2
2
|
|
3
3
|
class Function < Atom
|
4
4
|
|
5
|
-
attr_reader :doc
|
5
|
+
attr_reader :doc, :arity
|
6
6
|
|
7
7
|
def compute_required_argument_count(args)
|
8
8
|
a = args
|
9
|
-
@
|
9
|
+
@arity = 0
|
10
10
|
@var_args = false
|
11
11
|
while a
|
12
12
|
if a.symbol?
|
13
13
|
@var_args = true
|
14
14
|
return
|
15
15
|
else
|
16
|
-
@
|
16
|
+
@arity += 1
|
17
17
|
end
|
18
18
|
a = a.cdr
|
19
19
|
end
|
@@ -35,9 +35,9 @@ module Lisp
|
|
35
35
|
|
36
36
|
def internal_apply_to(parameters, env, should_eval)
|
37
37
|
if @var_args
|
38
|
-
raise "#{@name} expected at least #{@
|
38
|
+
raise "#{@name} expected at least #{@arity} parameters, received #{parameters.length}." if parameters.length < @arity
|
39
39
|
else
|
40
|
-
raise "#{@name} expected #{@
|
40
|
+
raise "#{@name} expected #{@arity} parameters, received #{parameters.length}." unless parameters.length == @arity
|
41
41
|
end
|
42
42
|
|
43
43
|
local_env = EnvironmentFrame.extending(@env, env.frame)
|
data/lib/rubylisp/parser.rb
CHANGED
@@ -167,6 +167,11 @@ module Lisp
|
|
167
167
|
return sexpr
|
168
168
|
end
|
169
169
|
|
170
|
+
def parse_and_eval(src, env=Lisp::EnvironmentFrame.global)
|
171
|
+
sexpr = self.parse(src)
|
172
|
+
return sexpr.evaluate(env)
|
173
|
+
end
|
174
|
+
|
170
175
|
def parse_and_eval_all(src, env=Lisp::EnvironmentFrame.global)
|
171
176
|
tokenizer = Tokenizer.new(src)
|
172
177
|
tokenizer.init
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubylisp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Astels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06
|
11
|
+
date: 2014-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An embeddable Lisp as an extension language for Ruby
|
14
14
|
email: dastels@icloud.com
|
@@ -55,7 +55,7 @@ files:
|
|
55
55
|
- lib/rubylisp/tokenizer.rb
|
56
56
|
- lib/rubylisp/type_checks.rb
|
57
57
|
- lib/rubylisp/vector.rb
|
58
|
-
homepage:
|
58
|
+
homepage: https://bitbucket.org/dastels/rubylisp
|
59
59
|
licenses:
|
60
60
|
- MIT
|
61
61
|
metadata: {}
|