Re: Rewrite using map? Trasformation array into hash of hash

2014-06-13 Thread Elizabeth Mattijsen
On 13 Jun 2014, at 12:36, Kamil Kułaga teodoz...@gmail.com wrote:
 I was wondering whether following code can be rewritten using map/grep
 construct.
 
 
class A {
   has $.a;
   has $.b;
   }
 
 
   my @array= (
   A.new(a='a', b='11'),
   A.new(a='a', b='22'),
   A.new(a='v', b='33'),
   A.new(a='w', b='44'),
   A.new(a='v', b='55')
   );
 
 
 
   my %hash;
   for @array - $elem {
   %hash{$elem.a}{$elem.b} =$elem;
}

Not sure it makes much difference:

@array.map( { %hash{.a}{.b} = $_ } );



Liz

Re: Diffrence between is and does in scope of overriding multi methods

2014-06-27 Thread Elizabeth Mattijsen
On 27 Jun 2014, at 09:25, Timo Paulssen t...@wakelift.de wrote:
 On 27/06/14 10:07, Kamil Kułaga wrote:
 Hi,
 
 I would like to ask for help in understanding difference between this code:
 
use v6;
 
role X {
multi method xyz(Any $a) {say Class X}
 }
 
 class Y does X {
 multi method xyz(Any $a) {say Class Y}
 }
 
 say Y.new.xyz(1);
 
 $ perl6 tst.pl
  Ambiguous call to 'xyz'; these signatures all match:
  :(Y: Any $a, *%_)
  :(Y: Any $a, *%_)
   in block  at tst.pl:26
 
 And this code:
use v6;
 
class X {
multi method xyz(Any $a) {say Class X}
 }
 
 class Y is X {
 multi method xyz(Any $a) {say Class Y}
 }
 
 say Y.new.xyz(1);
 
 $ perl6 tst.pl
 Class Y
 True
 
 It is hard to google such common words like is and does :)
 
 
 Hey Kamil,
 
 What happens when you does a role in a class, you mix in all the methods 
 at the same level, basically as if you had copy-pasted the method 
 declarations over. That's why you get the error that the call to xyz is 
 ambiguous.
 
 When you is a class, you derive from it. That's why the multi method X::xyz 
 gets overwritten by Y::xyz, as the signature is identical.
 
 At least that's my understanding.
 
 Btw, you can also is a role, in which case it will get punned into a 
 class. That operation is equivalent to declaring a class with an empty body 
 that does the given role. So in the upper example, with role X and class Y, 
 you could is X and get the same behavior as in the lower example.
 
 Hope to help (and hope what I wrote is actually accurate)

FWIW, I’m not sure why the first case is actually a problem.  I would expect 
this error if both X and Y were a role composed into a class Z.


Liz



Re: Compile a program into moar vm

2015-01-02 Thread Elizabeth Mattijsen
 On 01 Jan 2015, at 19:36, MAX PUX isleof...@gmail.com wrote:
 
 Excuse me but I can't find the documentation.
 Is there a way to compile a perl 6 program to moar vm bytecode?
 For example from example.pl to example.moarvm.

CompUnit.new(‘example.pl’).precomp

will create an ‘example.pl.moarvm’.


But there’s no real way to run it just yet like that.  It’s intended to only 
precompile modules at the moment.



Liz

Re: What is the latest Rakudo Star?

2015-01-03 Thread Elizabeth Mattijsen
 On 03 Jan 2015, at 21:32, Parrot Raiser 1parr...@gmail.com wrote:
 
 I stopped paying attention for a bit, and lost track.

2014.12.1


Liz


Re: Debug core modules

2015-01-11 Thread Elizabeth Mattijsen
 On 11 Jan 2015, at 10:57, MAX PUX isleof...@gmail.com wrote:
 is there a way to debug core modules like IO::Socket::INET?

Generally, you can copy a module out of the core settings and run from source: 
the module in source will hide the one from the settings.

Is that what you mean?



Liz

Re: Object Contruction

2015-03-18 Thread Elizabeth Mattijsen
 On 18 Mar 2015, at 23:21, Tom Browder tom.brow...@gmail.com wrote:
 
 You are correct, Liz, but I was trying those pieces to demonstrate to myself 
 that all was available to me in the methods and all worked as I expected.
 
 It demos very roughly what I think I have to do to translate Geo::Ellipsoid 
 to Perl 6.  It's a WIP and I'm learning Perl 6 as I go.  The prog is a toy 
 and not otherwise useful.
 
 Thanks.
 
 BTW, will you or any other Perl 6 people be presenting at YAPC::NC?  I don't 
 see a speaking line-up yet.

YAPC::NC  ??  You mean YAPC::NA?

I will be there, but haven’t had any inspiration for a presentation just yet.




Liz

Re: Object Introspection for Existence of Methods: How?

2015-03-23 Thread Elizabeth Mattijsen
 On 23 Mar 2015, at 14:11, Tom Browder tom.brow...@gmail.com wrote:
 On Mon, Mar 23, 2015 at 7:04 AM, Tom Browder tom.brow...@gmail.com wrote:
 From your and Henk's comments, I think I need to learn a lot more about
 testing in general.
 Any recommendations for books on the subject?

Perl Testing - A Developer’s notebook:

http://shop.oreilly.com/product/9780596100926.do


Liz

Re: Object Contruction

2015-03-18 Thread Elizabeth Mattijsen
 On 18 Mar 2015, at 21:32, Tom Browder tom.brow...@gmail.com wrote:
 On Wed, Mar 18, 2015 at 11:32 AM, Tom Browder tom.brow...@gmail.com wrote:
 On Wed, Mar 18, 2015 at 7:22 AM, Moritz Lenz mor...@faui2k3.org wrote:
 ...
 http://doc.perl6.org/language/objects#Object_Construction lists at least two
 possible ways. Probably the most interesting one is BUILDALL with a
 callsame; see the last example (or example skeleton) in that section.
 
 For my purposes I think the BUILD is best.  The BUILDALL method seems
 to put me in limbo as far as the constructed object and using self.
 
 I made a simple class and a driver Perl script:
 
 $ cat T.pm HERE_PM
 class T;
 
 has $.a is rw;
 has $.b is rw;
 has $.c is rw;
 
 submethod BUILD(
 # set defaults here
 :$!a = 15,
 :$!b,

Why not set the default here?

  :$!b = $!a  10 ?? 1 !! 0;

 :$!c,
  ) {
  self.set_b;

Then you won’t need this.

 }
 
 multi method set_b {
  if (self.a  10) {
self.b = 1;
  }
  else {
self.b = 0;
  }
 }

Nor this.

 multi method set_b($x) {
  self.b = $x;
 }

Nor this.

 HERE_PM
 
 $ cat T.pl HERE_PL
 #!/usr/bin/env perl6
 
 use v6;
 use lib '.';
 use T;
 my $t = T.new;
 say \$t.a = {$t.a};
 say \$t.b = {$t.b};
 say \$t.c = {$t.c.defined ?? $t.c !! 'undefined'};
 $t.set_b(20);

This would then just be:

  $t.set(20);

 $t.c = 'defined';
 say \$t.a = {$t.a};
 say \$t.b = {$t.b};
 say \$t.c = {$t.c.defined ?? $t.c !! 'undefined'};
 HERE_PM
 
 $ perl6 T.pl
 $t.a = 15
 $t.b = 0
 $t.c = undefined
 $t.a = 15
 $t.b = 20
 $t.c = defined


Liz

Re: Books on Perl 6

2015-04-19 Thread Elizabeth Mattijsen
 On 19 Apr 2015, at 19:16, Parrot Raiser 1parr...@gmail.com wrote:
 
 Apress have some books about Perl 6,
 http://www.apress.com/catalogsearch/result/?q=perl+6submit=Go but
 their dates of publishing, (c 2006) make me suspect that they are
 probably outdated to the point of being misleading.
 
 Is anyone sufficiently familiar with bot Perl 6 and the books to comment?

They’re outdated.  And misleading.

And I think at least one of them never made it to print anyway.



http://doc.perl6.org is the place to be until we really have a good book with a 
Perl 6 introduction.



Liz

Re: Scheduler problem with scheduled events

2015-05-02 Thread Elizabeth Mattijsen
 On 01 May 2015, at 13:57, mt1957 mt1...@gmail.com wrote:
 Reading though synopsis S17 concurrency I tried the following
 
 $*SCHEDULER.cue: in=10, { say 10s later }
 
 which will deliver the string after 10 seconds. However the moar will work 
 like hell at a 100% cpu time before and afterwards! Removing the option 'in' 
 didn't show this problem.
 
 Another option will show the same problem in the following code.
 
 my $c = $*SCHEDULER.cue: :every(1), { say Oh wow, a kangaroo! };
 sleep 10;
 $c.cancel;
 
 Canceling will stop the output of kangaroos but moar will keep on doing its 
 thing at about 100% cpu time. I didn't found an option or method to stop that 
 thread.

Thank you for reporting.  Yes, this is a known issue, potentially of the 
underlying libuv system.

BTW, it is generally thought not to be a good idea to directly call the 
scheduler directly like that. You probably want to use the Promise.in or the 
Supply.interval functionality to achieve the same effect.  And the same bug.  
Well, for now then.




Kind regards,

Liz

Re: Will Perl 6 save a compiled version of a source program like Python?

2015-05-18 Thread Elizabeth Mattijsen
 On 18 May 2015, at 14:28, Tom Browder tom.brow...@gmail.com wrote:
 
 I found some discussion of such a capability on the Perl Mongers' site but 
 haven't found anything official yet in the Synopses. 
 
 But I did find there an option that might do something related: 
 --output-format (which is implementation defined).  However, I do not see 
 that option in Rakudo Perl 6.
 
 Can anyone point me to more info or say yes or no to possible support of a 
 save-compilation feature?

A large part of Perl 6 is written in Perl 6.  This currently consists of about 
28000 lines of code.  This code is pre-compiled, so that it can be loaded in 
just over .1 second.

This pre-compilation is a normal part of the install process of *any* module if 
you’re using either rakudobrew or panda.

The compiled version differs by VM backend.  If JVM is the backend, the 
compiled version is stored as a standard .jar.  On MoarVM, it has the extension 
.moarvm, and has its own version.

The compiled version is also, one can say, “statically linked” as it were to 
the version of Rakudo that compiled it.  So if you upgrade rakudo, new compiled 
versions need to be created.  This is also part of rakudobrew and the panda 
rebootstrap process.


Hope this answers your question.



Liz

Re: Passing a hash to a subroutine: best method?

2015-07-03 Thread Elizabeth Mattijsen
 On 03 Jul 2015, at 17:26, Tom Browder tom.brow...@gmail.com wrote:
 
 While experimenting I've found the first two methods of passing a hash
 to a subroutine work:
 
 # method 1
 my %hash1;
 foo1(%hash1);
 say %hash1.perl;
 sub foo1(%hash) {
  %hash{1} = 0;
 }
 
 # method 2
 my %hash2;
 my $href2 = %hash2;
 foo2($href2);
 say %hash2.perl;
 sub foo2($href) {
  $href{1} = 0;
 }

Whatever you like best of these two methods.  A hash is an object, and as such 
doesn’t get flattened when you pass it as a parameter to a sub (unlike Perl 5).


 # this is what I naively tried first
 # method 3 [DOESN'T WORK]
 my %hash3;
 my $href3 = \%hash3;
 foo3($href3);
 say %hash3.perl;
 sub foo3($href) {
  %($href}){1} = 0;
 }

The \ creates a so-called Capture.  Unless you really know what you’re doing, I 
would say, don’t do that.  Everything in Perl 6 is already an object that you 
can pass along without fear of it getting flattened.


Liz

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(:<,>) { %(|$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

Re: questions about qw<>

2015-10-13 Thread Elizabeth Mattijsen
> On 13 Oct 2015, at 20:21, Marc Chantreux <kha...@phear.org> 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: What are Perl 6's killer advantages over Perl 5?

2015-08-26 Thread Elizabeth Mattijsen
 On 26 Aug 2015, at 12:18, H.Merijn Brand h.m.br...@xs4all.nl wrote:
 
 On Wed, 26 Aug 2015 10:26:23 +0200, Moritz Lenz mor...@faui2k3.org
 wrote:
 
 I could continue with other Perl 5 deficiencies (no strict by default,
 
 Using strict *STILL* is not enabled by default for perl6
 one-liners either:

It used to be, but that was not according to spec.  FROGGS++ implemented the 
lax mode, which is enabled by default in one-liners.  Perhaps TimToady wants to 
invoke rule #2 on this.


Personally, I use an alias that has ‘-M strict’ in it.



Liz

Re: Strict Rakudo version of this Perl5 one-liner

2015-09-02 Thread Elizabeth Mattijsen
> On 02 Sep 2015, at 14:02, Matija Papec  wrote:
> 02.09.2015, 10:46, "The Sidhekin" :
>>>  So it seems that perl6 handles lexicals inside while (<>){} one-liners 
>>> differently.
>> 
>>Ah, yes.  Interesting.  Run-time effect of C not happening 
>> repeatedly.  How would that deparse?
> 
> 
> Good question, I wouldn't be surprised that -n switch has some kind of 
> special behavior.
> 
> 
>>  $ seq 3 | perl6 -e 'for lines() { my %d; %d{$_}++; END { say keys %d } }'
>>  3
>>  $ seq 3 | perl6 -e 'for lines() { state %d; %d{$_}++; END { say keys %d } }'
>>  1 2 3
>>  $
>> 
>>… and while I'm comparing:
>> 
>>  $ seq 3 | perl6 -e 'for lines() { my %d; %d{$_}++; END { say keys %d } }'
>>  3
>>  $ seq 3 | perl -E 'while (<>) { my %d; $d{$_}++; END { say keys %d } }'
>>  1
>> 
>>… I need me a new mental model. :-)
> 
> I think this is covered somewhere in RFC; perl6 repeatedly overwrites END{} 
> block where last one references last %d definition (say %d.WHICH).
> perl5 on the other hand stays with first END{} block (say \%d).

A much shorter way, using Perl 6 features:

  $ seq 3 | perl6 -e ‘lines.Set.keys.say’

lines() reads lazily from STDIN and chomps them
Set is a coercer that turns the input into a Set
then take the keys of the set and show them






Liz

Re: How to push a hash on an array without flattening it to Pairs?

2015-09-26 Thread Elizabeth Mattijsen
> On 26 Sep 2015, at 13:09, Aristotle Pagaltzis  wrote:
> * Moritz Lenz  [2015-09-26 09:40]:
>> A trailing comma helps:
>> 
>> my %h = a => 1, b => 2;
>> my @a = %h, ;
>> say @a.perl;# [{:a(1), :b(2)},]
> 
> I think I understand why, but wow, that’s not reasonable. Is there
> really no better way to avoid the flattening? Even Perl 5 is nicer
> in that situation…

There is: you just need to itemize the hash, e.g. by prefixing it with $

$ 6 'my %h = a => 42, b => 666; my @a = $%h; dd @a'
Array @a = [{:a(42), :b(666)},]

This is the one argument rule at work.


The flattening will not be done if more than one argument is specified:

$ 6 'my %h = a => 42, b => 666; my @a = %h,%h; dd @a'
Array @a = [{:a(42), :b(666)}, {:a(42), :b(666)}]


This is the same behaviour as with for:

$ 6 'my %h = a => 42, b => 666; dd $_ for %h'
:a(42)
:b(666)

$ 6 'my %h = a => 42, b => 666; dd $_ for %h,%h'
Hash %h = {:a(42), :b(666)}
Hash %h = {:a(42), :b(666)}


It’s the same rule throughout  :-)


Liz

Re: require on string stopped working in rakudo 2015.09

2015-09-26 Thread Elizabeth Mattijsen
> On 26 Sep 2015, at 06:47, Gabor Szabo  wrote:
> I am really glad Rakudo finally came out.
> I've installed in and tried to run the tests of Perl6::Maven.
> 
> They quickly failed as I have been using 'require' on string
> to check if all the module compile properly.
> 
> The following code now fails:
> 
> use v6;
> my $name = 'Bailador';
> require $name;
> 
> 
> even though
> 
> require Bailador;
> 
> works.
> 
> In 2015.07 both worked.
> 
> 
> I've fixed my script by switching to EVAL "use $module";
> but I wonder if this is a regression or a planned deprecation?

I’m not sure yet.

Could you please rakudobug it so that it doesn’t fall through the cracks?  This 
change did not fire any spectest alarm either, so maybe we need a test for it 
as well  :-)



