Feature #4985
closedAdd %S[] support for making a list of symbols
Added by tenderlovemaking (Aaron Patterson) over 14 years ago. Updated over 13 years ago.
Description
I would like to add %S, which would create a list of symbols.
For example:
%S[foo bar] # => [:foo, :bar]
I've attached a patch which implements this along with ripper events and tests. Thanks to Josh Susser for thinking of this. :-)
Files
| qsymbols.patch (5.82 KB) qsymbols.patch | symbol patch | tenderlovemaking (Aaron Patterson), 07/07/2011 01:00 PM | |
| qsymbols.patch (5.76 KB) qsymbols.patch | correctly indented patch | tenderlovemaking (Aaron Patterson), 07/07/2011 01:02 PM | |
| percent_i.patch (7.2 KB) percent_i.patch | percent i and percent I | tenderlovemaking (Aaron Patterson), 08/04/2011 09:26 AM | |
| feature4985.pdf (261 KB) feature4985.pdf | tenderlovemaking (Aaron Patterson), 07/01/2012 04:27 AM | ||
| noname (500 Bytes) noname | Anonymous, 07/02/2012 11:29 PM | ||
| noname (500 Bytes) noname | Anonymous, 07/02/2012 11:29 PM | ||
| 4985.patch (7.69 KB) 4985.patch | updated patch to fix conflicts and tests | tenderlovemaking (Aaron Patterson), 07/24/2012 08:44 AM | 
        
           Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #1
            [ruby-core:37841]
          Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #1
            [ruby-core:37841]
        
      
      - File qsymbols.patch qsymbols.patch added
Adding a new patch with correct indentation for parse.y
        
           Updated by vjoel (Joel VanderWerf) over 14 years ago
          
          
        
        
          
            Actions
          
          #2
            [ruby-core:37843]
          Updated by vjoel (Joel VanderWerf) over 14 years ago
          
          
        
        
          
            Actions
          
          #2
            [ruby-core:37843]
        
      
      Wondering idly if the following could be parsed...
