Re: questions about qw<>

2015-10-13 Thread Elizabeth Mattijsen
> On 13 Oct 2015, at 20:21, Marc Chantreux  wrote:
> On Tue, Oct 13, 2015 at 05:59:04PM +0200, Elizabeth Mattijsen wrote:
> an unnamed hash ? does it make sense? 

sub h() { my % = a => 42, b => 666 }; dd h

Just another way to create an anonymous hash.



Liz


Re: questions about qw<>

2015-10-13 Thread Marc Chantreux
On Tue, Oct 13, 2015 at 05:59:04PM +0200, Elizabeth Mattijsen wrote:
> > designers for having a very good reason and i'm curious: what is actually 
> > this good reason for such a weird behave.
> 
> Well, for one, it is according to spec.  :-)

:)

> But the real reason, is that you can also use  to indicate the
> value of a key in a hash:
> my %h = a => 42;
> dd %h;

well .. ok ... i'll deal with it.

> >%< class foo id bar >
> 
> That is really a slice on an unnamed hash.  So that is ambiguous.

an unnamed hash ? does it make sense? 

> >[ ] i missed the good paragraph of the documentation ?
> >[ ] i'm going to do something very stupid ? 
> >[ ] other, your answer here
> 
> $ 6 'dd %()’
> Hash % = {:a("b"), :c("d")}


> > * i just don't know way i need | in front of % ... it just works but for
> >  me %() was enought and explicit on what i wanted to get. can someone 
> > explain ?
> 
> I guess without the |, you would pass a Hash to br.

i forgot to send the link. it was built with 

https://github.com/eiro/p6-Rototo/blob/master/lib/Rototo.pm#L11

> became a list of pairs.  Can’t really tell without the br code.  But,
> fwiw, I don’t think you need the prefix % at all  :-)

i do 'cause of the signature (*%attrs)

thanks for your answer!

cya

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
-- Abraham Lincoln


Re: questions about qw<>

2015-10-13 Thread Elizabeth Mattijsen
> On 13 Oct 2015, at 17:15, Marc Chantreux  wrote:
> 
> hello,
> 
> playing with <>, two questions came to my mind:
> 
> a) why isn't it "regular" ?
> 
>use Test;
>ok < foo bar bang >  ~~ List, "a list";
>ok < foo bar  >  ~~ List, "a list";
>ok < foo  >  ~~ List, "a list"; diag "actually a Str";
>ok < >  ~~ List, "a list";
> 
> not only it is an exception to a simple rule but it waste memorizable and 
> short
> way to write a 1 element list. as always with perl6, i trust the perl6
> designers for having a very good reason and i'm curious: what is actually 
> this good reason for such a weird behave.

Well, for one, it is according to spec.  :-)

But the real reason, is that you can also use  to indicate the value of a 
key in a hash:

my %h = a => 42;
dd %h;

Now, you want that to return a single Int, not a List with one Int in it.

So, that’s why  is a Str, and not a List.



> b) shortest way to hash ?
> 
> i used %(< class foo id bar >) in my code
> 
>https://github.com/eiro/p6-Rototo/blob/master/t/basic.t#L21
> 
> i know it sounds stupid but i'm very sorry not being able to write (and most
> of all: read and edit)
> 
>%< class foo id bar >

That is really a slice on an unnamed hash.  So that is ambiguous.

> 
> which isn't allowed ... but perl6 let me cheat: i can define a %
> operator working with an extra space
> 
>use v6; 
>use Rototo::html;
> 
>sub H (*@data) { join '', @data }
>sub prefix:<%> ( List $l ) is tighter(&infix:<,>) { %(|$l) }
> 
>say % < id foo class bar >; # class => bar, id => foo
>( % < id foo class bar > ).^name.say;   #   Hash
>say H br :id, :class; #  
>say H br |% < id foo class bar >;   #  
>say H p  |% < id foo class bar >, "this is a good thing”;
># this is a good thing
> 
> this is working but raised 2 questions:
> 
> * if it was so easy, why isn't it in perl6? 
>[ ] i missed the good paragraph of the documentation ?
>[ ] i'm going to do something very stupid ? 
>[ ] other, your answer here

$ 6 'dd %()’
Hash % = {:a("b"), :c("d")}


> * i just don't know way i need | in front of % ... it just works but for
>  me %() was enought and explicit on what i wanted to get. can someone explain 
> ?

I guess without the |, you would pass a Hash to br.  With the |, it became a 
list of pairs.  Can’t really tell without the br code.  But, fwiw, I don’t 
think you need the prefix % at all  :-)



Liz

questions about qw<>

2015-10-13 Thread Marc Chantreux
hello,

playing with <>, two questions came to my mind:

a) why isn't it "regular" ?

use Test;
ok < foo bar bang >  ~~ List, "a list";
ok < foo bar  >  ~~ List, "a list";
ok < foo  >  ~~ List, "a list"; diag "actually a Str";
ok < >  ~~ List, "a list";

not only it is an exception to a simple rule but it waste memorizable and short
way to write a 1 element list. as always with perl6, i trust the perl6
designers for having a very good reason and i'm curious: what is actually 
this good reason for such a weird behave.

b) shortest way to hash ?

i used %(< class foo id bar >) in my code

https://github.com/eiro/p6-Rototo/blob/master/t/basic.t#L21

i know it sounds stupid but i'm very sorry not being able to write (and most
of all: read and edit)

%< class foo id bar >

which isn't allowed ... but perl6 let me cheat: i can define a %
operator working with an extra space

use v6; 
use Rototo::html;

sub H (*@data) { join '', @data }
sub prefix:<%> ( List $l ) is tighter(&infix:<,>) { %(|$l) }

say % < id foo class bar >; # class => bar, id => foo
( % < id foo class bar > ).^name.say;   #   Hash
say H br :id, :class; #  
say H br |% < id foo class bar >;   #  
say H p  |% < id foo class bar >, "this is a good thing";
# this is a good thing

this is working but raised 2 questions:

* if it was so easy, why isn't it in perl6? 
[ ] i missed the good paragraph of the documentation ?
[ ] i'm going to do something very stupid ? 
[ ] other, your answer here

* i just don't know way i need | in front of % ... it just works but for
  me %() was enought and explicit on what i wanted to get. can someone explain ?

regards 

-- 
Marc Chantreux,
Mes coordonnées: http://annuaire.unistra.fr/chercher?n=chantreux
Direction Informatique, Université de Strasbourg (http://unistra.fr) 
"Don't believe everything you read on the Internet"
-- Abraham Lincoln