Liz

Re: How to push a hash on an array without flattening it to Pairs?

2015-09-26 Thread Elizabeth Mattijsen
> On 26 Sep 2015, at 14:26, Aristotle Pagaltzis <pagalt...@gmx.de> wrote:
> * Elizabeth Mattijsen <l...@dijkmat.nl> [2015-09-26 13:20]:
>> There is: you just need to itemize the hash, e.g. by prefixing it with $
>> 
>> $ 6 'my %h = a => 42, b => 666; my @a = $%h; dd @a'
>> Array @a = [{:a(42), :b(666)},]
>> 
>> This is the one argument rule at work.
> 
> Aha! Much better. Explicit. “Don’t subject %h to flattening.”
> 
> No need to combine two other unrelated rules to bend around invoking the
> undesired rule; just directly saying not to invoke it.
> 
> Now of course I must ask – is there an opposite also? I.e. when writing
> a list, is there a way I can say “do flatten this item?” Or put in other
> words, what goes in place of XXX in the following to make it real?
> 
>$ 6 'my %h = a => 42, b => 666; dd $_ for %h,XXX'
>Hash %h = {:a(42), :b(666)}
>:a(42)
>:b(666)

moritz++ already mentioned it:

$ 6 'my %h = a => 42, b => 666; dd $_ for |%h,|%h'
:a(42)
:b(666)
:a(42)
:b(666)

Prefix | is a short way to Slip something :-)



Liz

Re: Constants as members of a class

2015-12-18 Thread Elizabeth Mattijsen

> On 18 Dec 2015, at 03:46, TS xx  wrote:
> 
> Hello dear perl6 users,
> 
> I was in the need of declaring a member variable as a constant integer. After 
> many syntax tryouts I came to this one:
> 
> class MyClass {
> has int $.myConst;
> 
> method new () {
> return self.bless();
> }
> 
> submethod BUILD () {
> constant $!myConst = 1;
> }
> 
> method showMyConst () {
> print $!myConst;
> }
> }
> 
> But I'm getting the followinf error message: "Twigil-Variable constants not 
> yet implemented. Sorry."
> 
> The only place in the docs where I have found any reference to constants is 
> in here: https://doc.perl6.org/language/variables#The_%3F_Twigil
> But it's not what I am looking for :/
> 
> So my questions are:
> Is the syntax right and the thing isn't implemented yet?
> Is the syntax (or the full concept) wrong?
> Do I have and old interpreter (This is perl6 version 2015.02 built on MoarVM 
> version 2015.02)?

Yes, that is ancient in rakudo years  :-)

The question you should ask you: is the constant different for each 
instantiated object or not.

If not, and you only need it inside of your class, you can just make it a 
constant in the mainline of the class:

class MyClass {
constant FOO = 42;
…
}

If you need to expose a method returning such a constant:

class MyClass {
method FOO { 42 }
…
}

Otherwise, you probably just need to add an attribute.



Liz

Re: Perl6 build failure on Ubuntu 14.04, 32-bit

2015-12-23 Thread Elizabeth Mattijsen
> On 23 Dec 2015, at 18:32, Tom Browder  wrote:
> 
> On Wed, Dec 23, 2015 at 10:38 AM, Steve Mynott  wrote:
>> That looks like you don't have enough virtual memory (the physical
>> memory assigned to your VM and swap within it) should be at least 2GB
>> (maybe even more).
> 
> Thanks, Steve--I wasn't very bright, was I!
> 
> I have increased the VM guest's RAM and will report back with success, I'm 
> sure.
> 
> BTW, will that RAM be required always for Perl 6, or just during the
> installation?

Just during compilation really.

FWIW, a null program (like “perl6 -e ’sleep 20’) takes about 45MB on my OS X 
machine.



Liz

Re: Constants as members of a class

2015-12-18 Thread Elizabeth Mattijsen
> On 18 Dec 2015, at 23:37, TS xx  wrote:
> 
> Hi Liz, thanks for your reply.
> 
> Can I call the method from static context?
> I mean: MyClass.FOO

In general, yes:

class A {
method FOO { 42 }   # note the method doesn’t reference any attributes
}
say A.FOO;
say A.new.FOO;  # also works on instances

You can even have a method to be called in case of a static (class) context, 
and one to be called in the case of an instance:

class B {
has $.FOO = 666;
multi method FOO(B:U:) { 42 } # B is the class, :U is undefined, final 
: for self
multi method FOO(B:D:) { $!FOO }  # :D is defined, 
}
say B.FOO; # 42
say B.new.FOO; # 666
say B.new(FOO => 3.14).FOO;# 3.14


Hope this helps!



Liz

Re: '!' versus 'not' in boolean expression

2016-01-18 Thread Elizabeth Mattijsen

> On 18 Jan 2016, at 19:55, Tom Browder  wrote:
> 
> In creating some new Perl 6 programs I've run across several instances
> I'm confused about, to wit:
> 
> Example 1
> ---
> 
>> my %h; say 'false' if !%h:exists;
> Unexpected named parameter 'exists’ passed

Yeah, this is an unexpected one.  However, there is a simple solution:

  my %h; say 'false' if %h:!exists;

In general, :foo is equivalent to foo => True, and :!foo is equivalent to foo 
=> False.


> Example 2
> ---
> 
>> my %h; say 'false' if not %h:exists;
> false
> 
> It looks like '!' doesn't work as I thought it was supposed to.  But,
> I just discovered that when I use parens, it works.

Yes, the ! binds closer, and eats the :exists, and then complains about it.



Liz

2016.5,6 Rakudo Starring

2016-02-09 Thread Elizabeth Mattijsen
A new Perl 6 Weekly can be found at

   https://p6weekly.wordpress.com/2016/02/08/2016-56-rakudo-starring/


Liz


Re: A practical benchmark shows speed challenges for Perl 6

2016-02-03 Thread Elizabeth Mattijsen
> On 03 Feb 2016, at 14:59, Tom Browder  wrote:
> I use Perl for heavy duty text processing. A question on Perl Monks
> about Perl 5's handling of a large input file got me wondering how the
> two Perls compare at the moment.
> 
> I wrote a couple of simple programs, in both languages, to write and
> read a 10 Gb text file filled with identical 100-character lines. The
> reading programs counted total lines and characters of the input file.
> The results on my fastest host show that much optimization is still
> needed for Perl 6.
> 
> I compared read times for file sizes from one to 10 Gb in one-gigabyte
> increments and, in general, Perl 6 takes roughly 30 times longer than
> Perl 5.14 to read the same file.  So far I see no significant
> improvement in Rakudo 2016.01 over 2015.12, but the tests haven't
> quite finished yet.

Is the code available somewhere?  Would love to try some optimizations on it.



Liz


Re: Nice-to-have class methods

2016-01-27 Thread Elizabeth Mattijsen
> On 27 Jan 2016, at 14:00, Tom Browder  wrote:
> 
> Given so many handy methods for built-in classes, it would be nice to have a 
> couple of more for some, for instance:
> 
> IO:Path.stemname
>   Like basename except any suffix is removed

Seems like a nice idea.


> IO::Handle.say (or println)
>   Like print except with an added newline.

IO::Handle already has a .say ?

$ 6 '$*OUT.say("hello world")'
hello world


Liz

Re: A practical benchmark shows speed challenges for Perl 6

2016-03-30 Thread Elizabeth Mattijsen
> On 30 Mar 2016, at 16:06, yary <not@gmail.com> wrote:
> 
> Cross-posting to the compiler group-
> 
> On Wed, Mar 30, 2016 at 8:10 AM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
>> If you know the line endings of the file, using 
>> IO::Handle.split($line-ending) (note the actual character, rather than a 
>> regular expression) might help.  That will read in the file in chunks of 64K 
>> and then lazily serve lines from that chunk.
> 
> This reminds me of a pet peeve I had with p5: Inability to easily
> change the default buffer size for reading & writing.
> 
> I'm the lone Perl expert at $work and at one point was trying to keep
> a file processing step in perl. These files were about 100x the size
> of the server's RAM, consisted of variable-length newline-terminated
> text, the processing was very light, there would be a few running in
> parallel. The candidate language, C#, has a text-file-reading object
> that lets you set its read-ahead buffer on creation/opening the file-
> can't remember the details. That size had a large impact on the
> performance of this task. With perl... I could not use the
> not-so-well-documented IO::Handle->setvbuf because my OS didn't
> support it. I did hack together something with sysread, but C# won in
> the end due partly to that.
> 
> It seems this "hiding-of-buffer" sub-optimal situation is being
> repeated in Perl6: neither https://doc.perl6.org/routine/open nor
> http://doc.perl6.org/type/IO::Handle mention a buffer, yet IO::Handle
> reads ahead and buffers. Experience shows that being able to adjust
> this buffer can help in certain situations. Also consider that perl5
> has defaulted to 4k and 8k, whereas perl6 is apparently using 64k, as
> evidence that this buffer needs to change as system builds evolve.
> 
> Please make this easily readable & settable, anywhere it's implemented!

Thanks for your thoughts!

I’ve implemented $*DEFAULT-READ-ELEMS in 
https://github.com/rakudo/rakudo/commit/5bd1e .

Of course, all of this is provisional, and open for debate and bikeshedding.


Liz

Re: A practical benchmark shows speed challenges for Perl 6

2016-03-31 Thread Elizabeth Mattijsen
> On 31 Mar 2016, at 09:50, Jan Ingvoldstad <frett...@gmail.com> wrote:
> 
> On Wed, Mar 30, 2016 at 9:20 PM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> 
> Thanks for your thoughts!
> 
> I’ve implemented $*DEFAULT-READ-ELEMS in 
> https://github.com/rakudo/rakudo/commit/5bd1e .
> 
> Of course, all of this is provisional, and open for debate and bikeshedding.
> 
> 
> Brilliant and brilliantly quick response, Liz!
> 
> In the spirit of bikeshedding, my first thought is that the variable name 
> should have something with BUFFER in it, as that is what it appears to be. :)
> 
> Functionally, it's nice to be able to set it via the environment, but since 
> the environment may not necessarily be controlled by the programmer, I 
> consider that to be a short term solution.
> 
> A longer term solution would be for a way to set it within the program that 
> the environment cannot override.
> 
> Additionally, there could also be a default, compile-time option for Rakudo.
> 
> 
> The reasoning behind _not_ setting things via environment variables, is that 
> this means the programmer now needs to worry what e.g. the webserver running 
> the Perl program does, and there are unknown stability (and possibly 
> security) implications. This adds bloat to the program.
> 
> The programmer is better off if they only explicitly need to worry about it 
> when they want to change the defaults.

The environment variable is only used if there is no dynamic variable found.  
So, if a programmer wishes to use a specific buffer size in the program, they 
can.



Liz



Re: A practical benchmark shows speed challenges for Perl 6

2016-03-30 Thread Elizabeth Mattijsen
> On 30 Mar 2016, at 13:40, Tom Browder  wrote:
> On Tue, Mar 29, 2016 at 10:29 PM, Timo Paulssen  wrote:
>> On 03/30/2016 03:45 AM, Timo Paulssen wrote:
>> 
>> Could you try using $filename.IO.slurp.lines instead of $filename.IO.lines
>> and see if that makes things any faster?
> ...
>> Actually, the method on an IO::Handle is called "slurp-rest"; slurp would
>> only work with a filename instead.
>>  - Timo
> Timo, I'm trying to test a situation where I could process every line
> as it is read in.  The situation assumes the file is too large to
> slurp into memory, thus the read of one line at a time.  So is there
> another way to do that?  According to the docs "slurp-rest" gets all
> the remaining file at one read.

That is correct.

The thing is that IO.lines basically depends on IO.get to get a line.  So that 
is extra overhead, that IO.slurp.lines doesn’t have.

If you know the line endings of the file, using IO::Handle.split($line-ending) 
(note the actual character, rather than a regular expression) might help.  That 
will read in the file in chunks of 64K and then lazily serve lines from that 
chunk.

A simple test on an /etc/dict/words:

$ 6 '"words".IO.lines.elems.say'
235886
real0m0.645s

$ 6 '"words".IO.open.split("\x0a").elems.say'
235887
real0m0.317s

Note that with .split you will get an extra empty line at the end.


Hope this helps.


Liz

Re: A practical benchmark shows speed challenges for Perl 6

2016-04-01 Thread Elizabeth Mattijsen
> On 01 Apr 2016, at 13:50, Jan Ingvoldstad <frett...@gmail.com> wrote:
> 
> On Thu, Mar 31, 2016 at 10:36 AM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> > The reasoning behind _not_ setting things via environment variables, is 
> > that this means the programmer now needs to worry what e.g. the webserver 
> > running the Perl program does, and there are unknown stability (and 
> > possibly security) implications. This adds bloat to the program.
> >
> > The programmer is better off if they only explicitly need to worry about it 
> > when they want to change the defaults.
> 
> The environment variable is only used if there is no dynamic variable found.  
> So, if a programmer wishes to use a specific buffer size in the program, they 
> can.
>  
> This is precisely _not_ addressing the issue I raised.
> 
> This way, the programmer _needs_ to explicitly check whether the environment 
> variable is set, and if not, somehow set a sensible default if the 
> environment variable differs from the default.
> 
> That adds quite a bit of unnecessary programming to each Perl program that 
> deals with buffers.
> The status as it was before, was that the programmer didn't need to worry 
> about the environment for buffer size.

Sorry if I wasn’t clear: If there is no dynamic var, it will make one: either 
from the environment, or set it to 64K (like it was before).  So no programmer 
action is ever needed if they’re not interested in that type of optimization.


> If a malicious environment sets the buffer size to something undesirable, 
> there may be side effects that are hard to predict, and may have other 
> implications than merely performance.
> 
> I think it is preferable that the decision about that is made by the 
> programmer rather than the environment.
> 
> PS: I'm assuming that $*DEFAULT-READ-ELEMS is clean by the time it reaches 
> any code, that is that it only contains _valid_ integer values and cannot 
> lead to overflows or anything, I am not concerned about that.

