-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathski_call.rb
More file actions
38 lines (31 loc) · 708 Bytes
/
Copy pathski_call.rb
File metadata and controls
38 lines (31 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class SKICall < Struct.new(:left, :right)
def to_s
"#{left}[#{right}]"
end
def inspect
to_s
end
def combinator
left.combinator
end
def arguments
left.arguments + [right]
end
def reducible?
left.reducible? || right.reducible? || combinator.callable?(*arguments)
end
def reduce
if left.reducible?
SKICall.new(left.reduce, right)
elsif right.reducible?
SKICall.new(left, right.reduce)
else
combinator.call(*arguments)
end
end
def as_a_function_of(name)
left_function = left.as_a_function_of(name)
right_function = right.as_a_function_of(name)
SKICall.new(SKICall.new(S, left_function), right_function)
end
end