Class: Lisp::Primitive
- Inherits:
-
Atom
show all
- Defined in:
- lib/rubylisp/primitive.rb
Instance Attribute Summary collapse
Attributes inherited from Atom
#value
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Atom
#alist?, #all?, #car, #cdr, #character?, #class?, #copy, #eq?, #evaluate, #false?, #frame?, #function?, #length, #lisp_object?, #list?, #macro?, #negative?, #number?, #object?, #pair?, #positive?, #print_string, #quoted, #set!, #string?, #symbol?, #true?, #vector?, #zero?
Constructor Details
#initialize(name, doc, special, &implementation) ⇒ Primitive
Returns a new instance of Primitive.
12
13
14
15
16
17
|
# File 'lib/rubylisp/primitive.rb', line 12
def initialize(name, doc, special, &implementation)
@name = name
@doc = doc
@special = special
@implementation = implementation
end
|
Instance Attribute Details
Returns the value of attribute doc.
5
6
7
|
# File 'lib/rubylisp/primitive.rb', line 5
def doc
@doc
end
|
Returns the value of attribute name.
5
6
7
|
# File 'lib/rubylisp/primitive.rb', line 5
def name
@name
end
|
Class Method Details
.register(name, doc = "", special = false, env = Lisp::EnvironmentFrame.global, &implementation) ⇒ Object
7
8
9
10
|
# File 'lib/rubylisp/primitive.rb', line 7
def self.register(name, doc="", special=false, env=Lisp::EnvironmentFrame.global, &implementation)
instance = self.new(name, doc, special, &implementation)
env.bind(Symbol.named(name), instance)
end
|
Instance Method Details
#apply_to(args, env) ⇒ Object
19
20
21
|
# File 'lib/rubylisp/primitive.rb', line 19
def apply_to(args, env)
@implementation.call(args, env)
end
|
#apply_to_without_evaluating(args, env) ⇒ Object
23
24
25
|
# File 'lib/rubylisp/primitive.rb', line 23
def apply_to_without_evaluating(args, env)
@implementation.call(args, env)
end
|
31
32
33
|
# File 'lib/rubylisp/primitive.rb', line 31
def primitive?
true
end
|
35
36
37
|
# File 'lib/rubylisp/primitive.rb', line 35
def special?
@special
end
|
27
28
29
|
# File 'lib/rubylisp/primitive.rb', line 27
def to_s
"<prim: #{@name}>"
end
|
39
40
41
|
# File 'lib/rubylisp/primitive.rb', line 39
def type
:primitive
end
|