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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e43b771e458951f6724a4ea368359b651af68aa
4
- data.tar.gz: 32043fab0730d6414558a3fed26e3063b0a16943
3
+ metadata.gz: bb83eafd57c37cbb7ef8e45248b31ec8aed7b124
4
+ data.tar.gz: e9660c1b0bf3b359b18d0ff10af7b21790ef32cd
5
5
  SHA512:
6
- metadata.gz: 13a455aa9220f5f7850a5a2f9e6c54f2544cc6b5f946d3529cc056a0d4b589ca856f426da3604f22e1c986ff7535b1b96690a08fd4d30f25883eed3c2151a23a
7
- data.tar.gz: c5fd927f7d655390e1dc5d9a415f1ccb04fb1ed775e59d8b60aa5b16da3eb19325aeb99bc74aff20ef76321736c7c6866fbb77593deefad49bcee2a404b7499d
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
- puts parser.parse(line).evaluate(Lisp::EnvironmentFrame.global).to_s
12
+ begin
13
+ puts parser.parse_and_eval(line)
14
+ rescue Exception => ex
15
+ puts "ERROR: #{ex}"
16
+ end
13
17
  end
14
18
 
@@ -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
- @required_argument_count = 0
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
- @required_argument_count += 1
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 #{@required_argument_count} parameters, received #{parameters.length}." if parameters.length < @required_argument_count
38
+ raise "#{@name} expected at least #{@arity} parameters, received #{parameters.length}." if parameters.length < @arity
39
39
  else
40
- raise "#{@name} expected #{@required_argument_count} parameters, received #{parameters.length}." unless parameters.length == @required_argument_count
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)
@@ -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.0
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-21 00:00:00.000000000 Z
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: http://rubygems.org/gems/rubylisp
58
+ homepage: https://bitbucket.org/dastels/rubylisp
59
59
  licenses:
60
60
  - MIT
61
61
  metadata: {}