:[foo bar]
Eh, maybe it's too inconsistent with % notation anyway.
        
           Updated by matz (Yukihiro Matsumoto) over 14 years ago
          
          
        
        
          
            Actions
          
          #3
            [ruby-core:37844]
          Updated by matz (Yukihiro Matsumoto) over 14 years ago
          
          
        
        
          
            Actions
          
          #3
            [ruby-core:37844]
        
      
      Interesting idea (include Joel's)! But I am not sure whether they are the right prefix.
matz.
        
           Updated by nobu (Nobuyoshi Nakada) over 14 years ago
          
          
        
        
          
            Actions
          
          #4
            [ruby-core:37845]
          Updated by nobu (Nobuyoshi Nakada) over 14 years ago
          
          
        
        
          
            Actions
          
          #4
            [ruby-core:37845]
        
      
      Hi,
At Thu, 7 Jul 2011 16:15:36 +0900,
Joel VanderWerf wrote in [ruby-core:37843]:
Wondering idly if the following could be parsed...
:[foo bar]
It would be possible, but conflicts with :[] ("[]".to_sym).
--
Nobu Nakada
        
           Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #5
            [ruby-core:37848]
          Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #5
            [ruby-core:37848]
        
      
      On Thu, Jul 07, 2011 at 04:48:51PM +0900, Yukihiro Matsumoto wrote:
Issue #4985 has been updated by Yukihiro Matsumoto.
Interesting idea (include Joel's)! But I am not sure whether they are the right prefix.
Ya.  We already have %s, so %S might be confusing (especially when
compared to %w and %W).  I don't care about the prefix so much as I care
about having the feature.  :-)
--
Aaron Patterson
http://tenderlovemaking.com/
        
           Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #6
            [ruby-core:37849]
          Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #6
            [ruby-core:37849]
        
      
      On Thu, Jul 07, 2011 at 04:48:51PM +0900, Yukihiro Matsumoto wrote:
Issue #4985 has been updated by Yukihiro Matsumoto.
Interesting idea (include Joel's)! But I am not sure whether they are the right prefix.
How about %i and %I? (i stands for "intern").
--
Aaron Patterson
http://tenderlovemaking.com/
        
           Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #7
          Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #7
        
      
      - File deleted (noname)
        
           Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #8
          Updated by tenderlovemaking (Aaron Patterson) over 14 years ago
          
          
        
        
          
            Actions
          
          #8
        
      
      - File deleted (noname)
        
           Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 14 years ago
          
          
        
        
          
            Actions
          
          #9
            [ruby-core:37850]
          Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 14 years ago
          
          
        
        
          
            Actions
          
          #9
            [ruby-core:37850]
        
      
      How about "%:(symbol1 symbol2)"?
        
           Updated by nobu (Nobuyoshi Nakada) over 14 years ago
          
          
        
        
          
            Actions
          
          #10
            [ruby-core:37862]
          Updated by nobu (Nobuyoshi Nakada) over 14 years ago
          
          
        
        
          
            Actions
          
          #10
            [ruby-core:37862]
        
      
      Hi,
At Fri, 8 Jul 2011 02:36:50 +0900,
Rodrigo Rosenfeld Rosas wrote in [ruby-core:37850]:
How about "%:(symbol1 symbol2)"?
$ ruby -e 'p %:(:'
"("
Already ":" manages hard works. Don't overload anymore.
--
Nobu Nakada
        
           Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          
          
        
        
          
            Actions
          
          #11
            [ruby-core:38770]
          Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          
          
        
        
          
            Actions
          
          #11
            [ruby-core:38770]
        
      
      - File percent_i.patch percent_i.patch added
I've updated my patch to implement %i and %I. They have the same semantics as %w and %W (one with interpolation, one without).
What do you think of this matz?
        
           Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          
          
        
        
          
            Actions
          
          #12
            [ruby-core:39148]
          Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          
          
        
        
          
            Actions
          
          #12
            [ruby-core:39148]
        
      
      Bump
        
           Updated by shyouhei (Shyouhei Urabe) over 13 years ago
          
          
        
        
          
            Actions
          
          #13
          Updated by shyouhei (Shyouhei Urabe) over 13 years ago
          
          
        
        
          
            Actions
          
          #13
        
      
      - Status changed from Open to Assigned
        
           Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
          
          
        
        
          
            Actions
          
          #14
            [ruby-core:46005]
          Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
          
          
        
        
          
            Actions
          
          #14
            [ruby-core:46005]
        
      
      - File feature4985.pdf feature4985.pdf added
adding a slide
        
           Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 13 years ago
          
          
        
        
          
            Actions
          
          #15
            [ruby-core:46016]
          Updated by rosenfeld (Rodrigo Rosenfeld Rosas) over 13 years ago
          
          
        
        
          
            Actions
          
          #15
            [ruby-core:46016]
        
      
      I don't understand why your pdfs have a second weird slide :)
        
           Updated by mame (Yusuke Endoh) over 13 years ago
          
          
        
        
          
            Actions
          
          #16
            [ruby-core:46068]
          Updated by mame (Yusuke Endoh) over 13 years ago
          
          
        
        
          
            Actions
          
          #16
            [ruby-core:46068]
        
      
      Received. Thank you!
The second page is mysterious... A cat or something walked a straight line of your keyboard? :-)
--
Yusuke Endoh mame@tsg.ne.jp
        
           Updated by ko1 (Koichi Sasada) over 13 years ago
          
          
        
        
          
            Actions
          
          #17
            [ruby-core:46091]
          Updated by ko1 (Koichi Sasada) over 13 years ago
          
          
        
        
          
            Actions
          
          #17
            [ruby-core:46091]
        
      
      I guessed that %S(...) is S-expr syntax.
example:
%S((foo bar (baz boo)) #=> [:foo, :bar, [:baz, :boo]]
(I have no idea about use-case of this S-expr literal, except Lisp like DSL)
--
// SASADA Koichi at atdot dot net
        
           Updated by Anonymous over 13 years ago
          
          
        
        
          
            Actions
          
          #18
            [ruby-core:46106]
          Updated by Anonymous over 13 years ago
          
          
        
        
          
            Actions
          
          #18
            [ruby-core:46106]
        
      
      On Mon, Jul 02, 2012 at 02:17:12AM +0900, mame (Yusuke Endoh) wrote:
Issue #4985 has been updated by mame (Yusuke Endoh).
Received. Thank you!
The second page is mysterious... A cat or something walked a straight line of your keyboard? :-)
Quit likely. Sorry about the second page. ;-)
--
Aaron Patterson
http://tenderlovemaking.com/
        
           Updated by Anonymous over 13 years ago
          
          
        
        
          
            Actions
          
          #19
            [ruby-core:46107]
          Updated by Anonymous over 13 years ago
          
          
        
        
          
            Actions
          
          #19
            [ruby-core:46107]
        
      
      On Mon, Jul 02, 2012 at 06:45:38AM +0900, SASADA Koichi wrote:
