From: Joshua Ballanco Date: 2011-12-04T08:42:43+09:00 Subject: [ruby-core:41466] Re: [ruby-trunk - Feature #5478] import Set into core, add syntax --20cf300fb2ffea173a04b338a301 Content-Type: text/plain; charset=UTF-8 Perhaps in the vein of OCaml, we could use {[]} for set literals? On Sat, Dec 3, 2011 at 4:53 PM, Jos Backus wrote: > > Issue #5478 has been updated by Jos Backus. > > > How would one represent an empty Set? > '{}' can't be used as it would be ambiguous. > > ---------------------------------------- > 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 > > --20cf300fb2ffea173a04b338a301 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Perhaps in the vein of OCaml, we could use {[]} for set literals?

On Sat, Dec 3, 2011 at 4:53 PM, Jos Backus <jos@catnook.com> wrote:

Issue #5478 has been updated by Jos Backus.


How would one represent an empty Set?
'{}' can't be used as it would be ambiguous.

----------------------------------------
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


=3Dbegin
A set is a central data structure. However, a lot of Ruby developers use ar= rays for situations where it would be more reasonable to use a set. One rea= son 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:

=C2=A0 =C2=A0<1, 2, 3> =C2=A0# might be tricky to parse
=C2=A0 =C2=A0#[1, 2, 3] # would collide with comments
=C2=A0 =C2=A0$[1, 2, 3]
=C2=A0 =C2=A0${1, 2, 3}

Method suggestions:

=C2=A0 =C2=A0~[1, 2, 3]
=C2=A0 =C2=A0+[1, 2, 3]

Whitespace separated String Sets could look like this:

=C2=A0 =C2=A0%w<foo bar blah> # creates an array at the moment
=C2=A0 =C2=A0#w[foo bar blah] # would collide with comments
=C2=A0 =C2=A0$w[foo bar blah] # would collide with sending :[] to $w
=C2=A0 =C2=A0$w{foo bar blah}

=C2=A0 =C2=A0~%w[foo bar blah] # not really shorter than using an array wi= th strings
=C2=A0 =C2=A0+%w[foo bar balh] # not really shorter than using an array wi= th strings

Maybe it's ok to not have a whitespace separated syntax, I'm just b= rainstorming 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 a= nd Rubinius if you would consider this to be useful.
Although I would need help with the parser.
=3Dend



--
http://redmine.r= uby-lang.org


--20cf300fb2ffea173a04b338a301--