lambda makes lambdas but not really because you need `call` so you need to know they're a lambda. Ah yeah Proc a bit like lambda but also not really. And not until version 2.blah....
Aaargh!
lambda makes lambdas but not really because you need `call` so you need to know they're a lambda. Ah yeah Proc a bit like lambda but also not really. And not until version 2.blah....
Aaargh!
But seriously: Ruby has powerful message passing, blocks, and runtime introspection that address the same niches as real lambdas in other programming languages. They're difficult features to get used to from a Python (or Lisp) background, but leaning into them reveals much of Ruby's hidden beauty.
> Ah yeah Proc a bit like lambda but also not really.
lambda/-> creates a Proc instance (with an appropriate flag set). The distinction between lambda vs (lower case) "proc" is tricky until you consider that a "proc" is effectively just a shortcut to return a block as a value. The semantics of a block reified into a Proc instance by giving it a name, and a Proc instance created with "proc" are the same.
So you could implement your own "proc":
def make_proc(&block)
block
end
(in fact the above example is from the Ruby docs)Ruby lambdas are objects and not (potentially anonymous) free functions because Ruby has objects but doesn't have free functions, anonymous or otherwise, and all calls are consistently method calls on objects.
So, it's kind of to throw this complaint on the more than one way to do things pile since this is literally an issue of Ruby has exactly one way to do this particularly thing issue.