5 ms·
You could be me. Exasperating for someone coming from C/Python/Lisp/other lambda makes lambdas but not really because you need `call` so you need to know they'
by emmelaich 5y ago
You could be me. Exasperating for someone coming from C/Python/Lisp/other
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!
- woodruffw 5y agoThat's because Ruby is really a Smalltalk in disguise :-) 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.
- llamataboot 5y agoyou either love meta programming or you hate it, and if you love it enough, you also sometimes hate it :D
- vidarh 5y agoLambda makes Proc instances because Ruby is purely OO and every value you can get is an object. It might be nice if there were syntax that allowed you to treat an object as if it was a method, but it'd be tricky because of other Ruby syntax. > 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)
- petercooper 5y agoI find it amusing because I'm a Rubyist who has been trying to pick up some Python and I have exactly the same problem. There seems to be several ways to do everything (particularly around working with containers, lists, dicts, etc.) and not a lot of consistency as to the approach taken a lot of the time (e.g. functions versus methods on objects).
- prescriptivist 5y agoAgreed. Also a Rubyist that has worked on some fairly large Python codebases and aside from your points (builtins vs object dispatch) I've found certain forms of list comprehension and moreso, decorator abuse, to be some of the most difficult things to deal with at times and as easily on the level as any magic I've encountered in Ruby.
- dragonwriter 5y ago> lambda makes lambdas but not really because you need `call` so you need to know they're a lambda. 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.