s:g/T/U/ doesn't work ?

2012-10-24 Thread Marc Chantreux
hello perl6 people,

On

This is perl6 version 2012.09.1
built on parrot 4.6.0 revision 0

When i try to run

use v6;
use Test;
for 'GATGGAACTTGACTACGTAAATT' {
s:g/T/U/;
is $_
, 'GAUGGAACUUGACUACGUAAAUU'
, 'RNA';
}

I get

Cannot assign to a non-container
  in sub infix:= at src/gen/CORE.setting:11692
  in block at /tmp/ZZZ:4

As far as i understand from the doc, s:g/T/U/ is a valid syntax. any idea? 

regards
marc


the nature of a scalar?

2012-10-24 Thread Marc Chantreux
hello perl6 people,


this code says foo, exactly as expected. 

use v6;
my $path = ;
$path ||=foo;
say $path;

I'm trying to use the same thinh in a get callback of Baildador and it doesn't
work. i try to understand why is it so.

use v6;
use lib 'lib';
use Bailador;

get / (.*) '/' / = sub ($path) {
$path||=foo;
hello ($path)  ({$path.WHAT};{$path.defined}) {so $path};
#  curl localhost:3000
# hello ()  (;True) True
}
baile;

please help! 
regards
marc 



Re: s:g/T/U/ doesn't work ?

2012-10-24 Thread Carl Mäsak
Marc ():
 hello perl6 people,

 On

 This is perl6 version 2012.09.1
 built on parrot 4.6.0 revision 0

 When i try to run

 use v6;
 use Test;
 for 'GATGGAACTTGACTACGTAAATT' {
 s:g/T/U/;
 is $_
 , 'GAUGGAACUUGACUACGUAAAUU'
 , 'RNA';
 }

 I get

 Cannot assign to a non-container
   in sub infix:= at src/gen/CORE.setting:11692
   in block at /tmp/ZZZ:4

 As far as i understand from the doc, s:g/T/U/ is a valid syntax. any idea?

It's valid syntax. The error you're getting is not a syntax error;
it's a run-time error complaining about assigning to something that
isn't a container.

What you're assigning to is 'GATGGAACTTGACTACGTAAATT', a Str object.
That's a bit like trying to assign to the number 5. It should produce
an error, and it does. You need to put it into a variable, or an array
element, or a hash value -- in short, a container -- for it to work.
I think part of what felt confusing about this is that you did things
in a 'for' loop, so the assignment directly to a Str isn't that
obvious.

By the way, that 'for' loop over a single element is usually spelled
'given' in Perl 6.

I would write your code like this:

use v6;
use Test;

{
$_ = 'GATGGAACTTGACTACGTAAATT';
s:g/T/U/;
is $_,
'GAUGGAACUUGACUACGUAAAUU',
'RNA';
}

// Carl


Re: s:g/T/U/ doesn't work ?

2012-10-24 Thread jerry gay
On Wed, Oct 24, 2012 at 5:35 AM, Marc Chantreux kha...@phear.org wrote:
 Cannot assign to a non-container
   in sub infix:= at src/gen/CORE.setting:11692
   in block at /tmp/ZZZ:4

you're attempting to modify a string constant, which cannot be
modified. try something like (untested):

my $snippet = 'GATGGAACTTGACTACGTAAATT';
for $snippet {
  ...

~jerry


Re: s:g/T/U/ doesn't work ?

2012-10-24 Thread Jonathan Scott Duff
I imagine it's the same problem as this Perl 5 code:

use Test::More;

for ('GATGGAACTTGACTACGTAAATT') {
s/T/U/g;
is $_, 'GAUGGAACUUGACUACGUAAAUU', 'RNA';
}


Since $_ is an alias for each element of the list and the only element in
the list is a constant string and you can't modify constants, you get the
error.  Changing your code to:

use v6;
use Test;

my $x = 'GATGGAACTTGACTACGTAAATT';
for $x {
s:g/T/U/;
is $_ , 'GAUGGAACUUGACUACGUAAAUU' , 'RNA';
}


Does indeed work.

Though, if what I said is true, the error message is Less Than Awesome.  I
wonder could it be made more helpful?

Hope this helps,

-Scott


On Wed, Oct 24, 2012 at 7:35 AM, Marc Chantreux kha...@phear.org wrote:

 hello perl6 people,

 On

 This is perl6 version 2012.09.1
 built on parrot 4.6.0 revision 0

 When i try to run

 use v6;
 use Test;
 for 'GATGGAACTTGACTACGTAAATT' {
 s:g/T/U/;
 is $_
 , 'GAUGGAACUUGACUACGUAAAUU'
 , 'RNA';
 }

 I get

 Cannot assign to a non-container
   in sub infix:= at src/gen/CORE.setting:11692
   in block at /tmp/ZZZ:4

 As far as i understand from the doc, s:g/T/U/ is a valid syntax. any idea?

 regards
 marc



Re: the nature of a scalar?

2012-10-24 Thread Moritz Lenz



On 10/24/2012 02:46 PM, Marc Chantreux wrote:


use v6;
use lib 'lib';
use Bailador;

get / (.*) '/' / = sub ($path) {
 $path||=foo;


$path is a subroutine parameter, and thus read-only by default.
If you want to modify $path locally, write

sub ($path is copy) { ... }

Also if Bailador passes Match objects instead of strings into the 
function, $path evaluates to True in boolean context even if it matched 
the empty string.


Cheers,
Moritz


Re: s:g/T/U/ doesn't work ?

2012-10-24 Thread Marc Chantreux
hello again, 

i felt dumb reading your answers! it seems obvious now.

thanks everyone.

regards