Class: Calculi::Function
- Inherits:
-
Object
show all
- Includes:
- Base
- Defined in:
- lib/calculi/function.rb
Overview
Constant Summary
Constants included
from Utility
Utility::NON_IVAR, Utility::NULL
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Attributes
#configure, #initialize
#option_set
Methods included from Utility
#at_prefixed, #callable?, #constantly, #eval_or_value, #instance_variable_compute, #procable?, #set_attribute
Instance Attribute Details
#dependency_names ⇒ Object
91
92
93
|
# File 'lib/calculi/function.rb', line 91
def dependency_names
@dependency_names ||= Set.new
end
|
#function_set ⇒ Object
Returns the value of attribute function_set.
97
98
99
|
# File 'lib/calculi/function.rb', line 97
def function_set
@function_set
end
|
#key ⇒ Object
Returns the value of attribute key.
100
101
102
|
# File 'lib/calculi/function.rb', line 100
def key
@key
end
|
#memoize ⇒ Boolean
7
|
# File 'lib/calculi/function.rb', line 7
calculi_bool :memoize
|
#recursive ⇒ Boolean
TODO:
implement trampoline or some pseudostack to recur?
13
|
# File 'lib/calculi/function.rb', line 13
calculi_bool :recursive
|
#target ⇒ Class
104
|
# File 'lib/calculi/function.rb', line 104
delegate :target, to: :function_set
|
Instance Method Details
#body(&body_proc) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/calculi/function.rb', line 49
def body(&body_proc)
if block_given?
@body = body_proc
end
@body
end
|
#call(context, *args) ⇒ Object
20
21
22
23
24
|
# File 'lib/calculi/function.rb', line 20
def call(context, *args)
fn_caller = Calculi::Caller.new(self, context)
context.instance_exec(target, fn_caller, args, &body)
end
|
#eql?(other) ⇒ Boolean
26
27
28
|
# File 'lib/calculi/function.rb', line 26
def eql?(other)
other.is_a?(Calculi::Function) && other.hash == hash
end
|
#hash ⇒ Object
30
31
32
|
# File 'lib/calculi/function.rb', line 30
def hash
[function_set.hash, key.hash].hash
end
|
#inspect ⇒ Object
Also known as:
to_s
34
35
36
|
# File 'lib/calculi/function.rb', line 34
def inspect
"Calculi::Function(:#{key}, :dependencies => #{inspect_dependency_names})"
end
|
#inspect_dependency_names ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/calculi/function.rb', line 38
def inspect_dependency_names
mapped = dependency_names.map do |name|
":#{name}"
end.join(', ')
"[#{mapped}]"
end
|
#name(&name_proc) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/calculi/function.rb', line 57
def name(&name_proc)
if block_given?
@name = name_proc
end
@name
end
|
#realized_body ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/calculi/function.rb', line 74
def realized_body
instance_variable_compute 'realized_body' do
__fn = self
->(*args) { __fn.call(self, *args) }
end
end
|
#realized_name ⇒ Object
70
71
72
|
# File 'lib/calculi/function.rb', line 70
def realized_name
@realized_name ||= target.instance_eval(&@name)
end
|
#requires(*deps) ⇒ Object
65
66
67
|
# File 'lib/calculi/function.rb', line 65
def requires(*deps)
dependency_names.merge deps.flatten.map(&:to_s)
end
|