At the moment it is nothing but a balloon that I let go up in the air.  
Question is still out on whether this will continue to live until the next 
release, or that it will be replaced by something more low level, at the VM 
level.

If you put garbage in the environment, it will die trying to coerce that to an 
integer.


Liz



Re: Blobs and IEEE floating point

2016-04-19 Thread Elizabeth Mattijsen
> On 19 Apr 2016, at 12:03, Timo Paulssen  wrote:
> 
> On 19/04/16 01:58, Kevin Pye wrote:
>> […]
>> 2. Write a simple C function to take a pointer to a double and return
>> the double, put that into a shared library and then use NativeCall.
> 
>> […]
> 
> 
> Fortunately, you don't have to use a library with a custom function. You can 
> just use "nativecast" for this task.
> 
> That should also be a few hundred times faster than what BSON does, and it 
> also works for Int types.
> 
> You just might have to be careful with regards to endianness.

I’ve been looking at nativecast, but haven’t been able to find an example that 
I could apply to this?


Liz



Re: Blobs and IEEE floating point

2016-04-19 Thread Elizabeth Mattijsen
FWIW, I’ll take PR’s for the PackUnpack distribution to make ‘f’ and ‘d’ work  
:-)

> On 19 Apr 2016, at 07:28, JuhiMarcel LangbroekTimmerman  
> wrote:
> 
> Hi Kevin
> 
> I've made something up for the time being. You can find it in the BSON 
> module. Look for the file lib/Document.pm6 and the subs encode-double and 
> decode-double. This code must be rewritten though for speed but at least it 
> works.
> 
> Marcel
> 
> P.s. I've seen that not all comments in the program are correct, so take 
> care. The information about the process  can also be found on a wiki page
> 
> On April 19, 2016 1:58:12 AM Kevin Pye  wrote:
> 
>> Hi,
>> 
>> I have a several-thousand-line long Perl 5 script which I've been 
>> translating to Perl 6 over some time, and it runs fine, although a little 
>> slowly :-)
>> 
>> There is however one section which I haven't needed to use until recently, 
>> and which I've been avoiding translating because it's not all that easy. It 
>> takes a binary blob out of a database and then unpacks it into various 
>> structures.
>> 
>> This all works now, except that the blob contains several IEEE format 64-bit 
>> floating point numbers. The perl 5 code did a simple "unpack 'd', $buffer", 
>> but none of the various pack/unpack implementations I can find for Perl 6 
>> handle floating point yet.
>> 
>> I can see a couple of possible of possible solutions:
>> 
>> 1. Write perl code to rip apart the IEEE format and construct a new Real 
>> which has the same value as the original number; or
>> 
>> 2. Write a simple C function to take a pointer to a double and return the 
>> double, put that into a shared library and then use NativeCall.
>> 
>> The first isn't as bad as it looks because the numbers are all of limited 
>> range, and won't contain things like NaN and Inf so a general solution isn't 
>> needed. I'm guessing the second would run more quickly.
>> 
>> Any other ideas?
>> 
>> Kevin.



Re: Killer Features of Perl 6

2016-08-20 Thread Elizabeth Mattijsen

> On 20 Aug 2016, at 22:14, Tony Edwardson  wrote:
> In a few weeks I will be presenting a talk on a technical meeting for Milton 
> Keynes Perl Mongers and I have decided to try and sell the benefits of Perl 6 
> to a bunch of Perl 5 experts.
> I am interested in your opinion on which of the many features of Perl 6 are 
> the main reasons why anyone would migrate to Perl 6 from Perl 5.
> Any opinions greatly appreciated.

This is the text of the most up-to-date version of the Perl 6 Brochure that 
Wendy made:

https://wendyga.wordpress.com/2015/12/25/why-would-you-want-to-use-perl-6-some-answers/

Hope that helps  :-)


Liz

Re: debugging and HookGrammar

2017-02-28 Thread Elizabeth Mattijsen
> On 28 Feb 2017, at 22:28, Theo van den Heuvel <vdheu...@heuvelhlt.nl> wrote:
> Elizabeth Mattijsen schreef op 2017-02-28 20:29:
>> That was the consensus on the #perl6-dev channel:
>> https://irclog.perlgeek.de/perl6-dev/2017-02-28#i_14181744
>> Liz
> 
> I wasn't aware of this. Thanks

You’re welcome.

If you want more direct feedback, the #perl6 channel on irc.freenode.org is a 
good place to try as the first line.  #perl6-dev would be a place to check if 
the people on #perl6 don’t have an answer.



Liz

Re: for loop index question

2017-02-28 Thread Elizabeth Mattijsen
> On 28 Feb 2017, at 22:20, ToddAndMargo  wrote:
> 
> Hi All,
> 
> There are times when I want to know th4e index of an array
> when I am in a "for @array" loop.  I can do it with a
> variable outside the for loop and increment it, but
> I would line to know know if there is a way to incorporate
> it in the loop command.
> 
> This is my long winded way of doing it in Perl 5:
> 
> while (my ($Index, $Element) = each ( @Sorted_List ) ) { do something }

use .kv:

$ 6 'my @a = ; for @a.kv -> $index,$value { dd $index, $value }'
Int $index = 0
Str $value = "a"
Int $index = 1
Str $value = "b"
Int $index = 2
Str $value = “c"

Mind you, you can actually chain that with your sort:

$ 6 'my @a = ; for @a.sort.kv -> $index,$value { dd $index, $value }'
Int $index = 0
Str $value = "a"
Int $index = 1
Str $value = "b"
Int $index = 2
Str $value = “c"

HTH,

Liz

Re: coded size limits on Perl data types?

2016-09-13 Thread Elizabeth Mattijsen
> On 13 Sep 2016, at 14:15, Timo Paulssen  wrote:
> 
> I'll answer based on the data structures MoarVM uses internally:
> 
> On 09/13/2016 05:13 AM, Darren Duncan wrote:
> 
> > (Pretend the actual hardware has infinite memory so we wouldn't run
> > out of hardware first.)
> > 
> > 1.  Maximum size of a (non-machine) integer?
> 
> 
> We're using libtommath, which declares the "used" and "alloc" fields of the 
> mp_int as "int", iow a 32bit signed (???) integer.

eh, but Int is supposed to be a bigint, only limited by memory, no?


Liz

Re: doubt about sequence operator

2016-10-10 Thread Elizabeth Mattijsen

> On 10 Oct 2016, at 14:22, Luca Ferrari  wrote:
> 
> Hi all,
> I'm misunderstanding the ... operator. The following works as expected:
> 
>@seq = ( 1, 2, -> $a, $b { $a * 2 + $b % 2 } ... * )[^10];
> 
> while the following seems to loop infinitely:
> 
>@seq = ( 1, 2, -> $a, $b { $a * 2 + $b % 2 } ... 10 );
> 
> Looking at  I
> cannot find an explaination of why the ending value of 10 is not
> honored in the second case.

If you’re using a Callable in the sequence operator, the end-point needs to 
match exactly:

$ 6 'say 1,4, { $^a + 3 } ... 10'
(1 4 7 10)

6 'say 1,4, { $^a + 3 } ... 11'
(1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 
82 85 88 91 94 97 100 103 106 109 112 115 118 121 124 127 130 133 136 139 142 
145 148 151 154 157 160 163 166 169 172 175 178 181 184 187 190 193 196 199 202 
205 208 211 214 217 220 223 226 229 232 235 238 241 244 247 250 253 256 259 262 
265 268 271 274 277 280 283 286 289 292 295 298 …)

The reason for it is because you *could* be devising a sequence that may 
actually exceed the end value temporarily:

$ 6 'say 1,4, { $^a > 10 ?? $^a - 1 !! $^a + 3 } ... 11'
(1 4 7 10 13 12 11)

It is explained here: 
https://docs.perl6.org/language/operators#index-entry-sequence_operator

Hope this helps.



Liz

Re: doubt about sequence operator

2016-10-10 Thread Elizabeth Mattijsen
> On 10 Oct 2016, at 14:22, Luca Ferrari  wrote:
> Looking at  I
> cannot find an explaination of why the ending value of 10 is not
> honored in the second case.

Oops, missed that you already referenced the doc:  It’s in this line, I believe:

"If the endpoint is not *, it is smart-matched against each generated element, 
and the sequence is terminated when the smart-match succeeded. For the ... 
operator, the final element is included, for the ...^ operator it is excluded.”


Liz

Re: subset problem

2016-09-16 Thread Elizabeth Mattijsen
That’s because (elem) will coerce its righthand side parameter to a Bag.  If 
the count in a Bag goes to 0, the element doesn’t exist, and therefore returns 
False.

> On 16 Sep 2016, at 23:17, Brandon Allbery  wrote:
> 
> 
> On Fri, Sep 16, 2016 at 5:04 PM, yary  wrote:
> Having (elem) return False when the value of a Map element is 0 confuses me.
> 
> Me too, I disliked it the moment you pointed it out. I think that behavior is 
> intended for Bags, I am not sure it has any business being in Sets.
> 
> 
> -- 
> brandon s allbery kf8nh   sine nomine associates
> allber...@gmail.com  ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net



Re: subset problem

2016-09-16 Thread Elizabeth Mattijsen
I can’t help but think this can all be solved by using enums?

my enum pv (  );
my pv $x = aa;


??

> On 16 Sep 2016, at 13:49, mt1957  wrote:
> 
> Hi everyone,
> 
> I am trying to create a subset but get errors when used. Surely I do 
> something wrong here or is it a bug?
> 
> In REPL
> 
> > my Map $p .= new(.kv.reverse);
> Map.new((:aa(4),:bb(5),:d(0),:f(1),:ff(6),:g(2),:h(3)))
> > subset pv of Str where $_ (elem) $p;
> (pv)
> > my pv $x = 'aa';
> Type check failed in assignment to $x; expected pv but got Str ("aa")
>  in block  at  line 3
> 
> 
> Greetings,
> 
> Marce
> 



Re: Startup performance on OS X

2016-10-03 Thread Elizabeth Mattijsen
> On 02 Oct 2016, at 11:00, Thor Michael Støre  wrote:
> Is this normal startup performance?

https://www.promptworks.com/blog/public-keys-in-perl-6

I wonder what would be needed to run this in Perl 5, module wise, and CPU wise.



Liz

Re: Initializing a CStruct attribute of a CStruct

2016-10-03 Thread Elizabeth Mattijsen
recently, jnthn fixed a bug in attribute binding of natives in signatures, so 
you should now be able to say:

  submethod BUILD(uint64 :$!c, test1 :$!d) { }  # should work, but doesn't

which in turn begs the question why you would need the BUILD anyway.  But 
indeed it looks like you need to do the binding yourself.

  submethod BUILD(uint64 :$!c, test1 :$d) { $!d := $d }  # works, but shouldn’t 
be necessary


Please rakudobug this (by sending an email to rakudo...@perl.org).


Thanks!


Liz

> On 03 Oct 2016, at 14:50, Fernando Santagata  
> wrote:
> 
> Looks like the solution is declaring the parameter type in the BUILD 
> submethod. This one works fine:
> 
> use NativeCall;
> 
> class test1 is repr('CStruct') is export {
>   has uint64  $.a;
>   has uint64  $.b;
> }
> 
> class test2 is repr('CStruct') is export {
>   has uint64  $.c;
>   has test1   $.d;
>   submethod BUILD(uint64 :$c, test1 :$d){
> $!c = $c;
> $!d := $d;
>   }
> }
> 
> my test2 $t2 .= new(:3c, d => test1.new(:1a :2b));
> dd $t2;
> 
> On Sat, Oct 1, 2016 at 10:34 AM, Fernando Santagata 
>  wrote:
> Hello,
> 
> I'm trying to do something complex (at least for me :-) with NativeCall.
> 
> Let's start with plain Perl6. This:
> 
> class test1 {
>   has Int  $.a;
>   has Int  $.b;
> }
> 
> class test2 {
>   has Int   $.c;
>   has test1 $.d;
> }
> 
> my test2 $t2 .= new(:3c, d => test1.new(:1a :2b));
> dd $t2;
> 
> outputs:
> 
> test2 $t2 = test2.new(c => 3, d => test1.new(a => 1, b => 2))
> 
> But I need to do that with CStructs. This code:
> 
> use NativeCall;
> 
> class test1 is repr('CStruct') is export {
>   has uint64  $.a;
>   has uint64  $.b;
> }
> 
> class test2 is repr('CStruct') is export {
>   has uint64  $.c;
>   has test1   $.d;
> }
> 
> my test2 $t2 .= new(:3c, d => test1.new(:1a :2b));
> dd $t2;
> 
> doesn't really work and outputs this:
> 
> Cannot modify an immutable test1
> 
> Adding a BUILD submethod isn't enough:
> 
> submethod BUILD(:$!c, :$!d) { }
> 
> What I get is:
> 
> CStruct can't perform boxed get on flattened attributes yet
> 
> and this:
> 
> submethod BUILD(:$c, :$d){
>   $!c = $c;
>   $!d := $d;
> }
> 
> doesn't work either:
> 
> Can only store CStruct attribute in CStruct slot in CStruct
> 
> But this one does:
> 
> submethod BUILD(:$c, :$d){
>   $!c = $c;
>   $!d := test1.new(a => $d.a, b => $d.b);
> }
> 
> Only, I don't want to initialize all the attributes one by one...
> Is there a less cumbersome way to do that initialization?
> 
> Thanks!
> 
> -- 
> Fernando Santagata
> 
> 
> 
> -- 
> Fernando Santagata



Re: Startup performance on OS X

2016-10-03 Thread Elizabeth Mattijsen
$ time install/bin/nqp -e ''

real0m0.025s
user0m0.017s
sys 0m0.006s

Liz

> On 03 Oct 2016, at 12:45, Brock Wilcox <awwa...@thelackthereof.org> wrote:
> 
> It seems like Moose vs built-in-oop/mop is a very indirect comparison. Now 
> I'm wondering what nqp or moarvm startups are like.
> 
> 
> On Oct 3, 2016 06:14, "Elizabeth Mattijsen" <l...@dijkmat.nl> wrote:
> > On 02 Oct 2016, at 11:00, Thor Michael Støre <thormich...@gmail.com> wrote:
> >
> > Hey everyone!
> >
> > Is this normal startup performance?
> >
> >
> > Thormicks-MacBook-Pro-3:~ thormick$ time perl6 -e "say 'foo'"
> > foo
> >
> > real  0m0.444s
> > user  0m0.166s
> > sys   0m0.067s
> > Thormicks-MacBook-Pro-3:~ thormick$ time perl6 -e "say 'foo'"
> > foo
> >
> > real  0m0.202s
> > user  0m0.148s
> > sys   0m0.044s
> > Thormicks-MacBook-Pro-3:~ thormick$ time perl6 -e "say 'foo'"
> > foo
> >
> > real  0m0.205s
> > user  0m0.150s
> > sys   0m0.045s
> > Thormicks-MacBook-Pro-3:~ thormick$ perl6 -version
> > This is Rakudo version 2016.07.1 built on MoarVM version 2016.07
> > implementing Perl 6.c.
> >
> >
> > Foo indeed! ~200ms for this seems awfully slow to me.
> 
> FWIW, this is what I have on my MBP (2.8Ghz i7 Early 2013, SSD):
> 
> $ time perl6 -e "say 'foo'"
> foo
> 
> real0m0.122s
> user0m0.098s
> sys 0m0.023s
> 
> $ perl6 -version
> This is Rakudo version 2016.09-104-gc4c0718 built on MoarVM version 
> 2016.09-13-g34c375a
> implementing Perl 6.c.
> 
> 
> Wrt to Pm’s timing of perl 5 with Moose: if you actually want to have most of 
> Perl 6’s capabilities in Perl 5 with Moose, you will need to load quite a few 
> MooseX:: classes as well.  Which cannot have a positive effect on load time.
> 
> 
> 
> Liz



