On 10/23/19 6:07 AM, Ricky Teachey wrote:
I would expect %w{ ... } to return a set, not a list:
%w[ ... ] # list %w{ ... ] # set %w( ... ) # tuple
and I would describe them as list/set/tuple "word literals". Unlike list etc displays [spam, eggs, cheese] these would actually be true literals that can be determined entirely at compile-time.
A more convenient way to populate lists/tuples/sets full of strings at compile time seems like a win.
If I might be allowed to bikeshed: the w seems unnecessary. Why not drop it in favor of a single character like %, and use an optional r for raw strings?
%[words] # "words".split() %{words} # set("words".split()) %(words) # tuple("words".split()) %r[wo\rds] # "wo\\rds".split() %r{wo\rds} # set("wo\\rds".split()) %r(wo\rds) # tuple("wo\\rds".split())
At that point, the "obvious" choice is an "s" (short for "split") string rather than a whole new construct: >>> s"one two three" ["one", "two", "three"] which could be combined with "r" like f and b strings.