I guessed that %S(...) is S-expr syntax.
example:
%S((foo bar (baz boo)) #=> [:foo, :bar, [:baz, :boo]](I have no idea about use-case of this S-expr literal, except Lisp like DSL)
My patch (and slide) actually uses %i and %I ("i" stands for "intern")
and mirrors %w and %W.  %s is already taken :-)
--
Aaron Patterson
http://tenderlovemaking.com/
        
           Updated by claytrump (Clay Trump) over 13 years ago
          
          
        
        
          
            Actions
          
          #20
            [ruby-core:46113]
          Updated by claytrump (Clay Trump) over 13 years ago
          
          
        
        
          
            Actions
          
          #20
            [ruby-core:46113]
        
      
      +1, I'd use that a lot.
Do we need two versions? Why not always interpolate? Can't see who's going
to need a symbol with a litteral #{ or \whatever in it.
This way we could have only %S and it always interpolates.¶
        
           Updated by nobu (Nobuyoshi Nakada) over 13 years ago
          
          
        
        
          
            Actions
          
          #21
            [ruby-core:46592]
          Updated by nobu (Nobuyoshi Nakada) over 13 years ago
          
          
        
        
          
            Actions
          
          #21
            [ruby-core:46592]
        
      
      =begin
The latest ((%percent_i.patch%)) seems almost fine, except for a conflict in ((%parse.y%)).
=end
        
           Updated by nobu (Nobuyoshi Nakada) over 13 years ago
          
          
        
        
          
            Actions
          
          #22
            [ruby-core:46594]
          Updated by nobu (Nobuyoshi Nakada) over 13 years ago
          
          
        
        
          
            Actions
          
          #22
            [ruby-core:46594]
        
      
      =begin
Seems like ((%ext/ripper/eventids2.c%)) misses (({tSYMBOLS_BEG})).
=end
        
           Updated by mame (Yusuke Endoh) over 13 years ago
          
          
        
        
          
            Actions
          
          #23
            [ruby-core:46647]
          Updated by mame (Yusuke Endoh) over 13 years ago
          
          
        
        
          
            Actions
          
          #23
            [ruby-core:46647]
        
      
      - Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada)
Aaron Patterson,
I'm happy to inform you that matz has accepted your proposal.
Matz was worried about the letter `i' and searching other ones,
but finally accepted.
Nakada-san,
Could you review the patch attached?
--
Yusuke Endoh mame@tsg.ne.jp
        
           Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
          
          
        
        
          
            Actions
          
          #24
            [ruby-core:46691]
          Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
          
          
        
        
          
            Actions
          
          #24
            [ruby-core:46691]
        
      
      - File 4985.patch 4985.patch added
I've attached an updated patch that includes the correct symbols, fixes the ripper tests, and fixes the conflicts.
Nakada-san: if you're happy with this patch, I can apply. :)
        
           Updated by nobu (Nobuyoshi Nakada) over 13 years ago
          
          
        
        
          
            Actions
          
          #25
            [ruby-core:46717]
          Updated by nobu (Nobuyoshi Nakada) over 13 years ago
          
          
        
        
          
            Actions
          
          #25
            [ruby-core:46717]
        
      
      Seems fine to me.
        
           Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
          
          
        
        
          
            Actions
          
          #26
          Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
          
          
        
        
          
            Actions
          
          #26
        
      
      - Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r36524.
Aaron, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- 
parse.y: added symbols and qsymbols productions for %i and %I 
 support. %i{ .. } returns a list of symbols without interpolation,
 %I{ .. } returns a list of symbols with interpolation. Thanks to
 Josh Susser for inspiration of this feature. [Feature #4985]
- 
ext/ripper/eventids2.c: added ripper events for %i and %I. 
- 
test/ripper/test_parser_events.rb: ripper tests 
- 
test/ripper/test_scanner_events.rb: ditto 
- 
test/ruby/test_array.rb: test for %i and %I behavior