Re: serial communication over usb on linux

2017-01-02 Thread Elizabeth Mattijsen
> On 2 Jan 2017, at 23:49, Erik Colson  wrote:
> I'm considering to write a small IoT script in perl6.  For this I need
> serial communication as Perl5 has Device::SerialPort.  As this module
> has not (yet) been ported to perl6, I suppose I can achieve this with
> Inline-ing.  But of course, Perl6 can inline a lot of languages.
> 
> So: Which library would you use ?

How about starting with Inline::Perl5 and “use Device::SerialPort:from” ?


Liz

Re: write string requires an object with REPR MVMOSHandle

2017-03-29 Thread Elizabeth Mattijsen
> On 29 Mar 2017, at 12:36, Shlomi Fish  wrote:
> 
> On Wed, 29 Mar 2017 12:10:15 +0200
> Timo Paulssen  wrote:
> 
>> As part of the IOwesome grant, zoffix is going to fix this error. It's
>> what you get when you try to write to or read from or do anything with a
>> closed IO::Handle.
>> 
>> When you use "LEAVE:" you're just declaring a label called "LEAVE".
>> There are no labels with special function, so your code is equivalent to
>> 
>> sub save {
>>my $fh = open('data.txt', :w);
>>ohai: $fh.close;
>>$fh.print("hello\n");
>> }
>> 
>> so you're opening the file, closing the file, then writing to it. That
>> can't work, of course, but the error is also clearly LTA.
>> 
> 
> Hi Timo!
> 
> What does "LTA" stand for in this context? One thing I learned is to avoid
> acronyms as much as possible.

Less Than Awesome



Liz


Re: Failed to open file .. too many open files

2017-03-25 Thread Elizabeth Mattijsen
$file.IO.slurp and slurp($file) are basically the same.

$handle.slurp-rest does *not* close the handle, as another process might still 
be writing to it, so you could do another .slurp-rest.


To get back to your original code:

   get '/atom' => sub {
   my $path = $.meta ~ request.path;
   return open($path).slurp-rest;   
   }

I would write that as:

   get '/atom' => sub { slurp $.meta ~ request.path }

Should you wind up with an opened handle, could could use a LEAVE phaser to 
make sure the handle gets closed:

   get '/atom' => sub {
   LEAVE $.meta.handle.close;
   return $.meta.handle.slurp-rest;
   }

HTH,


Liz
=
> On 25 Mar 2017, at 17:12, Gabor Szabo  wrote:
> 
> Oh so you say that's indeed a bug in my code. That's a relief. Thanks!
> 
> 
> As I can see I had some $file.IO.slurp and some of the slurp-rest ones.
> 
> What is the difference between $file.IO.slurp and slurp($file) ?
> Is the latter just an alias for the former?
> 
> Gabor
> 
> 
> On Sat, Mar 25, 2017 at 4:54 PM, Timo Paulssen  wrote:
>> i highly suggest you slurp instead of open + slurp-rest, because that
>> will automatically close the file for you, too.
>> 
>> other than that, you can pass :close to the slurp-rest method and it'll
>> also close the file.
>> 
>> if you're not closing the files you're opening, you'll be relying on the
>> garbage collector to do file handle closing for you, which is
>> nondeterministic and a bad idea in general.
>> 
>> HTH
>>  - Timo


Re: Question for the developers on splice

2017-03-21 Thread Elizabeth Mattijsen
> On 21 Mar 2017, at 10:00, ToddAndMargo  wrote:
> on this command:
> 
> perl6 -e 'my @foo = ; @foo.splice(0,3); say @foo;'
> 
> Are you actually moving one set up data into another set's
> element/slot/index, or are you just rearranging the pointers
> to each element?

How is that important?

If you want to know what is faster: 3x shift or 1x splice, benchmark!   :-)



Liz


Re: RFE: throw an error on a single "="when used in an "if"

2017-03-18 Thread Elizabeth Mattijsen
(This time to the list)

> On 18 Mar 2017, at 10:19, ToddAndMargo  wrote:
> Request for Enhancement:
> 
> Would you consider throwing a compiler error on the following:
> 
> perl6 -e 'my $x=2;my $y=3; if $x = $y {say "yes";} else {say "no";}’
> yes

FWIW, I don’t think that will ever become a compile time error, but a warning 
may be in place.  Even although in Perl *5* this has been discussed at length 
and considered to be a feature rather than a bug or a trap.


> It should have two == signs if it is followed by a {do something}
> 
> This is the correct way:
> 
> $ perl6 -e 'my $x=2;my $y=3; if $x == $y {say "yes";} else {say "no";}'

In Perl 5 many people use the syntax to assign the value of a complicated 
expression to be useable inside the if statement:

 if (my $x = frobnicate(42)) {
 say $x
 }

In Perl 6, we have a different syntax for that, by using a pointy block:

 if frobnicate(42) -> $x {
 say $x
 }

Generally, in Perl 5 and Perl 6, when comparing against a constant, you could 
consider teaching yourself to always put the constant on the left-hand side:

 if 42 == $x

Should you then make a mistake, it will at least be obvious at runtime:

 $ 6 'my $x = 42; say "same" if 42 = $x'
 Cannot modify an immutable Int

One could argue this should be spotted at compile time.


HTH,

Liz

Re: maintainability and "or"

2017-03-21 Thread Elizabeth Mattijsen
> On 21 Mar 2017, at 12:38, ToddAndMargo  wrote:
> This is just one of those chatter posts.
> 
> To me, the holy grail of coding is maintainability,
> which is why I code in Top Down.
> 
> Code like below get my goat because I have to look
> at it several times before I realize what is going on
> 
> $Name.IO.f or $Name.IO.open(:w).close;
> 
> Basically the above says:
> 
>If the the first part of the logical OR passes,
>then don't bother testing the second part.  And
>if the second part of the Logical OR passes or
>fails, then "so what”.

FWIW, I agree with you.  I don’t like the use of and/or in this capacity.  But 
many people swear by it.  To each its own.


> I'd much rather see
>  if not $PathAndName.IO.f { $PathAndName.IO.open(:w).close; }
> 
> Which to me says:
> 
>If this does not pass, then do something about it.
> 
> To me, it is much more maintainable.

And then there is the postfix if/unless way, which I personally like:

  $PathAndName.IO.open(:w).close unless $PathAndName.IO.f;

Which to me reads:

  Create the file unless it already exists.


Liz

Re: Associative collection with automatic keys?

2017-04-04 Thread Elizabeth Mattijsen
> On 4 Apr 2017, at 11:31, Trey Ethan Harris  wrote:
> 
> I'm thinking of a Hash-like collection where I can add objects using a 
> index-less append operation, but then have random access to the elements 
> based on a key provided by the object. (For instance, imagine a ProcessTable, 
> where I create the collection telling it to index by the .pid method, add 
> each process to %table in serial without mentioning pid, and then look up the 
> one referring to the interpreter with %table{$*PID}.)

This is basically the approach that object hashes take internally.  So, feels 
to me you just need object hashes?

   https://docs.perl6.org/type/Hash#index-entry-object_hash

Objects are internally keyed to the result of the .WHICH method on that object. 
 If you create a class, one will be provided for you automatically.  But 
there’s nothing preventing you from making your own .WHICH method, as long as 
the result is consistent for a given object and the same for all objects you 
think should be considered identical, you should be fine.


> I really thought this was in Perl 6, but I can't find it in the docs, so 
> maybe I'm thinking of another language. (I think both Ruby and Python have 
> adverbial-like options to do things like this with dictionaries, so maybe 
> that's what I'm thinking of.) Or maybe it's a simple tweak to an existing 
> collection, or just something I need to implement in my element objects

If this is not what you’re looking for, perhaps you can elaborate a bit more, 
with some code examples?



Liz

Re: I need help with pattern matching

2017-03-13 Thread Elizabeth Mattijsen

> On 13 Mar 2017, at 08:27, ToddAndMargo  wrote:
> 
> Hi All,
> 
> What am I doing wrong here?
> 
> $ perl6 -e 'my $x="abc\(123\)def"; $x ~~ m/(abc\))(123)(\(def)/; say 
> "$x\n\$0=<$0>  \$1=<$1>  \$2=<$2>\n";'
> 
> Use of Nil in string context
>  in block  at -e line 1
> Use of Nil in string context
>  in block  at -e line 1
> Use of Nil in string context
>  in block  at -e line 1
> 
> abc(123)def
> $0=<>  $1=<>  $2=<>

You escaped the parens around (123) incorrectly:

$ 6 'my $x="abc\(123\)def"; $x ~~ m/(abc)\((123)\)(def)/; say "$x\n\$0=<$0>  
\$1=<$1>  \$2=<$2>\n"'
abc(123)def
$0=  $1=<123>  $2=


Liz

Re: preassigned names in pattern matches?

2017-03-14 Thread Elizabeth Mattijsen
> On 14 Mar 2017, at 02:04, ToddAndMargo <toddandma...@zoho.com> wrote:
> On 03/13/2017 02:21 PM, Elizabeth Mattijsen wrote:
>>> On 13 Mar 2017, at 22:17, ToddAndMargo <toddandma...@zoho.com> wrote:
>>> I adore this feature of loops:
>>> 
>>> perl6 -e 'my @x=qw[a b z y];
>>>  for @x -> $a, $b { say "<$a> <$b>" };'
>>> 
>>>  
>>>  
>>> 
>>> 
>>> because I can preassign a names to "$_".
>>> 
>>> Question:  in a pattern match such as:
>>> 
>>> perl6 -e 'my $x="ab12cd";
>>>  $x ~~ m/(ab)(12)(cd)/;
>>>  say "$x\n\$0=<$0>\t\$1=<$1>\t\$2=<$2>\n";'
>>> 
>>> ab12cd
>>> $0= $1=<12> $2=
>>> 
>>> Is there a similar way to preassign names to
>>> "$0", "$1", "$2" ?
>> 
>> $/[$n]
> The answer is "no" to predefined variables, but as
> Liz points out, there is a bit of a work around:
> 
> Note: the name of the variable is $ not $a
> 
> perl6 -e 'my $x="ab12cd"; $x ~~ m/$=(ab) $=(12) $=(cd)/;
>   say "$x\n\$a=<$>\t\$b=<$>\t\$c=<$>\n";'
> 
> ab12cd
> $a=   $b=<12> $c=
> 
> I might be more readable to stick with $0, etc, as
> you have to assign the <> variables to predefined
> variables anyway

You can also slice $/:

$ 6 'my $x=“ab12cd”; say "$” if $x ~~ m/$=(ab) $=(12) 
$=(cd)/'
ab 12 cd

Please note that I put the slice between double quotes, otherwise you will see 
the gist of Match objects:

$ 6 'my $x=“ab12cd”; say $ if $x ~~ m/$=(ab) $=(12) $=(cd)/'
(「ab」 「12」 「cd」)


HTH


Liz

Re: What to do when a pattern match fails

2017-03-13 Thread Elizabeth Mattijsen

> On 13 Mar 2017, at 22:06, ToddAndMargo  wrote:
> 
> Hi All,
> 
> $ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say "$x\n\$0=<$0>\n";'
> Use of Nil in string context in block  at -e line 1
> ab12cd
> $0=<>
> 
> With out the "q" in this, it works.  I deliberately put
> the "q" to see what would happen when a patter was not
> found.
> 
> Is there a way around the "use of nil" finger wag
> if a patter is not found?

The Nil is not caused by the smart match, but from your attempt to display the 
first positional capture (aka $0) of a match that failed.


> Or should I always test for its presence first if
> there is a possibility the pattern might not exist?

You should test whether the smart match was successful.

my $x="ab12cd"; say "$x\n\$0=<$0>\n” if $x ~~ m/ab(1q2)cd/;



Liz

Re: debugging and HookGrammar

2017-02-28 Thread Elizabeth Mattijsen
That was the consensus on the #perl6-dev channel:

https://irclog.perlgeek.de/perl6-dev/2017-02-28#i_14181744


Liz

> On 28 Feb 2017, at 15:24, Theo van den Heuvel  wrote:
> 
> Hi Will,
> 
> I reinstalled without rakudobrew. It helped. I will probably never know what 
> I did wrong with rakudobrew (possible traces of an older install).
> 
> thanks,
> 
> Theo
> 
> Will Coleda schreef op 2017-02-28 14:37:
>> FYI, rakudobrew is not recommend for users.
>> You could try "rakudobrew rehash", though I'm not sure if that will
>> help in this case.
>> On Tue, Feb 28, 2017 at 7:55 AM, Theo van den Heuvel
>>  wrote:
>>> hi everyone,
>>> last week I used rakudobrew to update my Perl6 installation on Ubuntu.
>>>  This is Rakudo version 2017.02-106-gdd4dfb1 built on MoarVM version
>>> 2017.02-7-g3d85900
>>>  implementing Perl 6.c.
>>> Now, whenever I try perl6-debug-m I get
>>>  Cannot find method 'setlang' on object of type Perl6::HookGrammar
>>>   at gen/moar/perl6-debug.nqp:407
>>> (/home/theo/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6-debug.moarvm:comp_unit)
>>> followed by a slew of other nqp stuff. Is there something wrong with my
>>> installation? Suggestions for repair?
>>> Thanks,
>>> --
>>> Theo van den Heuvel
>>> Malden, The Netherlands
> 
> -- 
> Theo van den Heuvel
> Van den Heuvel HLT Consultancy
> Malden, The Netherlands
> +31 24 3736356
> +31 625492788


Re: How to limit the list of imported functions?

2017-04-07 Thread Elizabeth Mattijsen
https://docs.perl6.org/syntax/need

> On 7 Apr 2017, at 16:59, Gabor Szabo  wrote:
> 
> Thanks. I was only looking at https://docs.perl6.org/syntax/use
> 
> Looking at that doc you linked to, I have a related quest I could not see:
> 
> Is there a way to tell Rakudo to not to import any function from the module?
> 
> Gabor
> 
> 
> On Fri, Apr 7, 2017 at 5:37 PM, Will Coleda  wrote:
>> Please check the docs at
>> https://docs.perl6.org/language/modules#Exporting_and_Selective_Importing
>> 
>> On Fri, Apr 7, 2017 at 10:21 AM, Gabor Szabo  wrote:
>>> In perl 5 we can limit which functions are imported by listing them
>>> after the name of the module:
>>> 
>>> use Module ('foo', 'bar');
>>> 
>>> When I try the same in Rakudo I get
>>> 
>>> "no EXPORT sub, but you provided positional argument in the 'use' statement"
>>> 
>>> 
>>> At least in this case:
>>> 
>>> use WWW::Google::Time 'google-time-in';
>>> 
>>> ===SORRY!=== Error while compiling /opt/google_time.pl
>>> Error while importing from 'WWW::Google::Time':
>>> no EXPORT sub, but you provided positional argument in the 'use' statement
>>> at /opt/google_time.pl:2
>>> --> use WWW::Google::Time 'google-time-in'⏏;
>>> 
>>> Using Rakudo Star 2017.01
>>> 
>>> regards
>>>   Gabor
>> 
>> 
>> 
>> --
>> Will "Coke" Coleda


