3 ms·
Thanks for mentioning sets - this is another thing that I would like to be built-in in Ruby. But "list(set(mylist))" seems like kind of a hack. > you can impor
by thehotelambush 15y ago
Thanks for mentioning sets - this is another thing that I would like to be built-in in Ruby. But "list(set(mylist))" seems like kind of a hack.
> you can import the rational class via a simple from fractions import Fraction
Sure, you can write a library for anything and by now Python has libraries for most everything. But it still makes a difference to have things in the core language, plus a nice syntax for them.
> why would you want to use lambdas if you have generator expressions?
This is a case of making up for odd semantic choices with special syntax, which then becomes an unnecessarily fixed-in-stone part of the language. Range objects in Ruby are actually like slice objects in Python. But Ruby separates the syntax for ranges from the get-item method, since there are plenty of other places where you would want to use ranges (then you can iterate and map over them, etc.).
Ruby uses blocks to implement things like an each method that fulfills the same function as Python's for statement. (Ruby has a for statement but it is hardly ever used.) In Ruby your example would be
countries.split(',').map &:strip
which is obviously more concise and no less readable. Compare with
countries.split(',').each &:foo
where foo is some side-effectful method.
IMO such a small change in behavior should result in a similarly small change in how the program is written.
- nathan_f77 15y agoRuby does have sets: require 'set' Set.new([1,2,3])