Earlier quoted context omitted.
No it does not. Ruby has first-class procs. They are not the same thing. It's a fundamental flaw of the language. It's in the Wikipedia page. https://en.wikipedia.org/wiki/First-class_function "The identifier of a regular "function" in Ruby (which is really a method) cannot be used as a value or passed. It must first be retrieved into a Method or Proc object to be used as first-class data. The syntax for calling such…
> Ruby has first-class procs. Procs are functions (at least, they are functionally equivalent to Python functions—as pure OO languages, in both Ruby and Python first-class callable entities are richer than classic functions, even when counting closures as a kind functions and not a separate thing that includes a function, because they can carry metadata besides the environment of a closure.) > It's in the Wikipedia p…
Ruby 3.2.0 is from another dimension
331–340 of 341 posts
Re: Ruby 3.2.0 is from another dimension
#332Earlier quoted context omitted.
Map/filter are considered inferior in Python to list comprehensions. res = [x**2 for x in range(10) if x != 5]
Map, filter and similar can be chained together and composed much better than comprehensions I think. I realize that it's probably not your opinion that comprehension are superior, (although it might be) but rather the general python style. I also think that map and filter style computations can be much more powerful, there are quite a few things other than just map and filter, like count, take, skip, find, flatten,…
The = binding is the chaining/composition tool of choice. This is why generator expressions are so important, relative to list and dict comprehensions. They both defer the allocation of space for intermediate values and allow the space to be bounded no matter what the input length is.
Often the “reduce” step, or even more commonly, realizing the side effects of such a generator composed of generators is a simple for loop—because that’s the most readable way to walk through it.
Re: Ruby 3.2.0 is from another dimension
#333Earlier quoted context omitted.
> its just syntax sugar for a symbol passed to a #send call This isn't the case. If you override `send` it only affects direct usage of `send`. You can't override method dispatch. You can in some other OO languages but not Ruby. Agreed otherwise. `x.foo` in Python and `x.method(:foo)` in Ruby do the exact same thing -- return a bound method object that can be called. These are both "proxies" in a sense but they're al…
You just gave away the difference right there. x.foo doesn’t “return a bound method object.” It just accesses an attribute and returns the value of that attribute. The attribute can be any Python value. If it’s a callable then it can be called with parens. There is no proxying whatsoever. In contrast x.method(:foo) does do that proxy construction that you describe… because Ruby does not have first-class functions.
Python docs, section 3.2, subsection "Callable types".
https://docs.python.org/3/reference/datamodel.html#the-stand...
x.foo returns an "instance method object", which is a "callable type". Also referred to as a "bound method", the same term that Ruby and JavaScript use.
> When an instance method object is called, the underlying function (__func__) is called, inserting the class instance (__self__) in front of the argument list. For instance, when C is a class which contains a definition for a function f(), and x is an instance of C, calling x.f(1) is equivalent to calling C.f(x, 1)... Note that the transformation from function object to instance method object happens each time the attribute is retrieved from the instance... It is also important to note that user-defined functions which are attributes of a class instance are not converted to bound methods; this only happens when the function is an attribute of the class.
This last part is why the following program has an error:
def foo(self):
print(self)
class Foo:
def __init__(self, fn):
self.foo = fn
x = Foo(foo)
x.foo()Re: Ruby 3.2.0 is from another dimension
#334Earlier quoted context omitted.
There is nothing about first-class functions that requires function call syntax to be the same as method invocation syntax. OCaml, Objective-C, and Smalltalk all have different syntax for method invocation and function calls. To make it concrete: what are you unable to do in Ruby that you're able to do in the languages that you claim do have first-class functions?
This is such an asinine argument. Function pointers and passing an environment struct in C let you do everything an OO language does. What are you unable to do in C that you can do in Ruby? You can implement a type system in Scheme if you really want to, what can you do in Haskell that you can’t do in Scheme? Just admit you are wrong, bud. It’s not as hard as you’re making it out to be. Strachey’s definition is quite…
https://en.wikipedia.org/wiki/First-class_citizen#History
In Ruby you can assign a function to a variable, pass it to a function as a parameter, return it as the result of a function, and test two function objects for equality. Ruby has first-class functions. If it didn't, you would easily be able to provide an example of a program using first-class functions that cannot be represented in Ruby.
Re: Ruby 3.2.0 is from another dimension
#335Earlier quoted context omitted.
> * Ruby was created as a personal, hobby project; Python was created while Guido worked in research institutions, and it helped Python gain recognition in academia environment As a data point, I remember interviewing for an internship in a research institution doing some work on medical images around 2002/2003 and the supervisor telling me that Python was the lingua franca in this domain (from a research and POC dev…
While I was at CERN during early 2000's, it was already being used for the build tooling and package management of HLT. Trainings for getting Python skills were a common offering.
Re: Ruby 3.2.0 is from another dimension
#336This whole thread consists of Python vs Ruby discussion. I abandoned both when .NET 5+ was released. C# on Linux makes me happiest.
how many jobs are using .net + c# on linux, and not some enterprises legacy software? where i live, Germany, is java .net and 99% are enterprises old managers with old software :(
Re: Ruby 3.2.0 is from another dimension
#337Earlier quoted context omitted.
Map/filter are considered inferior in Python to list comprehensions. res = [x**2 for x in range(10) if x != 5]
Before Ruby introduced filter_map: res = (1..10).select { |x| x != 5 }.map { |x| x ** 2 } With filter_map: res = (1..10).filter_map { |x| x ** 2 if x != 5 } In both cases, I think the Ruby solution is more readable. Python list comprehensions invert the subject (data) and the verb (action). You see what will be done before you see what the subject is. I would argue that showing the subject first allows easier code re…
[x + y for x in range(10) for y in range(5)]Re: Ruby 3.2.0 is from another dimension
#338Earlier quoted context omitted.
You just gave away the difference right there. x.foo doesn’t “return a bound method object.” It just accesses an attribute and returns the value of that attribute. The attribute can be any Python value. If it’s a callable then it can be called with parens. There is no proxying whatsoever. In contrast x.method(:foo) does do that proxy construction that you describe… because Ruby does not have first-class functions.
> x.foo doesn’t “return a bound method object.” It just accesses an attribute and returns the value of that attribute. The attribute can be any Python value. Python docs, section 3.2, subsection "Callable types". https://docs.python.org/3/reference/datamodel.html#the-stand... x.foo returns an "instance method object", which is a "callable type". Also referred to as a "bound method", the same term that Ruby and JavaSc…
me:
> If it's a callable then it can be called with parens
The docs:
> These are the types to which the function call operation (see section Calls) can be applied:
True of Python instance method objects. False of Ruby Methods and Procs. Therefore Python has first-class methods, and Ruby does not have first-class functions nor first-class methods. End of discussion.
Re: Ruby 3.2.0 is from another dimension
#339Earlier quoted context omitted.
> x.foo doesn’t “return a bound method object.” It just accesses an attribute and returns the value of that attribute. The attribute can be any Python value. Python docs, section 3.2, subsection "Callable types". https://docs.python.org/3/reference/datamodel.html#the-stand... x.foo returns an "instance method object", which is a "callable type". Also referred to as a "bound method", the same term that Ruby and JavaSc…
You are studiously missing the point and spamming irrelevant details. Yes, there's a Python "proxy" in your docs but it is syntactically transparent. Proc's proxy is not transparent. me: > If it's a callable then it can be called with parens The docs: > These are the types to which the function call operation (see section Calls) can be applied: True of Python instance method objects. False of Ruby Methods and Procs.…
Re: Ruby 3.2.0 is from another dimension
#340Earlier quoted context omitted.
I think Dlang is better than the other languages mentioned in this thread, but I know almost no one uses it. It is what it is.
I agree with your statement. The problem for Dlang is that it never reached the popularity Ruby did. Airbnb, Github, Shopify, Gitlab, old Twitter (and many, many others) are all written entirely in Ruby on Rails.