Re: String to array problem

2017-07-17 Thread Elizabeth Mattijsen
> On 17 Jul 2017, at 11:08, Brent Laabs  wrote:
> All of this is to say that I wish the Str.words method had a way of applying 
> Perl 6 quoting rules as if it were the qww operator.

Wouldn’t that be either .split or .comb?


Liz

Re: Is there a bash/shlex-like processor with double-quotes handling?

2017-07-14 Thread Elizabeth Mattijsen
zef install Text::CSV

This is a native port of Perl 5’s Text::CSV by the original author.

> On 14 Jul 2017, at 11:12, Philip Hazelden  wrote:
> 
> If you haven't yet, you might want to look into a CSV parser. I think that if 
> you configure one of those to split on whitespace, that should give you the 
> results you want.
> 
> (Now with added reply all.)
> 
> On Fri, 14 Jul 2017, 08:42 Mark Carter,  wrote:
> Is there a function that can decompose a string to an array separated by
> whitespace, but also respecting double quotes, and prefereably escape
> sequences?
> 
> So, for example:
> 
> my $d="hello   \"cruel world\"";
> 
> something-something($d) ; => ("hello", "cruel world")


Re: Where's the filter command?

2017-07-18 Thread Elizabeth Mattijsen

> On 18 Jul 2017, at 11:45, Mark Carter  wrote:
> 
> 
> 
> On 18/07/2017 09:53, Brent Laabs wrote:
>> Are you looking for grep()? https://docs.perl6.org/routine/grep
> Ah yes. Thanks for that.
> Pretty good:
> 
> say ($schema.lines().map: ).grep: { .elems() > 0; } ;

say $schema.lines.map().grep: *.elems;

should also do the trick, assuming .elems cannot return a value < 0.


Re: ping TImo: buf as a print

2017-07-09 Thread Elizabeth Mattijsen

> On 9 Jul 2017, at 07:32, ToddAndMargo  wrote:
> 
> On 07/08/2017 02:58 AM, timo wrote:
>> @ToddAndMargo  here's how to create an 
>> email with attachments:
>> my $image = "P5\n64 64\n255\n".encode("utf8") ~ Buf[int8].new( do for 
>> -32..^32 X -32..^32 -> ($x, $y) { 255 - (sqrt($x ** 2 + $y ** 2) * 4 % 
>> 255).ceiling });
> 
> Hi Timo,
> 
> perl6 -e 'my $image = "P5\n64 64\n255\n".encode("utf8") ~ Buf[int8].new(
> > do for -32..^32 X -32..^32 -> ($x, $y) {
> > 255 - (sqrt($x ** 2 + $y ** 2) * 4 % 255).ceiling
> > }); print $image;'
> 
> Cannot use a Buf as a string, but you called the Str method on it
>  in block  at -e line 4
> 
> 
> Am I missing something?

If you do:

  print $image.WHAT;

what does it say?  Buf?

The print is calling .Str on non-stringy objects.

Re: set (+) set = bag ?

2017-07-21 Thread Elizabeth Mattijsen

> On 21 Jul 2017, at 21:30, Darren Duncan  wrote:
> 
> On 2017-07-21 5:07 AM, Timo Paulssen wrote:
>> You want (|) to get the union of two sets as a set.
>> 
>> https://docs.perl6.org/language/setbagmix#Set%2FBag_Operators
>> 
>> hth
>>  - Timo
> 
> Right.  Every set operation except 1 (multiset sum) should result in a set, 
> and is just a special case of the same behavior as the bag operation.  
> Optionally the Set implementation of multiset sum could toss the duplicates 
> and still result in a Set, thus being an alias for union with Sets, rather 
> than resulting in a bag that it otherwise normally would.  Depends on 
> designer prefs I suppose.
> 
> Now, looking at that link, I can see at least 2 things that perhaps ought to 
> be changed.
> 
> Firstly, I believe ∆ (U+2206) is the standard symbol for symmetric 
> difference, and not circled minus as the above url currently gives.

https://en.wikipedia.org/wiki/Symmetric_difference seems to agree, showing it 
as the first choice.  However, ⊖ appears to be the second choice.  FWIW, I 
think ∆ better matches the Texas variant (^) .


> Secondly, I see there's an operator for multiplying 2 bags (which I hadn't 
> heard of before, but okay), but there should also be an operator for 
> multiplying 1 bag by a natural number, that is a scalar multiply of a bag.  
> Unless it is assumed the standard hyper-operator syntax is best for this.

If I get this right, you’d want:

  .Bag * 3 give (:3a,:6b).Bag ?

I guess that with * being commutative, 3 * .Bag would be the same result.

But then, what would .Bag * .Bag be?


Liz

Re: Announce: Rakudo Star Release 2017.07

2017-07-25 Thread Elizabeth Mattijsen
If that is the question, the answer is: the junction of “never" and “now".  
Which would also be the answer for Pumpking Perl 5, or any other programming 
language like ever.  Because as long as people are using it, a programming 
language will evolve.  Much like any human endeavour I would say.

