-
Notifications
You must be signed in to change notification settings - Fork 32
Description
awesome project, what would be an ideal implementation to run a lambda without having to label it into the context?, in your examples you have:
l.eval [:label, :second, [:quote, [:lambda, [:x], [:car, [:cdr, :x]]]]]
l.eval [:second, [:quote, [1, 2, 3]]]
#=> 2
this pretty much defeats the purpose of creating lambdas if we are naming them, for example to make this possible:
l.eval [[:quote, [:lambda, [:x], [:car, [:cdr, :x]]]], [:quote, [1, 2, 3]]]
#=> 2
how would you suggest implementing something like this?
one use case is to implement a map funcionality for example doing:
map: proc do |(fn, list), ctx|
evaluate(list, ctx).map do |i|
evaluate([fn, i], ctx)
end
end,
this works fine for a form like this:
[:map, :inc, [:quote, [1, 2, 3]]]
(making inc: ->((n), _) { n + 1 })
which returns
[2, 3, 4]
as expected
BUT, for a lambda, will not work:
[
:map,
[:quote, [:lambda, [:x], [:inc, :x]]],
[:quote, [1, 2, 3]]
]
since the key :lambda does not exist in the ctx, causing errors in:
evaluate ctx[fn][2], ctx.merge(Hash[*(ctx[fn][1].zip args).flatten(1)])
because fn (:lambda) does not exist in the context, but since we dont care, we can just use the "body", is a lambda after all right?
sorry if I am making the question more complex than needed, but this is why I wanted to check how would you implement lambda execution without labeling them, thanks