Michele Dondi <[EMAIL PROTECTED]> writes: > Well, it seems that there's still a big confusion/indecision about > the default behaviour. But then an interesting point, and one that > has already been raised, is that it should be somehow possible to > customize string interpolation bu means of e.g. adverbs (fortunately > we don't have "true" literal strings but rather quote-like > operators), attributes and god know what else!
I rather like the notion of putting the adverb on the q operator and its kin (qq, qx, ...) print q :literal "The value of $foo is " . $foo . "\n"; :literal might be poorly huffman coded, and q (as opposed to qq or whatever) might already default to not interpolating scalars, but the above demonstrates the syntax. One nice thing about this is it still allows for arbitrary characters to be used to delimit the quote: print qq :scalarcontext (There are @foo elements in [EMAIL PROTECTED]); Again, :scalarcontext isn't the point, just an illustration of the syntax. This syntax also would give us symetry with the match operators... $foo = qr :baz !blah$!; $bar =~ m :quux $foo; # I forget: is =~ still spelled as in Perl5? Here also, with qr you could use whatever adverbs you use with any of its brethren quoting operators, to interpolate or not interpolate various stuff, and then you could still use whatever pattern-match adverbs you like with the match operator. > Now it should be stressed that the problem is twofold here: one > aspect is chosing the "best" default for some hopefully reasonable > meaning of "best" Sure, but allowing the default to be overridden with adverbs doesn't hinder the ability to choose a nice default. > and the other one is providing a "slim" syntax for the alternate > behaviour(s); i.e. IMHO it would be unreasonable to require the > users to type something like > > :with_method_interpolation One would hope an adverb that useful would be shorter, sure. Maybe something along these lines, if we can conscion it... $foo = qq :i($) "Woo $hoo"; $bar = qq :i<<@ .>> ($boo.hoo @wibble); Here i stands for interplate, $ for scalars, @ for arrays, . for methods. If this is deemed too cryptic, perhaps something in between this and the excessive verbosity of :with_method_interplation is in order. It's slightly bothersome that :i would mean "interplate" for quoting but "case-insensitive" for matching, but since case-insensitivity doesn't seem sensible for quoting that might not matter. I thought about :int for interpolation, but too many people would think integer, probably, and :itpl is just too C-like in its unpronounceability and complete lack of obvious meaning. ("What's an i-tuple?") :terp or :iterp would make people think "interpreter" rather than "interpolate", I fear, and when we move up to :terpolate we're getting long. The only synonym I can think of for interpolate is evaluate, and I'm not certain :eval would mean the right thing to everyone. > each time they want it. But maybe certain delimiters for qq may > already provide that... (or would that be a bad idea?) I don't think which _delimiters_ you choose should have any impact on how the interpolation is done (except as regards the delimiters themselves; if you choose $ as your delimiter, you're going to have a hard time interplating scalars, obviously). IMO, the difference between q and qq should have to do with which adverbs are turned on by default. > As a related side note, is it possible to use multi-char delimiters in > Perl6? I mean, a la: > > qq<<...>>; I would worry that you'd be getting "<" and ">" at the beginning and end of your string. IMO, there are enough characters in ASCII that for any short quotation you ought to be able to find one character you can use as a quote delimiter. For longer quotations, we have heredocs. Speaking of which, that raises another question: can we apply adverbs to heredocs? if (somecondition()) { $foo = << :indent(5) "FOO"; blah, blah blah, blah blah, blah FOO } Parsing concerns might constrain that to this: if (somecondition()) { $foo = << :indent(5) "FOO"; blah, blah blah, blah blah, blah FOO } Which is still better than the bletcherous Perl5 way: if (somecondition()) { $foo = <<"FOO"; blah, blah blah, blah blah, blah FOO } I've found myself wrapping long quotations in their own subroutines (that just contain a heredoc and return a string) at the bottom of the file in Perl5 just to keep my indentation sane. There ought to be some way around this problem for POD, too. Perhaps POD could have its own quote operator... sub foo { qp :indent(5) <<FOOPOD; Put some POD here. FOOPOD ... } -- $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,"[EMAIL PROTECTED]/ --";$\=$ ;-> ();print$/