> On 25 Jul 2017, at 09:42, Andrew Kirkpatrick <uberm...@gmail.com> wrote:
> 
> I assume the meaning is, roughly when is the implementation expected
> to cover the entire spec?
> 
> Answering this is probably an exercise in futility, because its up to
> the community and not anyone in particular.
> 
> On 25 July 2017 at 17:00, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
>>> On 25 Jul 2017, at 05:57, ToddAndMargo <toddandma...@zoho.com> wrote:
>>> On 07/24/2017 11:40 AM, Steve Mynott wrote:
>>>> A useful and usable production distribution of Perl 6
>>>> On behalf of the Rakudo and Perl 6 development teams, I'm pleased to
>>>> announce the July 2017 release of "Rakudo Star", a useful and usable
>>>> production distribution of Perl 6. The tarball for the July 2017
>>>> release is available from https://rakudo.perl6.org/downloads/star/.
>>>> Binaries for macOS and Windows (64 bit) are also available.
>>>> This is the eighth post-Christmas (production) release of Rakudo Star
>>>> and implements Perl v6.c. It comes with support for the MoarVM backend
>>>> (all module tests pass on supported platforms).
>>>> IMPORTANT: "panda" is to be removed very shortly since it is
>>>> deprecated. Please use "zef" instead.
>>>> Currently, Star is on a quarterly release cycle and 2017.10 (October)
>>>> will follow later this year.
>>>> Please note that this release of Rakudo Star is not fully functional
>>>> with the JVM backend from the Rakudo compiler. Please use the MoarVM
>>>> backend only.
>>>> In the Perl 6 world, we make a distinction between the language ("Perl
>>>> 6") and specific implementations of the language such as "Rakudo
>>>> Perl".
>>>> This Star release includes release 2017.07 of the Rakudo Perl 6
>>>> compiler, version 2017.07 MoarVM, plus various modules, documentation,
>>>> and other resources collected from the Perl 6 community.
>>>> Note this Star release contains NQP version 2017.07-9-gc0abee7 rather
>>>> than the release NQP 2017.07 in order to fix the --ll-exception
>>>> command line flag.
>>>> The Rakudo compiler changes since the last Rakudo Star release of
>>>> 2017.01 are now listed in "2017.05.md", "2017.06.md" and "2017.07.md"
>>>> under the "rakudo/docs/announce" directory of the source distribution.
>>>> Notable changes in modules shipped with Rakudo Star:
>>>> + DBIish: Doc and CI updates
>>>> + doc: Too many to list. p6doc fixed.
>>>> + grammar-debugger: Works again now.
>>>> + p6-io-string: New dep for doc.
>>>> + p6-native-resources: Removed since deprecated and not used by linenoise.
>>>> + panda: Officially deprecate panda in favour of zef.
>>>> + perl6-Test-When: New dep for perl6-pod-to-bigpage.
>>>> + perl6-lwp-simple: Fix breakage due to rakudo encoding refactor.
>>>> + tap-harness6: Replaces deprecated tap-harness6-prove6.
>>>> + zef: Too many to list.
>>>> There are some key features of Perl 6 that Rakudo Star does not yet
>>>> handle appropriately, although they will appear in upcoming releases.
>>>> Some of the not-quite-there features include:
>>>> + advanced macros
>>>> + non-blocking I/O (in progress)
>>>> + some bits of Synopsis 9 and 11
>>>> There is an online resource at http://perl6.org/compilers/features
>>>> that lists the known implemented and missing features of Rakudo's
>>>> backends and other Perl 6 implementations.
>>>> In many places we've tried to make Rakudo smart enough to inform the
>>>> programmer that a given feature isn't implemented, but there are many
>>>> that we've missed. Bug reports about missing and broken features are
>>>> welcomed at rakudo...@perl.org.
>>>> See https://perl6.org/ for links to much more information about Perl
>>>> 6, including documentation, example code, tutorials, presentations,
>>>> reference materials, design documents, and other supporting resources.
>>>> Some Perl 6 tutorials are available under the "docs" directory in the
>>>> release tarball.
>>>> The development team thanks all of the contributors and sponsors for
>>>> making Rakudo Star possible. If you would like to contribute, see
>>>> http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
>>>> mailing list, or join us on IRC #perl6 on freenode.
>>> 
>>> 
>>> Any idea when the full Rakudo will be released?
>> 
>> What do you mean by “the full Rakudo” ?  Rakudo Star is the Rakudo compiler 
>> release with a set of useful modules added (“batteries included”).
>> 
>> So you could argue that Rakudo doesn’t get fuller than with Rakudo Star!


Re: Announce: Rakudo Star Release 2017.07

2017-07-25 Thread Elizabeth Mattijsen
> On 25 Jul 2017, at 05:57, ToddAndMargo  wrote:
> On 07/24/2017 11:40 AM, Steve Mynott wrote:
>> A useful and usable production distribution of Perl 6
>> On behalf of the Rakudo and Perl 6 development teams, I'm pleased to
>> announce the July 2017 release of "Rakudo Star", a useful and usable
>> production distribution of Perl 6. The tarball for the July 2017
>> release is available from https://rakudo.perl6.org/downloads/star/.
>> Binaries for macOS and Windows (64 bit) are also available.
>> This is the eighth post-Christmas (production) release of Rakudo Star
>> and implements Perl v6.c. It comes with support for the MoarVM backend
>> (all module tests pass on supported platforms).
>> IMPORTANT: "panda" is to be removed very shortly since it is
>> deprecated. Please use "zef" instead.
>> Currently, Star is on a quarterly release cycle and 2017.10 (October)
>> will follow later this year.
>> Please note that this release of Rakudo Star is not fully functional
>> with the JVM backend from the Rakudo compiler. Please use the MoarVM
>> backend only.
>> In the Perl 6 world, we make a distinction between the language ("Perl
>> 6") and specific implementations of the language such as "Rakudo
>> Perl".
>> This Star release includes release 2017.07 of the Rakudo Perl 6
>> compiler, version 2017.07 MoarVM, plus various modules, documentation,
>> and other resources collected from the Perl 6 community.
>> Note this Star release contains NQP version 2017.07-9-gc0abee7 rather
>> than the release NQP 2017.07 in order to fix the --ll-exception
>> command line flag.
>> The Rakudo compiler changes since the last Rakudo Star release of
>> 2017.01 are now listed in "2017.05.md", "2017.06.md" and "2017.07.md"
>> under the "rakudo/docs/announce" directory of the source distribution.
>> Notable changes in modules shipped with Rakudo Star:
>> + DBIish: Doc and CI updates
>> + doc: Too many to list. p6doc fixed.
>> + grammar-debugger: Works again now.
>> + p6-io-string: New dep for doc.
>> + p6-native-resources: Removed since deprecated and not used by linenoise.
>> + panda: Officially deprecate panda in favour of zef.
>> + perl6-Test-When: New dep for perl6-pod-to-bigpage.
>> + perl6-lwp-simple: Fix breakage due to rakudo encoding refactor.
>> + tap-harness6: Replaces deprecated tap-harness6-prove6.
>> + zef: Too many to list.
>> There are some key features of Perl 6 that Rakudo Star does not yet
>> handle appropriately, although they will appear in upcoming releases.
>> Some of the not-quite-there features include:
>> + advanced macros
>> + non-blocking I/O (in progress)
>> + some bits of Synopsis 9 and 11
>> There is an online resource at http://perl6.org/compilers/features
>> that lists the known implemented and missing features of Rakudo's
>> backends and other Perl 6 implementations.
>> In many places we've tried to make Rakudo smart enough to inform the
>> programmer that a given feature isn't implemented, but there are many
>> that we've missed. Bug reports about missing and broken features are
>> welcomed at rakudo...@perl.org.
>> See https://perl6.org/ for links to much more information about Perl
>> 6, including documentation, example code, tutorials, presentations,
>> reference materials, design documents, and other supporting resources.
>> Some Perl 6 tutorials are available under the "docs" directory in the
>> release tarball.
>> The development team thanks all of the contributors and sponsors for
>> making Rakudo Star possible. If you would like to contribute, see
>> http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
>> mailing list, or join us on IRC #perl6 on freenode.
> 
> 
> Any idea when the full Rakudo will be released?

What do you mean by “the full Rakudo” ?  Rakudo Star is the Rakudo compiler 
release with a set of useful modules added (“batteries included”).

So you could argue that Rakudo doesn’t get fuller than with Rakudo Star!


Re: accepting values on the command line

2017-07-01 Thread Elizabeth Mattijsen

> On 1 Jul 2017, at 15:15, Gabor Szabo  wrote:
> 
> I was hoping to wrote a simple script that would accept a bunch of
> filenames on the command line so I wrote:
> 
> #!/usr/bin/env perl6
> use v6;
> 
> multi sub MAIN(@files) {
>say @files.perl;
> }

This signature will only accept an Iterable.  The command line parameters are 
*not* considered a list, so this will not match.  What you need is a slurpy 
array:

multi sub MAIN(*@files) {
say @files.perl;
}


$ 6 'sub MAIN(*@a) { dd @a }' a b c d
["a", "b", "c", "d"]


Liz

Re: Version of a Module

2017-06-28 Thread Elizabeth Mattijsen
> On 28 Jun 2017, at 14:01, Martin Barth  wrote:
> but your approach means you have to state the version in the META6.json AND 
> in the Module.pm6 file again. This would be the similar to having $VERSION in 
> perl5. Shouldnt there be a simpler way?

Isn’t that info available in %?RESOURCES somewhere ??



Liz

Re: Need awk print sub

2017-08-04 Thread Elizabeth Mattijsen

> On 4 Aug 2017, at 22:00, ToddAndMargo  wrote:
> 
> Hi All,
> 
> How do I do this with a perl one liner?
> 
> $ echo "a b c d" | awk '{print $2}'
> b

echo "a b c d" | perl6 -e 'say words[1]’

Note array indices in Perl 6 are 0 based.

Re: another one liner

2017-08-05 Thread Elizabeth Mattijsen

> On 5 Aug 2017, at 09:21, ToddAndMargo  wrote:
> 
> On 08/04/2017 08:43 PM, Bruce Gray wrote:
>> P6-ish version:
>> ifconfig | perl6 -e 'say lines.map({ ~$0 if /^(\S+) ": flags="/ }).sort[1]'
> 
> Would some kind person please tell me what is going on here?

say the result of
  reading all lines of STDIN
mapping them to the stringified match (~)
  of the first ($0) non-whitespace (\S+) characters
  starting at the beginning of the string (^)
  if they’re followed by “: flags=“
sorting these strings (.sort)
taking the second element of the sorted list ([1]


Re: another one liner

2017-08-05 Thread Elizabeth Mattijsen
> On 5 Aug 2017, at 08:50, Sean McAfee  wrote:
> 
> On Fri, Aug 4, 2017 at 10:18 PM, ToddAndMargo  wrote:
> On 08/04/2017 08:43 PM, Bruce Gray wrote:
> 
> P6-ish version:
> ifconfig | perl6 -e 'say lines.map({ ~$0 if /^(\S+) ": flags="/ }).sort[1]'
> 
> 
> Wait a second.  How does map skip input elements like that?
> 
> > map { $_ if $_ %% 2 }, 1..10
> (2 4 6 8 10)
> 
> > 1 if 1 %% 2
> ()
> 
> But:
> 
> > map { $_ %% 2 ?? $_ !! () }, 1..10
> (() 2 () 4 () 6 () 8 () 10)

Because a failing “if" returns the empty Slip (aka Empty):

$ 6 'dd do if 0 { }’
Empty

Now isn’t that convenient  :-)


Liz

Re: Task::Star and Panda

2017-05-23 Thread Elizabeth Mattijsen
> On 23 May 2017, at 19:23, ToddAndMargo  wrote:
> 
> On 05/23/2017 06:30 AM, Will Coleda wrote:
>> Removed? It's still available athttps://github.com/tadzik/panda  …
> 
> It is on its way out.  The developers over on the chat
> line directed me to zef when I asked for help getting
> panda working.
> 
>>> Panda stinks.
>> That's not really true or called for.
> 
> Panda is broken and not going to be repaired.  The
> developers on the chat line recommend zef instead.
> Was polite enough?

Perhaps you should check out the section “The End of an Era” in last weeks Perl 
6 Weekly: https://p6weekly.wordpress.com/2017/05/16/2017-20-crossing-the-alps/

You should realize that open source software is not made by robots but by 
people.  People for which keeping up with changes can take more resources than 
they have at hand.

Also remember that without panda, I don’t think we would have had an ecosystem 
out now as fleshed out as it is now.

So saying that certain software stinks, feels more like projection than 
anything else.  So yes, *I* think it was uncalled for.


Liz

Re: Task::Star and Panda

2017-05-23 Thread Elizabeth Mattijsen
> On 23 May 2017, at 20:21, ToddAndMargo <toddandma...@zoho.com> wrote:
> On 05/23/2017 10:47 AM, Elizabeth Mattijsen wrote:
>>> On 23 May 2017, at 19:23, ToddAndMargo <toddandma...@zoho.com> wrote:
>>> 
>>> On 05/23/2017 06:30 AM, Will Coleda wrote:
>>>> Removed? It's still available athttps://github.com/tadzik/panda  …
>>> 
>>> It is on its way out.  The developers over on the chat
>>> line directed me to zef when I asked for help getting
>>> panda working.
>>> 
>>>>> Panda stinks.
>>>> That's not really true or called for.
>>> 
>>> Panda is broken and not going to be repaired.  The
>>> developers on the chat line recommend zef instead.
>>> Was polite enough?
>> Perhaps you should check out the section “The End of an Era” in last weeks 
>> Perl 6 Weekly: 
>> https://p6weekly.wordpress.com/2017/05/16/2017-20-crossing-the-alps/
>> You should realize that open source software is not made by robots but by 
>> people.  People for which keeping up with changes can take more resources 
>> than they have at hand.
>> Also remember that without panda, I don’t think we would have had an 
>> ecosystem out now as fleshed out as it is now.
>> So saying that certain software stinks, feels more like projection than 
>> anything else.  So yes, *I* think it was uncalled for.
>> Liz
> 
> Would substituting "broken" for "stinks" be polite enough?

IMO yes, because that would be factual.


Liz

Re: Invoking method by name found in variable

2017-05-23 Thread Elizabeth Mattijsen

> On 23 May 2017, at 20:01, Gabor Szabo  wrote:
> given an object $o and the name of a method in $method = "run"
> how can I invoke the $o.run() ?
> 
> Something like $o.call($method)

$o.”$method"()

$ 6 'my $method = "Str"; dd 42."$method"()'
“42"

Liz

Re: problem converting Inf and NaN

2017-05-27 Thread Elizabeth Mattijsen
> On 27 May 2017, at 23:22, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
>> On 27 May 2017, at 19:33, Marcel Timmerman <mt1...@gmail.com> wrote:
>> In perl6 version 2017.04.3-287-g3e7675a built on MoarVM version 
>> 2017.04-64-g6d5ea04
>> implementing Perl 6.c. I observe the following;
>> 
>> my Num $num = Inf;
>> my FatRat $f = $num.FatRat;
>> Type check failed in assignment to $f; expected FatRat but got 
>> Rational[Num,Int] (?)
>> in block  at  line 1
>> 
>> Inf.WHAT;# (Num)
>> Inf.FatRat.WHAT  # (Rational[Num,Int])
>> 
>> It boils down to not converting to FatRat while a defined number does;
>> my Num $num = 2.3e3;
>> $num.FatRat.WHAT;# (FatRat)
>> 
>> 
>> This is the same for NaN.
>> 
>> If this is defined behavior, then there is no way to set NaN or Inf for 
>> FatRat (and for Rat too). Is there another way to accomplish this?
> 
> This feels like a bug.  Could you rakudobug it so it won’t fall through the 
> cracks?
> 
> FWIW, the golf is:
> 
> $ 6 'dd FatRat.new(Inf)'
> Type check failed in binding to parameter 'nu'; expected Int but got Num (Inf)
>  in block  at -e line 1

Please disregard the above.

This is a problem that basically comes down to:

  $ 6 'say Int.Range.max.WHAT'
  (Num)

In other words: the maximum value of an Int is  *not* an Int.  To be able to 
support Inf in rationals, we use a hack to create a special type of Rat that 
allows for a Num numerator.

  https://github.com/rakudo/rakudo/blob/nom/src/core/Num.pm#L44

I’m not seeing a way around this at the moment.  But then I’m really tired now  
:-)

Re: problem converting Inf and NaN

2017-05-27 Thread Elizabeth Mattijsen


> On 27 May 2017, at 19:33, Marcel Timmerman  wrote:
> In perl6 version 2017.04.3-287-g3e7675a built on MoarVM version 
> 2017.04-64-g6d5ea04
> implementing Perl 6.c. I observe the following;
> 
> my Num $num = Inf;
> my FatRat $f = $num.FatRat;
> Type check failed in assignment to $f; expected FatRat but got 
> Rational[Num,Int] (?)
>  in block  at  line 1
> 
> Inf.WHAT;# (Num)
> Inf.FatRat.WHAT  # (Rational[Num,Int])
> 
> It boils down to not converting to FatRat while a defined number does;
> my Num $num = 2.3e3;
> $num.FatRat.WHAT;# (FatRat)
> 
> 
> This is the same for NaN.
> 
> If this is defined behavior, then there is no way to set NaN or Inf for 
> FatRat (and for Rat too). Is there another way to accomplish this?

This feels like a bug.  Could you rakudobug it so it won’t fall through the 
cracks?

FWIW, the golf is:

$ 6 'dd FatRat.new(Inf)'
Type check failed in binding to parameter 'nu'; expected Int but got Num (Inf)
  in block  at -e line 1

Re: naming a class

2017-05-28 Thread Elizabeth Mattijsen
> On 28 May 2017, at 11:49, Marcel Timmerman  wrote:
> I've a question about naming a specific class. It is about the type 
> Decimal128 which I need in BSON. For the moment I want it to hold a number 
> and in BSON to encode and decode it to a byte stream. Later I can add 
> specific operations and other known decimal types. I am thinking of the 
> following names;
> 
> Math::Decimal::D128
> Math::Decimal::D64
> Math::Decimal::D32
> 
> For the 128, 64 and 32 bit decimal types. Or should I drop the Math:: part.
> 
> The other question I have is the following; I know about the _Decimal128 type 
> in C (gcc). Is it also a standard type in C on windows and mac? In that case 
> I could try to go native.

Apart from the naming, isn’t Decimal64 the same as “num64” in Rakudo?  And 
Decimal32 the same as “num32” ?  If so, I think there’s already an outstanding 
RT for not supporting “num128” in Rakudo.  Perhaps it would be better to focus 
on supporting this in MoarVM directly?



Liz

Re: zef, zef-j, zef-m

2017-05-29 Thread Elizabeth Mattijsen

> On 29 May 2017, at 17:33, Fernando Santagata  
> wrote:
> 
> On Mon, May 29, 2017 at 12:20 PM, Brent Laabs  wrote:
> > On 29 May 2017, at 11:22, Fernando Santagata  
> > wrote:
> >
> > /me sighs: NQP is still so poorly documented!
> 
> Believe it or not, this is documented in nqp/docs/ops.markdown in the section 
> under stat.
> 
> That is not under https://docs.perl6.org/, I presume.

No, as it is specific to the Rakudo / nqp implementation of Perl 6.

You can find it here in rendered format:

  https://github.com/perl6/nqp/blob/master/docs/ops.markdown



Liz

Re: Get Better error message that "is trait on $-sigil variable not yet implemented. Sorry."?

2017-05-26 Thread Elizabeth Mattijsen
Fixed with https://github.com/rakudo/rakudo/commit/f2fca0c8c2 .

> On 26 May 2017, at 10:47, Brent Laabs  wrote:
> 
> To file a bug in Rakudo, you should email rakudo...@perl.org.
> 
> If it's a better error message you want, put "LTA Error" in the email subject 
> somewhere.  LTA means "less than awesome", because we in Perl 6 land only 
> accept awesome error messages.
> 
> If you want to actually have the feature, put "[NYI]" in the subject line, 
> for "not yet implemented".
> 
> You can of course track Perl 6 bugs at in RT, perl6 queue: 
> https://rt.perl.org/
> 
> On Fri, May 26, 2017 at 1:34 AM, Gabor Szabo  wrote:
> I just tried:
> 
> 
> > my $x is Int = 42;
> ===SORRY!=== Error while compiling:
> is trait on $-sigil variable not yet implemented. Sorry.
> --> my $x is Int⏏ = 42;
> expecting any of:
> constraint
> 
> and was a bit disappointed. It took me a while and reading the book of
> Andrew Shitov till I tried
> 
> > my Int $x = 42;
> 42
> 
> 
> I wonder if the error message could hint at this way of declaring a
> type constraint?
> 
> Gabor
> 


Re: zef, zef-j, zef-m

2017-05-29 Thread Elizabeth Mattijsen
Perhaps Zoffix is willing to take a PR for an IO::Path.nlinks method as part of 
the IO grant.

> On 29 May 2017, at 11:22, Fernando Santagata <nando.santag...@gmail.com> 
> wrote:
> 
> /me sighs: NQP is still so poorly documented!
> 
> On Mon, May 29, 2017 at 11:10 AM, Brent Laabs <bsla...@gmail.com> wrote:
> This works without a module on Rakudo:
> 
> use nqp;
> my $path = "foo".IO;
> my $hardlink-count =  nqp::stat($path.absolute, 
> nqp::const::STAT_PLATFORM_NLINKS);
> 
> 
> 
> 
> On Mon, May 29, 2017 at 1:54 AM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> > On 29 May 2017, at 10:42, Fernando Santagata <nando.santag...@gmail.com> 
> > wrote:
> >
> > The three files are already hard-linked, no need for soft links.
> >
> > BTW, is there a way to detect hard links in Perl6?
> > Perl5 "stat" operator returns an array whose fourth element is the number 
> > of hard links of a file, but I don't see anything like that in the Perl6 
> > docs.
> 
> Generally, unixisms are not directly supported in Perl 6 in the core.  It 
> should be relatively trivial to create an ecosystem module for this using 
> NativeCall directly accessing functionality in libc (which then of course 
> won’t work on Windows).
> 
> 
> Liz
> 
> 
> 
> 
> -- 
> Fernando Santagata


Re: Creating an array of a single hash

2017-06-02 Thread Elizabeth Mattijsen
> On 1 Jun 2017, at 16:29, Gabor Szabo  wrote:
> 
> use v6;
> 
> my @x = { name => "Foo" }, { name => "Bar"}
> say @x.gist; # [{name => Foo} {name => Bar}]
> say @x.^name;# Array
> say @x[0].^name; # Hash
> 
> my @y = { name => "Foo" }
> say @y;   # [name => Foo]
> say @y.^name; # Array
> say @y[0].^name;  # Pair
> 
> my @z = { name => "Foo" },;
> say @z;   # [{name => Foo}]
> say @z.^name; # Array
> say @z[0].^name;  #  Hash
> 
> 
> In the first example, creating an array of 2 hashes work.
> In the second example the listy assignment removes the hashy-ness of
> the right hand side.
> In the 3rd example adding a comma at the end solves the problem.
> 
> Is this how it is recommended to initiate an array with a single hash?
> Is there an operator that forces the assignment to item-assignment?

FWIW, this follows out of the 1 argument rule:

$ 6 'for { a => 42 } { dd $_ }'
:a(42)

$ 6 'for { a => 42 }, { b => 666 } { dd $_ }'
Hash % = {:a(42)}
Hash % = {:b(666)}

If only 1 argument is specified, it will be iterated over.  And you could 
consider list assignment also such a case (as it internally calls @x.STORE in 
that case).



Liz

Re: How to deriving own distinguish type from Int?

2017-05-31 Thread Elizabeth Mattijsen
> On 31 May 2017, at 12:25, cle-pe...@qiao.in-berlin.de wrote:
> 
> Hello,
> 
> I am already following Perl 6 since many years. But only recently as books 
> began to appear, I began to really learn it.
> 
> One of the many things I like on Perl 6 is its static typing possibility. I 
> am used to dynamical typed languages like Perl 5, Ruby, Python ... you name 
> it. But I am very fond of strong static typing especially if it comes with 
> automatic type inference like in languages like OCaml, Go and recently C++ 
> since 2011. But I like languages like Ada too :-)
> 
> Now I would like to define two datatypes  in Perl 6 deriving from `Int` but 
> being incompatible with `Int` the same time.
> 
> For instance:
> 
>  `Distance` derived from `Int` with a range 0 up to 32000, and
>  `Offset` derived from `Int` with a range from -32000 up to 32000
> 
> Now I would like the types `Distance`, `Offset` and `Int` being 
> distinguishable and incompatible to each other on default.
> 
> So (pseudo Perl 6):
> 
>  my Distance $d = Distance(12);  // ok
>  my Offset $o = Offset(-1);  // ok
>  my Distance $d2 = $o;   // BUMMER!
> 
>  say $d + $o;// BUMMER!
> 
> and so on! I want the Perl 6 compiler to complain if I ever try to mix 
> `Distance`s and `Offset`s implicitly.
> 
> In my books I've read so far there was no hint how to achieve this. Asking 
> Google for some days also offer me no any answer whether this is possible, 
> and if it is, how?
> 
> I found about `subset` but this only put some restriction on a type, but does 
> not render it incompatible to the original type. Furthermore it is not 
> distinguishable from the original type if its restrictions are met in both 
> the original type and its subset.
> 
> So I would like to ask here if anybody know if this is possible in Perl 6? 
> And if yes, how would I have to do it?
> 
> Thanks for your patience to follow me up to here ...

