by chowells · 5y ago · 0 comments
Well, no. Know what else is a syntactic structure? Numeric and string literals. People would never have touched the language in the first place if Ruby required you to write code like
x = String("abc")
y = Integer(123)
But people bend over backwards to explain why z = { |x| x + 1 }
Is bad and shouldn't be allowed.What?
The whole block vs proc thing is an artificial distinction. It doesn't add value, it removes it.
(Yeah, I know about the difference in how they handle return. This strikes me as an incredibly ad-hoc way to address something they could have solved a lot more elegantly.)
Really? I’ve never seen anyone bend over backward to explain it as bad, mostly just that that's the way it is, there are tradeoffs either way, and its not worth changing.
> The whole block vs proc thing is an artificial distinction
Presumably, you mean lambda vs. proc. (Both of which are defined using blocks, and procs are what using & syntax in a function signature causes a passed block to be reified into.)
But, yes, all distinctions are creations of humans, especially all distinctions within human creations like, say, programming languages. So “artificial distinction” is a meaningless descriptor when we are talking about things in a programming language.
z = ->(x) { x + 1 }
z.call(y)Letting you obtain some kind of raw reference to a block that isn't a method on an object would make blocks unlike every other value in Ruby.
Ruby doesn't have functions; things that look like bare (non-method) function calls in other languages are just method calls on self.
So procs/lambdas can't be called the same as, or differently from, functions—they are the closest thing Ruby has to functions to start with.