From: Alexey Muranov Date: 2011-12-05T19:59:11+09:00 Subject: [ruby-core:41490] [ruby-trunk - Feature #5478] import Set into core, add syntax Issue #5478 has been updated by Alexey Muranov. Adam Prescott wrote: > On Sun, Dec 4, 2011 at 22:34, Joshua Ballanco wrote: > > > Actually, the bulk of Set's functionality is already built on top of Hash. > > Personally, since the ability to create Hashes from comma-delimited > > key,value lists has been removed in 1.9, I think reintroducing it to create > > Set literals is not the worst idea in the world. > > > > Additionally, implementing Set functionality directly on top of Hash would > > remove the unfortunate method call overhead that currently exists in the > > Set library (note that the implementation of Set#include? is just a call > > through to Hash#include?): > > > > This really does seem to just be an argument via implementation details. I > don't think that's the best approach. The point of implementation details > is that they're just that. From the point of view of behavior/interface, both sets and associative arrays are just unordered collections, associative arrays being unordered collections of (key,value) pairs, where each key is unique. ---------------------------------------- Feature #5478: import Set into core, add syntax http://redmine.ruby-lang.org/issues/5478 Author: Konstantin Haase Status: Open Priority: Normal Assignee: Category: Target version: 3.0 =begin A set is a central data structure. However, a lot of Ruby developers use arrays for situations where it would be more reasonable to use a set. One reason for that is that it is way easier to use Array then Set at the moment, another one is that developers are simply not aware it exists. I propose moving Set from the stdlib to core and possibly add a syntax or a method on array for creating Set literals. First class syntax suggestions: <1, 2, 3> # might be tricky to parse #[1, 2, 3] # would collide with comments $[1, 2, 3] ${1, 2, 3} Method suggestions: ~[1, 2, 3] +[1, 2, 3] Whitespace separated String Sets could look like this: %w # creates an array at the moment #w[foo bar blah] # would collide with comments $w[foo bar blah] # would collide with sending :[] to $w $w{foo bar blah} ~%w[foo bar blah] # not really shorter than using an array with strings +%w[foo bar balh] # not really shorter than using an array with strings Maybe it's ok to not have a whitespace separated syntax, I'm just brainstorming here. The issue with the method approach is that it would create an Array to send the message to first. I favor the <1, 2, 3> syntax, possibly without the ability to create a whitespace separated version. I'd be willing to work on a patch not only for MRI but also for JRuby and Rubinius if you would consider this to be useful. Although I would need help with the parser. =end -- http://redmine.ruby-lang.org