This feels a lot like a question well asked on StackOverflow, tagged with 
“perl6” .


Liz

Re: The speed (improvement) of Rakudo

2017-06-17 Thread Elizabeth Mattijsen
> On 17 Jun 2017, at 13:12, Tom Browder  wrote:
> On Fri, Jun 16, 2017 at 23:47 Gabor Szabo  wrote:
>> Is there some measurements regarding the speed of Rakudo?
> 
> Perl 6 is still very slow on IO compared to Perl 5. I have a
> read/write test suite I've been using since 2014 and it shows little
> improvement so far (Perl 6 takes about 10-20 times as long as Perl 5
> to read the same size ASCII file).  Jonathan is planning to work on
> that aspect of Rakudo soon.
> 
> The test suite is at:
> 
>  https://github.com/tbrowder/perl6-read-write-tests

AFAIK, Jonathan has already done extensive work on that the past days, but 
deemed it too ‘new’ to release for 2017.06 (due today).  So expect to see quite 
a bit of improvement for 2017.07, especially on UTF-8 encoded text files.



Liz

Re: contains question

2017-06-12 Thread Elizabeth Mattijsen
Thinking about this...

> On 12 Jun 2017, at 11:17, Francesco Rivetti <o...@oha.it> wrote:
> 
> if you can:
> 
> $s ~~ "foo"
> $s ~~ /foo/
> 
> then wouldn't be good to have also:
> 
> $s.contains("foo");
> $s.contains(/foo/);
> 
> IOW, overload .contains() with Str and Regex
> 
> F
> 
> On 06/12/2017 10:42 AM, Elizabeth Mattijsen wrote:
>>> On 12 Jun 2017, at 01:27, ToddAndMargo <toddandma...@zoho.com> wrote:
>>> perl6 -e 'my $x = "\t"; if $x !~~ /<[A..Z a..z 0..9]>/ {say "out"} else 
>>> {say "in"}'
>>> 
>>> Would this be easier to do with $x.contains?  Or would it
>>> be too worky?
>> .contains only takes a *single string* to look up.  So it is only useful for 
>> checking whether “foo” exists in “foo bar”:
>>   say “foo bar”.contains(“foo”)
>> Liz


Re: contains question

2017-06-12 Thread Elizabeth Mattijsen

> On 12 Jun 2017, at 01:27, ToddAndMargo  wrote:
> perl6 -e 'my $x = "\t"; if $x !~~ /<[A..Z a..z 0..9]>/ {say "out"} else {say 
> "in"}'
> 
> Would this be easier to do with $x.contains?  Or would it
> be too worky?

.contains only takes a *single string* to look up.  So it is only useful for 
checking whether “foo” exists in “foo bar”:

  say “foo bar”.contains(“foo”)



Liz

Re: Perl 6 ignores SIGPIPE

2017-06-16 Thread Elizabeth Mattijsen
> On 16 Jun 2017, at 08:34, Sean McAfee  wrote:
> 
> I see at
> 
> http://www.moarvm.com/releases.html
> 
> ...that as of the 2017.03 release, Perl 6 "ignores SIGPIPE by default."  I 
> discovered this for myself when I piped a program that generates unlimited 
> output to the head utility, and the program did not exit when head was 
> finished.  Simple example:
> 
> $ perl6 -e '.say for ^Inf' | head
> 
> This will print numbers up to 9, and then continue to use almost 100% of the 
> CPU printing to a closed pipe.
> 
> I haven't been able to turn up any discussion about this change.  Does anyone 
> have any insight?  It's surprising and, frankly, unwelcome.

Trying this on HEAD I get:

$ 6 '.say for ^Inf' | head
0
1
2
3
4
5
6
7
8
9
Failed to write bytes to filehandle: Broken pipe
  in block  at -e line 1

So it would appear this got fixed by the synchronous IO refactor, and will be 
available in the 2017.06 release, which is scheduled for tomorrow.



Liz

Re: How do you call the variable types?

2017-06-16 Thread Elizabeth Mattijsen

> On 16 Jun 2017, at 06:23, Gabor Szabo  wrote:
> 
> On Sat, Jun 10, 2017 at 9:38 AM, Brent Laabs  wrote:
>> I thought:
>> $ is Scalar
>> @ is Array
>> % is Hash
>> & is a function
>> 
> 
> Reading this https://docs.perl6.org/language/containers I just found
> out that a @-variable can also contain a List,
> not just an array:
> 
>> my @z = ()
> []
>> @z.^name
> Array
>> my @z := ()
> ()
>> @z.^name
> List

You can bind *anything* that does Positional to an @-variable:

$ perl6 
To exit type 'exit' or '^D'
> my @a := 42 but Positional
42
> @a[0]
42
> @a[1]
Index out of range. Is: 1, should be in 0..0
  in block  at  line 1



Liz


Re: Perl 6 ignores SIGPIPE

2017-06-16 Thread Elizabeth Mattijsen
> On 16 Jun 2017, at 14:10, Jan Ingvoldstad <frett...@gmail.com> wrote:
> 
> On Fri, Jun 16, 2017 at 12:13 PM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> 
> Failed to write bytes to filehandle: Broken pipe
>   in block  at -e line 1
> 
> So it would appear this got fixed by the synchronous IO refactor, and will be 
> available in the 2017.06 release, which is scheduled for tomorrow.
> 
> 
> 
> This appears to be only a partial fix with an unexpected outcome.
> 
> awk, Perl 5, Ruby, etc. do not generate errors for similar use of pipes, and 
> instead use exit status 0.

Then this should be filed as a rakudobug  :-)



Liz


Re: getting help in the REPL

2017-06-16 Thread Elizabeth Mattijsen
> On 14 Jun 2017, at 16:07, Gabor Szabo  wrote:
> On Wed, Jun 14, 2017 at 4:44 PM, Timo Paulssen  wrote:
>> WHY and WHEREFOR are "fully" supported, it's just that we've not put any
>> pod into the core setting and we don't have helper code that loads it
>> "lazily" when WHY is called the first time on a core class or sub …
> 
> $ perl6
> To exit type 'exit' or '^D'
>> my @x = 1, 2, 3;
> [1 2 3]
>> @x.WHY
> (Any)

These commits:

  https://github.com/rakudo/rakudo/commit/23d6d42d91
  https://github.com/rakudo/rakudo/commit/cc4d9091d7

added a gist to the Nil that gets returned by Mu.WHY.  The effect is visible in 
the REPL:

$ perl6
To exit type 'exit' or '^D'
> my @x = 1,2,3;
[1 2 3]
> @x.WHY
No documentation available for type 'Array'.
Perhaps it can be found at https://docs.perl6.org/type/Array


It’s not as good as I would like it to see, but it is at least better than it 
was, I think.



Liz

Re: Undeclared routine: break used at line ...

2017-06-13 Thread Elizabeth Mattijsen
> On Tue, Jun 13, 2017 at 8:50 PM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
>>> On 13 Jun 2017, at 19:34, Gabor Szabo <szab...@gmail.com> wrote:
>>> 
>>> I just managed to write
>>> 
>>> while True {
>>>   ...
>>>   break if $code eq 'exit';
>>>   ...
>>> }
>>> 
>>> 
>>> I wonder if Rakudo could be more cleaver in this particular case and
>>> remind me to use 'last' instead of 'break'.
>> Is the undeclared sub error not helpful enough?
> I think for someone who comes from a language where 'break' is the
> keyword, this would be very surprising
> and an telling that person it is called 'last' in Perl 6 would be a nice 
> touch.

After https://github.com/rakudo/rakudo/commit/69b1b6c808 you get:

$ 6 'break'
===SORRY!=== Error while compiling -e
Undeclared routine:
break used at line 1. Did you mean 'last’?

$ 6 'sub brake() {}; break'
===SORRY!=== Error while compiling -e
Undeclared routine:
break used at line 1. Did you mean 'brake', 'last’?


:-)


Liz

Re: can't adverb and infix

2017-09-20 Thread Elizabeth Mattijsen

> On 19 Sep 2017, at 13:04, Brandon Allbery  wrote:
> 
> On Tue, Sep 19, 2017 at 3:44 AM, Luca Ferrari  wrote:
> this will sound trivial, but the following piece of code that in my
> mind should work does not:
> 
> $mode = 'csv' if ( ! $mode.defined || %available_modes{ $mode }:!exists );
> 
> and the compiler says:
> 
> You can't adverb :<||>
> 
> You want the adverb to be on the postcircumfix; parenthesize the expression. 
> IIRC this was considered the least bad alternative out of an ambiguous parse 
> (i.e. which operation does the adverb apply to?).
> 
> $mode = 'csv' if ( ! $mode.defined || (%available_modes{ $mode }:!exists) 
> );

Or use the lower precedence “or” instead of “||”:

  $mode = 'csv' if ( ! $mode.defined or %available_modes{ $mode }:!exists );


Liz

Re: bash and pm6 question

2017-09-21 Thread Elizabeth Mattijsen
> On 22 Sep 2017, at 00:32, Bennett Todd  wrote:
> 
> With perl5, that could have been something like. "perl -Mmy -e ...", but I 
> don't have access to a perl6 at this instant to compare. There should be a 
> flag you can use to include a module into the.running environment before 
> evaluating the 
> "-e" code.
> 
> Using "use" within the "-e" string should work, too.

Guess what?  It’s also -M in Rakudo Perl 6:

$ perl6 -MTest -e 'ok 1’
ok 1 - 


Liz

Re: Thread example from evanmiller

2017-09-11 Thread Elizabeth Mattijsen
> On 8 Sep 2017, at 05:16, Norman Gaywood  wrote:
> 
> Several weeks ago there was this post:
> http://www.evanmiller.org/why-im-learning-perl-6.html
> 
> That gave this example of perl6 N:M threads in action:
> 
> use v6.d.PREVIEW;
> 
> my $channel = Channel.new;
> 
> my @ten_tasks = (^10).map: {
> start {
> my $thread = $*THREAD.id;
> await $channel;
> say "HOLY MOLEY SOMEONE STOLE MY THREAD" if $thread != $*THREAD.id;
> }
> }
> 
> $channel.send("Ring ring") for ^10;
> $channel.close;
> 
> await @ten_tasks;
> 
> 
> It demonstrates that perl6 will not tie up a thread in the thread pool just 
> sitting around waiting (I think).
> 
> The example is intended to be condensed without any surplus code.
> So my question is, is the $channel.close required? Leave it out and the code 
> still seems to work. Am I missing some subtle point?

Jonathan tells me the .close is not required:

https://irclog.perlgeek.de/moarvm/2017-09-11#i_15148891


Liz

Re: Are 64 bit natives universally available?

2017-08-27 Thread Elizabeth Mattijsen
They have been available since Christmas, afaik.

> On 27 Aug 2017, at 22:42, David Warring  wrote:
> 
> Quick question.
> 
> I just want to doublle check that int64,  uint64 are universally available 
> via Perl 6, before introducing them into modules. e.g.
> % perl6 -e'my uint64 $n = 99; say $n'   
> 99
> 
> - David


Re: thread behavior

2017-09-04 Thread Elizabeth Mattijsen
> On 4 Sep 2017, at 10:44, JuhiMarcel LangbroekTimmerman  
> wrote:
> Thanks for your anwer. I assume there are a few things I can rely on;
> - the main thread is where the code starts and will always have id 1

That can not be relied on in general, I’m afraid.  However, after some 
discussion, it appears that there is some support for an "is-initial-thread” 
method:

   https://irclog.perlgeek.de/perl6-dev/2017-09-04#i_15112552

Note that the feeling is that you shouldn’t write code that depends on this.


> - a continuation of statements/blocks will always be excecuted on the same 
> thread except for those hyper thingies which are again separate blocks or 
> closures excecuted on other threads

I would say anything that either explicitly or implicitly does an await() in 
the future is not guaranteed to continue executing on the same thread.  Of 
course, the catch is in the “implicitly”: if you have complete control over 
your code, I guess you can be sure.  As soon as you start using 3rd party 
modules, I guess you could argue that all bets are off.

So this comes back to: why is it important to you to be sure that code 
continues to execute on the same thread?


> Is that correct?

Not sure  :-)


Liz

Re: thread behavior

2017-09-04 Thread Elizabeth Mattijsen
> On 4 Sep 2017, at 09:29, Marcel Timmerman  wrote:
> I was wondering about the following,
> 
> When an Exception is thrown in a thread and is CATCHed  in another object, 
> will that block be run in the same thread as the Exception is thrown?

I think from 6.d onward, you can not rely on your code being executed in any 
specific thread, especially when using await(), but possibly more generally in 
the future.

So it feels like a premature optimisation depending on your code being executed 
by the same thread in *any* situation, but especially in the light of control 
exceptions.


Hope this is a useful answer  :-)



Liz

Re: Set difference using hashes vs array

2017-11-23 Thread Elizabeth Mattijsen
Will have a look at this in about 12 hours (probably).  Meanwhile, don’t let 
that stop anyone from figuring this out  :-)


