Talk:Partial function application: Difference between revisions

Content added Content deleted
Line 237: Line 237:


<lang ruby>
<lang ruby>
def f(a, b, x)
def f
a * x + b
proc {|a, b, x| a * x + b}
end
end


def f2
def f2(a, b, x)
lambda {|a, b, x| a * x + b}
a * x + b
end
end


def g
def g
proc { |a| proc { |b| proc { |x| a * x + b } } }
proc {|a| proc {|b| proc {|x| a * x + b}}}
end

def main
u = f.curry
v = f.curry[7,9]
w = g[7][9]
puts [ (1..5).map {|x| u[7][9][x]} \
, (1..5).map {|x| v[x]} \
, (1..5).map {|x| w[x]} ]
end
end


main
u = f2.curry[7][9]
v = f2.curry[7,9]
w = g[7][9]
puts [ [1,2,3,4,5].map {|x| u[x]} \
, [1,2,3,4,5].map {|x| v[x]} \
, [1,2,3,4,5].map {|x| w[x]} ]
</lang>
</lang>