Re: Not a bug?
On Mon, Jan 12, 2009 at 3:54 PM, Larry Wall wrote: > On Mon, Jan 12, 2009 at 01:19:12PM -0800, Jon Lang wrote: > : As well, isn't there a way to escape a character that would otherwise > : be interpolated? If the intent were as you suppose, the original > : could be rewritten as: > : > : $ perl6 -e 'my $foo = "foo";say "\{" ~ $foo ~ "}"' > > Sure, though in any case I'd probably prefer: > >$ perl6 -e 'my $foo = "foo"; say Qs/{$foo}/' > > : (Or would you need to escape the closing curly brace as well as the > : opening one?) > > Not unless something outside of it all was attempting to count braces. > But the P6 parser has sworn off all such activities for P6-derived > code. Parsing something first as a string and then again as some > other language is generally looked upon as a Bad Plan these days. > > Which is, of course, why "{" is a problem now. Perhaps use of nested > double quotes deserves a warning. > masak++ was right, if you use single quotes it works properly. Here's how you do it from a bash prompt: $ ./perl6 -e 'my $foo = '\''foo'\''; say '\''{'\'' ~ $foo ~ '\''}'\'' ' {foo} Notice the overly redundant single-quotes; in fact, all of those quotes are single quotes. -Jason "s1n" Switzer
Re: Not a bug?
On Mon, Jan 12, 2009 at 01:19:12PM -0800, Jon Lang wrote: : As well, isn't there a way to escape a character that would otherwise : be interpolated? If the intent were as you suppose, the original : could be rewritten as: : : $ perl6 -e 'my $foo = "foo";say "\{" ~ $foo ~ "}"' Sure, though in any case I'd probably prefer: $ perl6 -e 'my $foo = "foo"; say Qs/{$foo}/' : (Or would you need to escape the closing curly brace as well as the : opening one?) Not unless something outside of it all was attempting to count braces. But the P6 parser has sworn off all such activities for P6-derived code. Parsing something first as a string and then again as some other language is generally looked upon as a Bad Plan these days. Which is, of course, why "{" is a problem now. Perhaps use of nested double quotes deserves a warning. Larry
Re: Not a bug?
On Mon, Jan 12, 2009 at 1:08 PM, Larry Wall wrote: > On Mon, Jan 12, 2009 at 03:43:47AM -0800, Jon Lang wrote: > : On Mon, Jan 12, 2009 at 2:15 AM, Carl Mäsak wrote: > : > Ovid (>): > : >> $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' > : >> ~ foo ~ > : > > : > Easy solution: only use double quotes when you want to interpolate. :) > : > > : > This is not really an option when running 'perl6 -e' under bash, though. > : > : $ perl6 -e 'my $foo = "foo";say q:qq({" ~ $foo ~ "})' > : > : ...or something to that effect. > > Assuming that's what was wanted. I figgered they want something more > like: > >$ perl6 -e 'my $foo = "foo"; say q[{] ~ $foo ~ q[}];' True enough. Either one of these would be more clear than the original example in terms of user intent. As well, isn't there a way to escape a character that would otherwise be interpolated? If the intent were as you suppose, the original could be rewritten as: $ perl6 -e 'my $foo = "foo";say "\{" ~ $foo ~ "}"' (Or would you need to escape the closing curly brace as well as the opening one?) -- Jonathan "Dataweaver" Lang
Re: Not a bug?
On Mon, Jan 12, 2009 at 03:43:47AM -0800, Jon Lang wrote: : On Mon, Jan 12, 2009 at 2:15 AM, Carl Mäsak wrote: : > Ovid (>): : >> $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' : >> ~ foo ~ : > : > Easy solution: only use double quotes when you want to interpolate. :) : > : > This is not really an option when running 'perl6 -e' under bash, though. : : $ perl6 -e 'my $foo = "foo";say q:qq({" ~ $foo ~ "})' : : ...or something to that effect. Assuming that's what was wanted. I figgered they want something more like: $ perl6 -e 'my $foo = "foo"; say q[{] ~ $foo ~ q[}];' Larry
Re: Not a bug?
HaloO, Tim Bunce wrote: On Sun, Jan 11, 2009 at 04:41:12PM -0800, Ovid wrote: I really don't think this is a bug, but it did confuse the heck out of me at first. This *is* expected behavior due to how {} is interpolated in strings, yes? $ perl6 -e 'my $foo = "foo";say "<" ~ $foo ~ ">"' $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' ~ foo ~ I presume string interpolation is, er, "set-up", at compile-time. So it only happened here because "{" ~ $foo ~ "}" was rewritten to "{$foo}" at compile-time. And if "{" and "}" were replaced with variables, for example, then the interpolation wouldn't have happened. Right? The point is that the code that is interpolated is just the string " ~ $foo ~ " which is interpolated when the closure runs. That is there are two nested interpolations! Note that you can't use "{" to initialize a variable because it either ends in a syntax error or as in the given example swallows some code into a string. This works as you intent: my $left = '{'; my $right = '}'; my $foo = "foo"; # no danger with interpolation say $left ~ $foo ~ $right; That is in the example from Ovid there are *no* concatenations! Regards, TSa. -- "The unavoidable price of reliability is simplicity" -- C.A.R. Hoare "Simplicity does not precede complexity, but follows it." -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan
Re: Not a bug?
On Sun, Jan 11, 2009 at 04:41:12PM -0800, Ovid wrote: > I really don't think this is a bug, but it did confuse the heck out of me at > first. This *is* expected behavior due to how {} is interpolated in strings, > yes? > > $ perl6 -e 'my $foo = "foo";say "<" ~ $foo ~ ">"' > > $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' >~ foo ~ I presume string interpolation is, er, "set-up", at compile-time. So it only happened here because "{" ~ $foo ~ "}" was rewritten to "{$foo}" at compile-time. And if "{" and "}" were replaced with variables, for example, then the interpolation wouldn't have happened. Right? Tim.
Re: Not a bug?
On Mon, Jan 12, 2009 at 2:15 AM, Carl Mäsak wrote: > Ovid (>): >> $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' >> ~ foo ~ > > Easy solution: only use double quotes when you want to interpolate. :) > > This is not really an option when running 'perl6 -e' under bash, though. $ perl6 -e 'my $foo = "foo";say q:qq({" ~ $foo ~ "})' ...or something to that effect. -- Jonathan "Dataweaver" Lang
Re: Not a bug?
Ovid (>): > $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' > ~ foo ~ Easy solution: only use double quotes when you want to interpolate. :) This is not really an option when running 'perl6 -e' under bash, though. // Carl
Re: Not a bug?
On Sun, Jan 11, 2009 at 04:41:12PM -0800, Ovid wrote: : I really don't think this is a bug, but it did confuse the heck out of me at first. This *is* expected behavior due to how {} is interpolated in strings, yes? : : $ perl6 -e 'my $foo = "foo";say "<" ~ $foo ~ ">"' : : $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' :~ foo ~ Yep, that's working right. Or at least, working as designed... :) Larry
Not a bug?
I really don't think this is a bug, but it did confuse the heck out of me at first. This *is* expected behavior due to how {} is interpolated in strings, yes? $ perl6 -e 'my $foo = "foo";say "<" ~ $foo ~ ">"' $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' ~ foo ~ Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6