> On 23 Nov 2017, at 05:27, Norman Gaywood  wrote:
> 
> Talking to myself :-) 
> 
> Seems it has something to do with the values in the hash. If they are just 
> True, this works:
> $ perl6
> To exit type 'exit' or '^D'
> > my %a= :k, :e, :r; my %r= :r; my %e= :e; my Set $s = %a (-) %r (-) %e;
> set(k)
> 
> 
> 
> On 23 November 2017 at 16:20, Norman Gaywood  wrote:
> For compactness, here are the 1-liners:
> 
> $ perl6
> To exit type 'exit' or '^D'
> > my %a= k=>"k", e=>"e", r=>"r"; my %r= r=>"r"; my %e= e=>"e"; my Set $s = %a 
> > (-) %r (-) %e;
> Cannot convert string to number: base-10 number must begin with valid digits 
> or '.' in '⏏k' (indicated by ⏏)
>   in block  at  line 1
> 
> > my %a= k=>"k", e=>"e", r=>"r"; my %r= r=>"r"; my %e= e=>"e"; my Set $s = 
> > (%a (-) %r) (-) %e;
> set(k)
> > my @a= "k", "e", "r"; my @r= "r"; my @e= "e"; my Set $s = @a (-) @r (-) @e;
> set(k)
> > 
> 
> 
> On 23 November 2017 at 15:41, Norman Gaywood  wrote:
> I'm not sure what this error message means and what is going on here:
> perl6 --version
> This is Rakudo version 2017.08 built on MoarVM version 2017.08.1
> implementing Perl 6.c.
> 
> $ cat tt-h.p6 
> #!/usr/bin/env perl6
> 
> my %excludes = "exclude" => "exclude";
> my %all = :keep("keep"), :exclude("exclude"), :remove("remove");
> my %remove = :remove("remove");
> 
> my Set $take1 = (%all (-) %remove) (-) %excludes;
> dd $take1;
> my Set $take2 = %all (-) %remove (-) %excludes;
> dd $take2;
> 
> $ ./tt-h.p6 
> Set $take1 = set("keep")
> Cannot convert string to number: base-10 number must begin with valid digits 
> or '.' in '⏏remove' (indicated by ⏏)
>   in block  at ./tt-h.p6 line 10
> 
> The difference in $take1 and $take2 are the brackets around the 1st set 
> operation.
> 
> If I use arrays then no problem with either expression:
> 
> $ cat tt-a.p6 
> #!/usr/bin/env perl6
> 
> my @excludes = "exclude";
> my @all = "keep", "exclude", "remove";
> my @remove = "remove";
> 
> my Set $take1 = (@all (-) @remove) (-) @excludes;
> dd $take1;
> my Set $take2 = @all (-) @remove (-) @excludes;
> dd $take2;
> 
> $ ./tt-a.p6 
> Set $take1 = set("keep")
> Set $take2 = set("keep")
> 
> -- 
> Norman Gaywood, Computer Systems Officer
> School of Science and Technology
> University of New England
> Armidale NSW 2351, Australia
> 
> ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
> Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062
> 
> Please avoid sending me Word or Power Point attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
> 
> 
> 
> -- 
> Norman Gaywood, Computer Systems Officer
> School of Science and Technology
> University of New England
> Armidale NSW 2351, Australia
> 
> ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
> Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062
> 
> Please avoid sending me Word or Power Point attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
> 
> 
> 
> -- 
> Norman Gaywood, Computer Systems Officer
> School of Science and Technology
> University of New England
> Armidale NSW 2351, Australia
> 
> ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
> Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062
> 
> Please avoid sending me Word or Power Point attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html


Re: The equivalent of Moose's "around"

2017-11-17 Thread Elizabeth Mattijsen
> On 17 Nov 2017, at 20:09, Fernando Santagata  
> wrote:
> I tried to use the code you suggested:
> 
> sub trait_mod:(Attribute:D \attribute, :!) {
>   attribute.package.^add_method(attribute.name, my method () { proxy($_) })
> }
> 
> class A {
>   has $!a is proxy({ $^a * 2 });
>   has $!b is proxy({ $^a * 3 });
> }
> 
> my A $a .= new;
> $a.a = 21;# <-- No such method 'a' for invocant of type 'A'
> say $a.a;
> $a.b = 21;
> say $a.b;
> 
> But I got an error on the first assignment.
> What am I doing wrong?

Ok, finally had some time to figure this out more deeply.  My result:
=
sub trait_mod:(Attribute:D \attribute, :!) {
my $name   = attribute.name;
my $method = $name.substr(2);
attribute.package.^add_method($method, my method ($SELF:) is raw {
use MONKEY-GUTS;
Proxy.new(
  FETCH => { nqp::getattr(nqp::decont($SELF),$SELF.WHAT,$name) },
  STORE => -> $, $value {
nqp::bindattr(nqp::decont($SELF),$SELF.WHAT,$name,proxy($value))
  }
)
});
}

class A {
  has $!a is proxy({ $^a * 2 });
  has $!b is proxy({ $^a * 3 });
}

my A $a .= new;
$a.a = 21;
say $a.a;   # 42
$a.b = 21;
say $a.b;   # 63
=

Unfortunately, this involves some MONKEY guts…  lemme see if I can figure out a 
way for you not to have to do that.



Liz

Re: The equivalent of Moose's "around"

2017-11-17 Thread Elizabeth Mattijsen

> On 17 Nov 2017, at 20:09, Fernando Santagata  
> wrote:
> I tried to use the code you suggested:
> 
> sub trait_mod:(Attribute:D \attribute, :!) {
>   attribute.package.^add_method(attribute.name, my method () { proxy($_) })
> }
> 
> class A {
>   has $!a is proxy({ $^a * 2 });
>   has $!b is proxy({ $^a * 3 });
> }
> 
> my A $a .= new;
> $a.a = 21;# <-- No such method 'a' for invocant of type ‘A'

The problem here is that I forgot that the name of the attribute includes the 
sigil and the twigil.  Which you don’t want to be part of the method name.

attribute.name.substr(2) fixes this, but then other problems appear…


Looking into that now...


Liz

Re: The equivalent of Moose's "around"

2017-11-16 Thread Elizabeth Mattijsen
Oops,

> On 17 Nov 2017, at 01:24, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> sub trait_mod:(\attribute, :!) is export {

sub trait_mod:(Attribute:D \attribute, :!) is export {

so that the trait can only be used on Attribute objects.



Liz


Re: The equivalent of Moose's "around"

2017-11-16 Thread Elizabeth Mattijsen
You could probably do this nicer as an Addtribute trait:

Creator.pm
==
sub trait_mod:(\attribute, :!) is export {
attribute.package.^add_method(attribute.name,my method () { proxy($_) })
}

A.pm

use Creator;

class A {
has $!a is proxy(  );
has $!b is proxy(  );
}

Didn’t test this thoroughly, but this should give you some idea.  :-)


Liz

> On 16 Nov 2017, at 10:31, Fernando Santagata <nando.santag...@gmail.com> 
> wrote:
> 
> Maybe someone might find this useful.
> 
> In the end I concocted this kind of code. The price of simplicity at the base 
> program level is paid at the class level, with a specific BUILD submethod, 
> and with an even greater complexity at role level, where the accessors are 
> created dynamically with some metaprogramming.
> 
> role Creator {
>   method create(::class, $method, $attribute is rw, ) {
> ::class.^add_method($method, my method (::class:) {
>   Proxy.new(
> FETCH => { $attribute },
> STORE => -> $, $value { $attribute = ($value) }
>   )
> });
>   }
> }
> 
> class A does Creator {
>   has $!a;
>   has $!b;
>   submethod BUILD {
> self.create(::A, 'a', $!a, { $^a * 2 });
> self.create(::A, 'b', $!b, { $^a * 3 });
>   }
> }
> 
> my A $a .= new;
> $a.a = 21;
> say $a.a;  # 42
> $a.b = 21;
> say $a.b;  # 63
> 
> 
> On Tue, Nov 14, 2017 at 7:09 PM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> This might it then:
> 
> class A {
> has $!a;  # $.a if you want to be able to assign with .new
> method a() {
> Proxy.new(
>   FETCH => { $!a },
>   STORE => -> $, $value { $!a = $value * 2 }
> )
> }
> }
> my $a = A.new;
> $a.a = 77;
> dd $a.a;   # 154
> 
> > On 14 Nov 2017, at 18:51, Fernando Santagata <nando.santag...@gmail.com> 
> > wrote:
> >
> > Hi Liz,
> >
> > What I need is to preprocess the value before assigning it to an attribute.
> >
> > I would do that in Perl5/Moose, using "around", like this:
> >
> > package A;
> > use Moose;
> >
> > has 'attribute' => (is => 'rw', isa => 'Str');
> >
> > around [qw(attribute)] => sub {
> >   my ($next, $self, $val) = @_;
> >   return $self->$next unless $val;
> >   return $self->$next(preprocess $val); # Preprocess the value before the 
> > assignment
> > }
> >
> > In this way I don't have to make an explicit call to the preprocessor any 
> > time I assign a value to that attribute, effectively removing that from the 
> > main program.
> >
> > I'm looking for a way to do that in Perl6.
> >
> > On Tue, Nov 14, 2017 at 6:11 PM, Elizabeth Mattijsen <l...@dijkmat.nl> 
> > wrote:
> > > On 14 Nov 2017, at 18:06, Fernando Santagata <nando.santag...@gmail.com> 
> > > wrote:
> > > I'm converting a program from Perl5/Moose.
> > > I have several classes, each has some attributes that need to be 
> > > processed in the same way before being passed to other objects.
> > >
> > > When I was using Moose, I had some "around" methods that would 
> > > automatically modify the value before delivering it to those attributes, 
> > > so delegating the object to do the needed adjustments.
> > >
> > > Stripped to the bare bones, the thing that in Perl6 looks like this:
> > >
> > > class A {
> > >   has $!a;
> > >
> > >   method a($val?)
> > >   {
> > > if $val.defined {
> > >   # Modify $val in some way
> > >   $!a = $val;
> > > } else {
> > >   $!a;
> > > }
> > >   }
> > > }
> > >
> > > my A $a .= new;
> > > # $a.a = 42; # This outputs an error
> > > $a.a(42);
> > > say $a.a;
> > >
> > > Any hint how to make it work as an assignment, instead of a method call?
> > > Better yet, is there a way to abstract that behavior in a role?
> >
> > I think you want “is rw” on a public attribute?
> >
> > class A {
> > has $.a is rw;
> > }
> > my $obj = A.new;
> > $obj.a = 42;
> > dd $obj;
> > ===
> > A $obj = A.new(a => 42)
> >
> >
> >
> > Liz
> >
> >
> >
> > --
> > Fernando Santagata
> 
> 
> 
> -- 
> Fernando Santagata


Re: The equivalent of Moose's "around"

2017-11-14 Thread Elizabeth Mattijsen
> On 14 Nov 2017, at 18:06, Fernando Santagata  
> wrote:
> I'm converting a program from Perl5/Moose.
> I have several classes, each has some attributes that need to be processed in 
> the same way before being passed to other objects.
> 
> When I was using Moose, I had some "around" methods that would automatically 
> modify the value before delivering it to those attributes, so delegating the 
> object to do the needed adjustments.
> 
> Stripped to the bare bones, the thing that in Perl6 looks like this:
> 
> class A {
>   has $!a;
> 
>   method a($val?)
>   {
> if $val.defined {
>   # Modify $val in some way
>   $!a = $val;
> } else {
>   $!a;
> }
>   }
> }
> 
> my A $a .= new;
> # $a.a = 42; # This outputs an error
> $a.a(42);
> say $a.a;
> 
> Any hint how to make it work as an assignment, instead of a method call?
> Better yet, is there a way to abstract that behavior in a role?

I think you want “is rw” on a public attribute?

class A {
has $.a is rw;
}
my $obj = A.new;
$obj.a = 42;
dd $obj;
===
A $obj = A.new(a => 42)



Liz

Re: The equivalent of Moose's "around"

2017-11-14 Thread Elizabeth Mattijsen
This might it then:

class A {
has $!a;  # $.a if you want to be able to assign with .new
method a() {
Proxy.new(
  FETCH => { $!a },
  STORE => -> $, $value { $!a = $value * 2 }
)
}
}
my $a = A.new;
$a.a = 77;
dd $a.a;   # 154

> On 14 Nov 2017, at 18:51, Fernando Santagata <nando.santag...@gmail.com> 
> wrote:
> 
> Hi Liz,
> 
> What I need is to preprocess the value before assigning it to an attribute.
> 
> I would do that in Perl5/Moose, using "around", like this:
> 
> package A;
> use Moose;
> 
> has 'attribute' => (is => 'rw', isa => 'Str');
> 
> around [qw(attribute)] => sub {
>   my ($next, $self, $val) = @_;
>   return $self->$next unless $val;
>   return $self->$next(preprocess $val); # Preprocess the value before the 
> assignment
> }
> 
> In this way I don't have to make an explicit call to the preprocessor any 
> time I assign a value to that attribute, effectively removing that from the 
> main program.
> 
> I'm looking for a way to do that in Perl6.
> 
> On Tue, Nov 14, 2017 at 6:11 PM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
> > On 14 Nov 2017, at 18:06, Fernando Santagata <nando.santag...@gmail.com> 
> > wrote:
> > I'm converting a program from Perl5/Moose.
> > I have several classes, each has some attributes that need to be processed 
> > in the same way before being passed to other objects.
> >
> > When I was using Moose, I had some "around" methods that would 
> > automatically modify the value before delivering it to those attributes, so 
> > delegating the object to do the needed adjustments.
> >
> > Stripped to the bare bones, the thing that in Perl6 looks like this:
> >
> > class A {
> >   has $!a;
> >
> >   method a($val?)
> >   {
> > if $val.defined {
> >   # Modify $val in some way
> >   $!a = $val;
> > } else {
> >   $!a;
> > }
> >   }
> > }
> >
> > my A $a .= new;
> > # $a.a = 42; # This outputs an error
> > $a.a(42);
> > say $a.a;
> >
> > Any hint how to make it work as an assignment, instead of a method call?
> > Better yet, is there a way to abstract that behavior in a role?
> 
> I think you want “is rw” on a public attribute?
> 
> class A {
> has $.a is rw;
> }
> my $obj = A.new;
> $obj.a = 42;
> dd $obj;
> ===
> A $obj = A.new(a => 42)
> 
> 
> 
> Liz
> 
> 
> 
> -- 
> Fernando Santagata


Re: The equivalent of Moose's "around"

2017-11-17 Thread Elizabeth Mattijsen
> On 17 Nov 2017, at 22:47, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:
>> On 17 Nov 2017, at 20:09, Fernando Santagata <nando.santag...@gmail.com> 
>> wrote:
>> I tried to use the code you suggested:
>> 
>> sub trait_mod:(Attribute:D \attribute, :!) {
>>  attribute.package.^add_method(attribute.name, my method () { proxy($_) })
>> }
>> 
>> class A {
>>  has $!a is proxy({ $^a * 2 });
>>  has $!b is proxy({ $^a * 3 });
>> }
>> 
>> my A $a .= new;
>> $a.a = 21;# <-- No such method 'a' for invocant of type 'A'
>> say $a.a;
>> $a.b = 21;
>> say $a.b;
>> 
>> But I got an error on the first assignment.
>> What am I doing wrong?
> 
> Ok, finally had some time to figure this out more deeply.  My result:
> =
> sub trait_mod:(Attribute:D \attribute, :!) {
>my $name   = attribute.name;
>my $method = $name.substr(2);
>attribute.package.^add_method($method, my method ($SELF:) is raw {
>use MONKEY-GUTS;
>Proxy.new(
>  FETCH => { nqp::getattr(nqp::decont($SELF),$SELF.WHAT,$name) },
>  STORE => -> $, $value {
>nqp::bindattr(nqp::decont($SELF),$SELF.WHAT,$name,proxy($value))
>  }
>)
>});
> }

And this would be the version without MONKEY-GUTS, moritz++


sub trait_mod:(Attribute:D \attribute, :!) {
attribute.package.^add_method(attribute.name.substr(2), my method ($SELF:) {
Proxy.new(
  FETCH => { attribute.get_value($SELF) },
  STORE => -> $, \value { attribute.set_value($SELF,proxy(value)) }
)
});
}


Turns out the Attribute class has a set_value and get_value method.  Which 
moritz++ pointed out to me on #perl6-dev.  So no need to get gutsy!



Liz

  1   2   3   4   >