Re: Fwd: Working with a regex using positional captures stored in a variableperl6-us...@perl.org

2021-03-11 Thread Moritz Lenz
Hi there,

On 11.03.21 17:43, William Michels wrote:
> Hi Moritz your book is mentioned below. Care to chime in? Reply to
> perl6-users  .
> 
> Thx, Bill.
> W. Michels, Ph.D.
> 
> -- Forwarded message -
> From: Joseph Brenner 
> Date: Thu, Mar 11, 2021 at 12:28 AM
> Subject: Working with a regex using positional captures stored in a variable
> To: perl6-users 
> 
> 
> Does this behavior make sense to anyone?  When you've got a regex
> with captures in it, the captures don't work if the regex is
> stashed in a variable and then interpolated into a regex.
> 
> Do capture groups need to be defined at the top level where the
> regex is used?
> 
> { #  From a code example in the "Parsing" book by Moritz Lenz, p. 48,
> section 5.2
>my $input = 'There are 9 million bicycles in beijing.';
>if $input ~~ / (\d+) \s+ (\w+) / {
>say $0.^name;  # Match
>say $0;# 「9」
>say $1.^name;  # Match
>say $1;# 「million」
>say $/;
> # 「9 million」
> #  0 => 「9」
> #  1 => 「million」
>}
> }
> 
> say '---';
> 
> { # Moving the pattern to var which we interpolate into match
>my $input = 'There are 9 million bicycles in beijing.';
>my $pattern = rx{ (\d+) \s+ (\w+) };
>if $input ~~ / <$pattern> / {
>say $0.^name;  # Nil
>say $0;# Nil
>say $1.^name;  # Nil
>say $1;# Nil
>say $/;# 「9 million」
>}
> }
> 
> In the second case, the match clearly works, but it behaves as
> though the capture groups aren't there.

$0 is an alias for $/[0].

When the match is in a different variable, you need to access the
capture group as $match[0] instead of its alias $/[0].

Regards,
Moritz

-- 
Moritz Lenz
https://perlgeek.de/ -- https://raku.org/


[perl #125555] [NYI] Comparison ops for DateTimes in Rakudo

2018-02-05 Thread Moritz Lenz via RT
Tests added in https://github.com/perl6/roast/commit/ff0472adfc


Re: Where is "Subject"?

2017-02-23 Thread Moritz Lenz
Hi,

On 24.02.2017 07:51, ToddAndMargo wrote:
> Am I blind or is there nowhere to set the subject of an eMail
> in Net::SMTP?
> 
> https://github.com/retupmoca/P6-Net-SMTP

You're not blind, just thinking at the wrong level. Net::SMTP expects
you to have an email string that contains both the headers and the body
($email in the README), and the subject is part of the headers.

The only reason that $from and @to have a separate interface is that
SMTP handles them separately.

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: per 5 converter?

2017-02-12 Thread Moritz Lenz
Hi,

What's the use case for converting Perl 5 to Perl 6 automatically?

If you want to use Perl 5 code from within your Perl 6 code, you can do
that through Inline::Perl5.

But automatic translation (if it works at all) typically doesn't produce
good or idiomatic code, so you should try to stay away from it.

Cheers,
Moritz

On 12.02.2017 07:47, ToddAndMargo wrote:
> Hi All,
> 
> I know I asked this once before and I had though I'd written it
> down, but do you have any favorite Perl5 to Per6 converters?
> 
> Many thanks,
> -T
> 

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: [perl #130638] [LTA] X::Seq don't say which Seq the exception occurred on

2017-01-25 Thread Moritz Lenz


On 25.01.2017 10:47, Samantha McVey wrote:
> On Wednesday, 25 January 2017 01.45.59 PST you wrote:
>> On Tue, 24 Jan 2017 23:15:32 -0800, samant...@posteo.net wrote:
>> > CODE:
>> > my Seq $thing = (1,3,4).Seq; $thing.iterator; $thing.iterator
>> > 
>> > STDERR:
>> > This Seq has already been iterated, and its values consumed
>> > (you might solve this by adding .cache on usages of the Seq, or
>> > by assigning the Seq into an array)
>> >   in block  at  line 1
>> > 
>> > I have had lines that have multiple sequences on that, and it is very
>> > difficult to know which Seq it was without a nice error.
>> 
>> What would you suggest we do? The point of the Seq iterator is that it 
>> doesn't generally store the old values, so pretty much by definition we 
>> *can't* give more details about the contents of the Seq, and we generally 
>> don't know which variable it's stored in either.
>> 
>> Unless somebody has a good idea on how to improve this, I'd close it as 
>> "sadly won't fix".
>> 
>> Cheers,
>> Mority
>> 
>> 
> 
> I don't want the values of the Seq, I want the name of the variable.

Trying to find the name of a variable (if there is one at all) from the
object is inherently brittle, and has lead to many false positives in
the past (like reporting the name of a parameter from a routine in CORE
somewhere).

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: mocking $*OUT

2017-01-24 Thread Moritz Lenz
Hi Brian,

On 24.01.2017 23:28, Brian Duggan wrote:
> Hi All,
> 
> This code:
> 
>   my $str = '';
>   class Mock {
> method say($arg) { $str ~= $arg }
>   }
>   $*OUT = Mock.new;
>   say 'hi';
> 
> produces:
> 
>   Too many positionals passed; expected 1 argument but got 2
> in block  at out.p6 line 6
> 
> Changing the signature of say doesn't seem to help.
> 
> If I change 'say' to 'print' in Mock, things work
> fine, though I'm having a hard time figuring out why
> the code above doesn't work.  Any ideas?

Because say() is a high-level function that uses the lower-level
$*OUT.print under the hood.

>From rakudo's src/core/io_operators.pm:

multi sub say(Str:D \x) {
my $out := $*OUT;
$out.print(nqp::concat(nqp::unbox_s(x),$out.nl-out));
}

You might be interested in
https://perlgeek.de/blog-en/perl-6/2016-book-testing-say.html :-)

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: A stricter typed variable

2017-01-07 Thread Moritz Lenz
Hi,

On 07.01.2017 15:52, Joseph Garvin wrote:
> Being able to type the elements in containers was considered a major
> problem in Java for years before they added generics. 

Please note that Java and Perl 6 are coming from very different
directions. Java 1 a statically typed language, where every operation
whose type safety the compiler can't prove at compile time is rejected.
So with untyped containers in Java 1.4-, you needed explicit runtime
casts juts to call methods on container elements.

Perl used to be a dynamically typed language, which means that the
compiler basically never rejected a program due to type errors. Type
errors can happen at run time.

> And the whole
> point of having a computer is to have it do repetitive things, e.g. loop
> over a bunch of stuff and do the same thing to all of it.

You can loop over a bunch of stuff and do the same thing to all of it
without explicitly typing the contents of an array. That's what all
other dynamically typed languages tend to do (python, ruby, lua, PHP,
you name it).


If you have, for example:

sub wants-str(Str $x) { ...}
sub test(@a) {
   for @a -> $x { wants-str($x) }
}

Perl 6 happily compiles and executes this, because it can't prove a type
error at compile time. Java OTOH would reject the equivalent code.


> How is this an
> "exaggerated" use of containers? Why have the language feature at all if
> it's too clunky for people to use it?

I'm not saying it's always too clunky to use. I'm saying there's a cost
attached, and you should consider whether to use it.

I observe some weird behavior in Perl 6 newbies (and I've observed it in
myself too): they're so enamored by type constraints that they use them
everywhere, and run into all sorts of type errors they didn't expect.
The weird part is that if they wanted a statically typed language, they
could have easily chosen one. But they picked Perl 6, and then they try
to use it like a statically language, and wonder why it feels clunky.

If you write a type constraint, ask yourself: could there be an object
from another type that my could would also work with? Maybe I'm just
calling a method that's implemented in type Str, but a user-supplied
object could implement the same method as well. If it walks like a duck,
and quacks like a duck, do I really have to care if it's a duck or not?

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: A stricter typed variable

2017-01-07 Thread Moritz Lenz
Hi,

On 07.01.2017 12:45, Fernando Santagata wrote:
> Hello,
> 
> I have a function like this:
> 
> sub test(Str :$format, :@filter)
> {
>   say $format;
>   say @filter;
> }
> 
> and I wish to have a stricter type control over the second parameter.
> 
> The natural way to do it seemed this:
> 
> sub test(Str :$format, Array[Str] :$filter)
> {
>   say $format;
>   say $filter;
> }
> 
> but then I have to call it this way:
> 
> test format => 'gnutar', filter => Array[Str].new('gzip', 'uuencode');
> 
> Is there a less cumbersome way to do it?

As you have discovered, you need to be explicit about the type of the
argument that's passed in.

You can use anonymous variables to write an Array[Str] more compact:

test format => 'gnutar', filter => my Str @ = 'gzip', 'uuencode';

or even

test format => 'gnutar', filter => my Str @ = ;

My general advise is to not exaggerate the usage of container types.
Think of Perl 6 as a dynamically typed language, and only add types
where they make life easier for everybody involved.

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


[perl #130396] [BUG] =:= operation aginst item contextualized object returns incorrect result

2016-12-23 Thread Moritz Lenz via RT
This is not a bug. $b is a container that contains the array @a, so @a !=:= $b.
:
An easy test is assigning to $b, and see if it's reflected in @a:

$ perl6 -e 'my @a = 1,2; my $b = @a.item; $b = 42; say @a'
[1 2]


Re: [perl #130371] [REGRESSION] return in block does not return from sub that is parameterised with that block

2016-12-18 Thread Moritz Lenz
Hi,

On 18.12.2016 15:35, Wenzel Peppmeyer (via RT) wrote:
> # New Ticket Created by  Wenzel Peppmeyer 
> # Please include the string:  [perl #130371]
> # in the subject line of all future correspondence about this issue. 
> # https://rt.perl.org/Ticket/Display.html?id=130371 >
> 
> 
> my  = { say 'returning from '; return };
> sub returned-from() { say 'enter returned-from'; code; say 'leave 
> returned-from' };
> sub forcing-a-return { returned-from  };
> forcing-a-return;
> 
> # OUTPUT«enter returned-from␤returning from ␤Attempt to return outside 
> of any Routine␤  in block  at  line 1␤␤»
> # expected
> # OUTPUT«enter returned-from␤returning from ␤»
> # this may be a regression caused by a4ca12afa30be4ce5dfc3602f54a5563d069ffa5

I'm pretty sure that's not a bug;  is supposed to be tied to the
lexically outer Routine, and in this example, there is no lexically
outer Routine, so the error message is valid.

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: Need some help to understand how modify an AST.

2016-12-05 Thread Moritz Lenz
Hi,

On 06.12.2016 00:49, CARAYOL Jean-Pierre wrote:
> Hi,
> 
> 
> 
> I don't understand why the 2 following Perl6 programs give a different
> result when running.
> 
> If someone could give me an explanation, it will help me a lot. Many thanks.
> 
> 
> 
> /(Note the 2 programs run on Linux and the Linux environment variable
> $toto is set to "totoenv". ( export toto=totenv )/
> 
> 
> _Program1 :_
> 
> /cattest051.pl6/_
> _
> 
> #!/opt/rakudo-star-2016.10/bin/perl6
> use v6;
> 
> grammar TEST {
> rule  TOP { :i \s*}
> token varenv {'$' }
> token mot { <[a..z A..Z 0..9 =\-_!~'():@&+$,\']>+ }
> }
> 
> class ActionsTest {
> method TOP ($/) { $/.make( ~%*ENV{$}); }
> }
> 
> my $actions = ActionsTest.new;
> my $script = "\$toto" ;
> my $scr = TEST.parse($script,:$actions);
> say $scr;
> say $scr.made;
> ===>./test051.pl6
> 「$toto」
>  varenv => 「$toto」
>   mot => 「toto」
> *totoenv*
> 
> This programs runs fine and displayed the value for the toto environment
> variable.
> 
> 
> 
> _Program2:_
> 
> __cat test052.pl6
> 
> grammar TEST {
> rule  TOP { :i \s*}
> token varenv {'$' }
> token mot { <[a..z A..Z 0..9 =\-_!~'():@&+$,\']>+ }
> }
> 
> class ActionsTest {
> method varenv ($/) { $/.make( %*ENV{$}); }
> method TOP ($/) { $/.make( ~$/); }

$/.make stores the result in $/.made, so the second line should be

method TOP($/) { $/.make($.made) }

HTH,
Moritz

> }
> 
> my $actions = ActionsTest.new;
> my $script = "\$toto" ;
> my $scr = TEST.parse($script,:$actions);
> say $scr;
> say $scr.made;
> 
> ===>
> Use of Nil in string context
>   in method varenv at ./test052.pl6 line 14
> 「$toto」
>  varenv => 「$toto」
>   mot => 「toto」
> $toto
> 
> This program displays an error message and doesn't find the value of
> toto environment variable.
> 
> 
> The only difference between the 2 programs is instruction "make(
> %*ENV{$}" is part of the TOP method in the program 1 and
> part of the varenv method in program 2.
> 
> I'm certainly missing something but I don't understand why program 2
> doesn't work. I'm very interested to get explanations for that. It will
> help me to understand how to modify and AST using Perl6.
> 
> 
> Thanks a lot for your help.
> 
> Best regards,
> 
> Jean-Pierre 
> 
> 

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: What is rakudo-star?

2016-11-18 Thread Moritz Lenz

On 19.11.2016 03:14, _ ifdog wrote:
> So why there is not a star release of 2016.10  for windows ?

Because nobody one yet. I'm happy to upload it for you if you provide it.

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: Where to start?

2016-11-18 Thread Moritz Lenz
Hi,

On 19.11.2016 03:34, ToddAndMargo wrote:
> Hi All,
> 
> I just install rakudi-star in my Fedora 24 virtual machine.
> 
> I know how to program and run things in perl 5.
> 
> Can someone point me to a how to that will show me the
> basic template for running a perl 6 program in Linux.

#!/usr/bin/env /path/to/your/rakudo/inst/bin/perl6

use v6;


> Also, do I need to run perl6 through a compiler or
> does it compile on the fly like perl 5?

There's no separate compilation step.

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: What's involved in the creation of a new Rakudo * version?

2016-10-16 Thread Moritz Lenz
Hi

On 16.10.2016 17:24, Parrot Raiser wrote:
> We "Star" users are falling rather behind the compiler versions.
> I'd like to help catch up, if the processes involved are sufficiently mundane.
> Is there a checklist of the required tasks from which to work?

Yes, there is:
https://github.com/rakudo/star/blob/master/tools/star/release-guide.pod

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: think I found a bug in the doc's

2016-10-04 Thread Moritz Lenz
Hi,

On 04.10.2016 13:06, Francis (Grizzly) Smit wrote:
> in https://docs.perl6.org/type/Int#routine_expmod
> 
> it reads:
> 
> 
> routine expmod <https://docs.perl6.org/type/Int#___top>
> 
> multi  sub expmod(Int  $y,Int  $mod)returns  Int:D
> multi  method  expmod(Int:D:  Int  $y,Int  $mod)returns  Int:D
> 
> Returns the given |Int| raised to the |$y| power within modulus |$mod|.
> 
> say  expmod(4,2,5);# 1
> say  7.expmod(2,5);# 4
> 
> 
> Shouldn't the su form read:
> 
> multi  sub expmod(Int:D $x,Int  $y,Int  $mod)returns  Int:D it needs 
> three parameters

Yes, that's right.

If you tell me your github username, I can give you access so that you
can change it directly on https://github.com/perl6/doc/.

Otherwise a pull request would be very welcome.

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: What are variables/parameters that start with a pipe | char

2016-10-01 Thread Moritz Lenz
Hi,

On 01.10.2016 04:22, Francis (Grizzly) Smit wrote:
> I keep finding stuff like this:
> 
> multi method spurt(IO::Path:D: Blob $contents, :$bin, |c)
> multi method spurt(IO::Path:D: Cool $contents, :$bin, |c)
> 
> 
> but I cannot find the |c syntax in the docs I have googled but no good 
> a pointer or link would be good. 

Just for the record, a good approach to find such a thing would be to
type the defining character, here the |, into search box on
https://doc.perl6.org/.

It doesn't work for everything, but for | it does give you, among other
things, "| (parameter)", which points to relevant documentation.

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: Sorting Multidimentional Arrays

2016-10-01 Thread Moritz Lenz
Hi,

On 01.10.2016 19:57, mimosinnet wrote:
> I have been searching on how to sort multidimensional arrays. The 
> following code works and sorts the fourth column of the array:
> 
> ---
> #!/usr/bin/env perl6
> # sort multidimensional array 
> 
> my @opposite = (
>   <8976 ABD AB11 6LX NJ >,
>   <8860 PLN AB12 4JS NO >,
>   <8905 DYC AB21 7EQ NJ >,
>   <8964 STN AB39 2NE NO >,
> );
> 
> for @opposite -> $line { say $line; }
> say "-" x 22;
> @opposite = @opposite.sort({@$^a[3]});

For the record, you can simplify this a bit:

@opposite = @opposite.sort(*[3]);


> for @opposite -> $line { say $line; }
> ---
> 
> I have adapted this from: 
> http://www.wellho.net/resources/ex.php?item=p600/mapper
> 
> I wanted to ask about the syntax, buy I have understood it while 
> writing the message ;) :D 

I've had the same experience a few times :-)

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: unicode

2016-09-17 Thread Moritz Lenz
Hi,

On 17.09.2016 13:12, MT wrote:

> Searching further I found the ucd2c.pl program in the Moarvm tools 
> directory. This generates the unicode_db.c somewhere else in the rakudo 
> tree. I run this program myself on the Unicode 9.0.0 database and 
> comparing the generated files shows many differences between the one in 
> the rakudo tree and the generated one.

Please make a rakudo spectest with those changes, and if it passes,
submit your patch as a pull request.

> The date found in the file  unicode_db.c file is 2012-07-20 which is 
> about Unicode version 6.1.0

docs/ChangeLog in MoarVM says

+ Updated to Unicode 8

in the section of the 2015.07 release, so it's not that bad :-)

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: grammars and indentation of input

2016-09-13 Thread Moritz Lenz
Hi,

On 13.09.2016 18:55, Patrick R. Michaud wrote:
> I don't have an example handy, but I can categorically say that
> Perl 6 grammars are designed to support exactly this form of parsing.
> It's almost exactly what I did in "pynie" -- a Python implementation
> on top of Perl 6.  The parsing was done using a Perl 6 grammar.

See https://github.com/arnsholt/snake for a newer implementation that
parses python (or subsets thereof). Its grammar is likely inspired by
pynie, but your chances to get it to run are much better, due to the
more recent development that has gone into it.

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: Inline::Python panda installation fails

2016-07-13 Thread Moritz Lenz

Hi,

On 07/13/2016 11:01 AM, The Holy Ghost wrote:


On linux 2016.04 and windows 2016.01 :

==> Fetching Inline::Python
==> Building Inline::Python
gcc pyhelper.c -Wall -I"/usr/include/python2.7" -L"/usr/lib/python2.7/config" 
-lpython2.7 -shared -o /home/erana/.panda-work/1468400277_1/resources/libraries/libpyhelper.so 
-fPIC -g
pyhelper.c:1:20: fatal error: Python.h: No such file or directory


It seems you do need a Python.h, so a libpython-dev of python-devel or 
so package that includes the header files.


Cheers,
Moritz


Re: [perl #128428] [BUG] Behaviour of div / mod on Non-Ints

2016-06-20 Thread Moritz Lenz

Hi,

On 06/18/2016 12:39 AM, Zoffix Znet (via RT) wrote:

# New Ticket Created by  Zoffix Znet
# Please include the string:  [perl #128428]
# in the subject line of all future correspondence about this issue.
# https://rt.perl.org/Ticket/Display.html?id=128428 >


Current implementation of `mod` has (Real, Real) signature and uses `div 
(Int,Int)` to perform the division. This creates an LTA error that mentions 
`div` when argumenemts aren't Ints:

 m: say 2 mod 1.5
 rakudo-moar 5ca43c: OUTPUT«Cannot resolve caller infix:(Int, Rat); none of 
these signatures match:␤(Int:D \a, Int:D \b)␤(int $a, int $b --> int)␤  in block  
at  line 1␤␤»

Reading the spec (http://design.perl6.org/S03.html), descriptions of 
infix:/infix: suggest they should work on all numeric types, as long 
as LHS/RHS are the same type:


But that's not what your example uses. It's Int mod Rat, so it 
explicitly falls into this category:


: Not coercive, so fails on differing types.

So I don't see the bug yet.

Cheers,
Moritz



-quote from spec--
===
infix:, integer division

 $numerator div $denominator

Dispatches to the infix: multi most appropriate to the operand types, 
returning a value of the same type. Not coercive, so fails on differing types.

Policy on what to do about division by zero is up to the type, but for the sake 
of hyperoperators and junctions those types that can represent overflow (or 
that can contain an unthrown exception) should try to do so rather than simply 
throwing an exception. (And in general, other operators that might fail should 
also consider their use in hyperops and junctions, and whether they can 
profitably benefit from a lazy exception model.)

On the other hand, div wants to be very efficient and jittable when used as a 
low-level operation, so when you use div on two native ints, it relies on 
hardware to detect division by 0. Hence, it will always throw an exception 
rather than return a Failure.

In general, div should give the same result as

 $x div $y == floor($x/$y)

but the return value should be the same type as $x.

This identity stops holding when $x/$y degrades to a Num and runs into 
precision limits. A div operation on two Int objects must always be done 
precisely.

===
infix:, integer modulo

 $x mod $y

Dispatches to the infix: multi most appropriate to the operand types, 
returning a value of the same type. Not coercive, so fails on differing types.

This should preserve the identity

 $x mod $y == $x - ($x div $y) * $y
-/quote from spec--



Re: NativeCall interface for a char ** argument

2016-05-27 Thread Moritz Lenz
Hi,

On 25.05.2016 17:35, Fernando Santagata wrote:
> Hello,
> 
> Please excuse my naivety, I'm trying to use NativeCall to interface a
> Perl6 program with a C library and I have a problem mapping a char **
> argument.
> 
> The C function has this prototype:
> 
> void function(char **arg1, char **arg2);
> 
> I read that declaring a sub with Str rw parameters would do the trick:
> 
> sub test(Str $arg1 is rw, Str $arg2 is rw) is native('mylibrary') { * }
> 
> When I use the imported test function:
> 
> my Str ($arg1, $arg2);
> test($arg1, $arg2);
> say $arg1, $arg2;
> 
> what appears is just
> 
> (Str)(Str)

In my experience, "is rw" doesn't always work, and I have no idea when
or why.

In DBIish (a DB interface with backends for PostgreSQL, mysql, sqlite3
and Oracle, iirc) we tend to use CArray[Str] for the parameters, see for
example
https://github.com/perl6/DBIish/blob/master/lib/DBDish/Pg/Native.pm6#L83-92

Cheers,
Moritz


Re: How to capture an div 0 exception

2016-05-18 Thread Moritz Lenz



On 05/18/2016 01:39 PM, mt1957 wrote:

On 18-05-16 13:07, Richard Hainsworth wrote:

use v6;
my $d = 1;
my $e = 2;
my $f = 0;
#my $r;
my $r = 5;

CATCH {
# when X::AdHoc {
when Exception {
.Str.say;
# $r = 5;
 .resume
} }

$r = try {
( $d + $e ) / $f;
};

# my $r = try EVAL ' ( 1 + 2 ) /0 ';

say "r is $r";


Hi Richard,

There are a few things to mention;

Write CATCH in a block. In that block you must test the things which
might go wrong. Like so;

try {
...
CATCH {
  when  {
  
  }

  default {
  ...
  }
}
}


if you have an explicit CATCH block, you don't need a try { ... } on the 
outside.



Below there is some other code about your example;

my $r;
{
try {
  my $d = 1;
  my $e = 2;
  my $f = 0;

  $r = ( $d + $e ) / $f;
  say "r is $r";

  CATCH {

.WHAT.say;
when X::Numeric::DivideByZero {
  $r = 65;
  .resume;
}

default {
  $r = 55;
  .resume;
}


If you want to only catch exceptions of type X::Numeric::DivideByZero, 
don't supply a default block.


Cheers,
Moritz


Re: Fwd: perl6 INC

2016-05-11 Thread Moritz Lenz

On 05/11/2016 04:30 PM, Bennett Todd wrote:

Thanks for the explanation. Sounds like an unfortunate situation, rather than 
letting the system admin choose modules within the limits of filesystem 
namespace,  it's using a separate database, opaque to filesystem tools. I hope 
this is just a temporary hack until a mature solution is hammered out.


We'd love it to be temporary, but until all target platforms (Linux, Mac 
OS X, Windows) can offer fully Unicode-capable, case sensitive file 
systems, we *have* make our own workarounds.


Cheers,
Moritz



Re: Unwanted failure and FAILGOAL

2016-05-11 Thread Moritz Lenz

Hi,

On 05/11/2016 07:45 AM, Richard Hainsworth wrote:

I have the following in a grammar

 rule TOP{ ^ + $ };

 rule statement  {  '=' 
  | { { self.panic($/, "Declaration syntax
incorrect") } }
 };

 rule endvalue   {  '(' ~ ')' 
  | { self.panic($/, "Invalid declaration.") }
 }

The grammar parses a correct input file up until the end of the file. At
that point even if there is no un-consumed input, there is an attempt to
match , which fails. The failure causes the panic with 'Declaration
syntax'.

Am I missing something simple here?

I would have thought  (though this is only a very newbie assumption)
that if the end of the input being sent to the grammar has been reached
after the last  has been matched, then there should be no
reason for the parse method to try to match  again, and if it
fails to test for the end of input.


This is not how regexes or grammars work.

The + quantifier tries as many times as possible to match the regex. It 
doesn't look ahead to see if more characters are available, and it 
doesn't know about the end-of-string anchor that comes next in the grammar.


In fact, it doesn't know if the rule it quantifies might have a way to 
match zero characters. In this case, it would be wrong behavior to not 
do a zero-width at the end of the string.


As for improving the error reporting from within a grammar, there are 
lots of way to get creative, and I'd urge you to read Perl 6's own 
grammar, which is a good inspiration for that.

See https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Grammar.nqp

One thing you could do is structure the statement rule differently:

rule statement {

   [  '=' 
   || { self.panic($/, "Invalid declaration.")
   ]
}

And maybe also TOP:

rule TOP{ ^ [  || . { self.panic($/, "Expected a 
statement") } ] $ };


That extra dot before the panic ensures it's not called at the end of 
the string. If you don't want that, you could also do


[  || $ || { self.panic(...) } ]

Cheers,
Moritz


Re: Work around to "unwanted fail"

2016-05-11 Thread Moritz Lenz

Hi,

On 05/11/2016 09:22 AM, Richard Hainsworth wrote:

I had

grammar RatingGrammar {

 rule TOP{ ^ + $ };

 rule statement  {  '=' 
  | {
 if ($/.CURSOR.pos < $/.orig.chars) {

 self.panic($/, "Declaration syntax
incorrect.")
 }
 }
 };


This generates an error for a correct input because it fails 
at the end of input.


I think the problem is that you use | which instructs the compiler to 
try both paths "at the same time" (no extra threading involved, just 
notionally). You really want to use || instead, which is "first try the 
first path, and if it doesn't work, try the second path".


Cheers,
Moritz


Re: DBIish: Why can't I interpolate variable holding database name?

2016-05-01 Thread Moritz Lenz
On 01.05.2016 15:36, James E Keenan wrote:
> 
> Thanks; that worked:
> 
> #
> cat dbiish_connect_dynamic_3.pl6
> #!/usr/bin/env perl6
> use DBIish;
> 
> my $db = 'hierarchy';
> my $dbh = DBIish.connect("Pg", :database($db));

Another nice little language feature is that you can reuse the name of
variable when it coincides with the name of the named parameter.

So :database($database) just becomes :$database.

Which today often influences how I name my variables:

my $database = 'hierarchy';
my $dbh = DBIish.connect('Pg', :$database);

(and it's a feature I miss surprisingly often when back in perl 5 or
python land).

Cheers,
Moritz


Re: question about Supply.act()

2016-04-28 Thread Moritz Lenz

On 04/28/2016 11:11 AM, mt1957 wrote:

Hi,

The documentation about the method act explains that 'the given code is
guaranteed to be only executed by one thread at a time'.

Can I assume from this that any other thread including the main thread
isn't running?


No. Other threads might still be running and do other things.

Cheers,
Moritz


Re: Perl 6 pod-handling code seems widely scattered

2016-04-27 Thread Moritz Lenz

On 04/25/2016 03:27 PM, Tadeusz Sośnierz wrote:

On 25/04/16 14:13, Tom Browder wrote:

I would like to hack on the pod handling code (particularly the HTML
generation) but it seems to be quite scattered around github.  Is
http://github.com/perl6/Pod::To::HTML>> the definitive repo location
for that chunk?

Yes, that's the module that turns Pod AST into HTML. That's what you're
looking for :)



It's a document tree, not really an AST.
The AST is an intermediate format inside the compiler that user-space 
modules don't see.



Cheers,
Moritz :-)


Re: [perl #127890] [IMPROVEMENT PROPOSAL] Test.pm6 make subtest multi to take description first

2016-04-13 Thread Moritz Lenz

Hi,

On 04/13/2016 02:52 PM, Zoffix Znet (via RT) wrote:

# New Ticket Created by  Zoffix Znet
# Please include the string:  [perl #127890]
# in the subject line of all future correspondence about this issue.
# https://rt.perl.org/Ticket/Display.html?id=127890 >


Hey,

I propose we make Test.pm6's `subtest` a multi sub that can also take a Pair. 
The key of the Pair is to be the description of the test and the value is to be 
the codeblock to run.

Test.pm6 has `subtest` sub that lets you group your tests. It takes a code 
block and description, but that description follows AFTER the codeblock, 
following the same pattern as all the other subs the module provides.

The problem is unlike all the other subs, `subtest` takes a codeblock, which 
can get large quickly.
A programmer reading the code has to skip through all the way to the END of the 
codeblock to find
the description and understand what the subtest is testing.

Here's an example of the current way to use subtest:

 subtest {
 my $res= $glot.list;
 ok $res.keys ⊆ , 'return keys match expectations';

 my $expected
 = ;
 for |$res {
 ok .keys ⊆ $expected, 'item keys match expectations';
 }
 }, '.list method';

My proposal, if implemented, would allove the above to be written as:

 subtest '.list method' => {
 my $res= $glot.list;
 ok $res.keys ⊆ , 'return keys match expectations';

 my $expected
 = ;
 for |$res {
 ok .keys ⊆ $expected, 'item keys match expectations';
 }
 };


Why not simply allow two ordinary arguments?

Like this:
subtest 'description', { code here };

Since one of the arguments is always a string or String-alike (probably 
Cool), and the other is always Callable, there shouldn't be any 
ambiguous cases.


All in all I approve of this idea though.

Cheers,
Moritz


Re: [perl #127878] UTF8-C8 + Str.subst either dumps core or corrupt memory

2016-04-12 Thread Moritz Lenz


On 11.04.2016 17:00, Moritz Lenz wrote:
> On 04/11/2016 03:04 PM, Nicholas Clark wrote:
>> On Mon, Apr 11, 2016 at 04:39:59AM -0700, H. Merijn Brand wrote:
>>
>>> In a one-liner:
>>>
>>> $ p6 -e'my$b=Buf.new(61,^2048 .map({256.rand.Int}));my Str 
>>> $u=$b.decode("utf8-c8");$u.=subst(/("a"|"b")/,{"c$0"},:g);'
>>> Segmentation fault
>>>
>>> or (same code)
>>
>> With timotimo's commit from this afternoon:
>>
>> commit 808fd05041b3d846b0a54acc4297299af2a1b71d
>> Author: Timo Paulssen <timona...@perpetuum-immobile.de>
>> Date:   Mon Apr 11 14:05:57 2016 +0200
>>
>>  cope with buffers being too small in re_nfg
>>
>>  fixes a crash when working with utf8-c8 strings.
>>
>>
>> that one liner changes from ASAN barfage to no output.
>> (which means that the SEGV is fixed).
>>
>> That means it's now "tests needed" ?
> 
> It is.
> 
> I'd also be grateful if somebody could provide a deterministic string of 
> numbers that made Rakudo segfault, because I hate having fuzzy/random 
> tests in the test suite.

Turns out that somebody is me :-)

This code coredumps reliably on a not-yet-patched rakudo for me:

use v6;
my @ints = 103, 248, 111, 217, 210, 97;
my $b = Buf.new(@ints);
my Str $u=$b.decode("utf8-c8");
$u.=subst("a","b");

Cheers,
Moritz


> Cheers,
> Moritz
> 


Re: [perl #127878] UTF8-C8 + Str.subst either dumps core or corrupt memory

2016-04-11 Thread Moritz Lenz

On 04/11/2016 03:04 PM, Nicholas Clark wrote:

On Mon, Apr 11, 2016 at 04:39:59AM -0700, H. Merijn Brand wrote:


In a one-liner:

$ p6 -e'my$b=Buf.new(61,^2048 .map({256.rand.Int}));my Str 
$u=$b.decode("utf8-c8");$u.=subst(/("a"|"b")/,{"c$0"},:g);'
Segmentation fault

or (same code)


With timotimo's commit from this afternoon:

commit 808fd05041b3d846b0a54acc4297299af2a1b71d
Author: Timo Paulssen 
Date:   Mon Apr 11 14:05:57 2016 +0200

 cope with buffers being too small in re_nfg

 fixes a crash when working with utf8-c8 strings.


that one liner changes from ASAN barfage to no output.
(which means that the SEGV is fixed).

That means it's now "tests needed" ?


It is.

I'd also be grateful if somebody could provide a deterministic string of 
numbers that made Rakudo segfault, because I hate having fuzzy/random 
tests in the test suite.


Cheers,
Moritz


[perl #66820] Null PMC access in find_method() while accessing bound return value from gather/take

2016-03-12 Thread Moritz Lenz via RT
On Sun Jun 21 11:24:57 2009, moritz wrote:
> $ perl6 -e 'my @a := gather {  for 1..3 { take $_; say @a.perl } }; say
> @a.perl'
> Null PMC access in find_method()
> in Main (:1)

Current behavior:

Type check failed in binding; expected Positional but got Seq (?)


If I change it to 'my \a = gather { ... }'

I get

$ ./perl6 -e 'my \a = gather { for 1..3 { take $_; say a.perl } }; say
a.perl'
Seq.new-consumed()
Seq.new-consumed()
Seq.new-consumed()
(1, 2, 3).Seq

Which, IMHO, is sane enough to make this ticket go away.


Re: Confused about rakudobrew and Rakudo Star

2016-02-08 Thread Moritz Lenz

On 02/06/2016 12:37 AM, Brock Wilcox wrote:

Also note that in my listing I installed a specific rakudo release, the
one that is included in the star tarball. That way further rakudo
releases are irrelevant.


There's a contradiction in terms here: if there were no Rakudo releases, 
you couldn't specify a Rakudo by version. Which means Rakudo releases 
are still quite relevant.


Cheers,
Moritz


Re: Installing both from rakudobrew and Rakudo Star

2016-02-05 Thread Moritz Lenz



On 02/05/2016 01:57 AM, James E Keenan wrote:

Follow-up questions to those I posed on perl6-users today.

So I have successfully used rakudobrew to build moar and panda.  That
perl6 executable is located here:
$ which perl6
/home/jkeenan/.rakudobrew/bin/perl6

Now, suppose I *also* wish to install Rakudo Star.  I've downloaded the
rakudo-star-2016.01 tarball and have read the instructions in README for
installation.  From past experience, I guess that if I say simply:

$ perl Configure.pl --backend=moar --gen-moar
$ make
$ make install

... that this will install in /usr/local/bin/.  Is that recommended
(assuming that my main emphasis is on learning Perl6 in the context of a
beginners study group)?


I generally recommend installing star releases.
We didn't have an R* release for some time, which is why recommendations 
for perlbrew have started to show up, but that's more for staying at the 
(b)leading edge, not for beginners.



Is there a PREFIX setting,


sure, Configure.pl --prefix=... --gen-moar

(--gen-moar implies backend moar)


should I wish to install it under my home
directory?


It makes permission management easier, which is why I tend to do that.

Cheers,
Moritz


Re: Confused about rakudobrew and Rakudo Star

2016-02-04 Thread Moritz Lenz



On 02/04/2016 01:26 PM, James E Keenan wrote:

On 02/03/2016 10:48 PM, Brandon Allbery wrote:

On Wed, Feb 3, 2016 at 10:30 PM, James E Keenan 
wrote:


I am evidently confused as to the relationship, if any, between the
'rakudobrew' utility and the Rakudo::Star distribution.



In short: rakudobrew is for the folks who want to track the rapid
development of Rakudo. Star is for folks who want something stable in
order
to play with the language, and includes the Task::Star ecosystem. As Star
was cut earlier today, it's based on the rakudo that was current earlier
today (and still fairly current as there haven't been many commits in the
past few hours).

It's more or less the difference between a Python or Perl 5 release, and
installing either from git HEAD. rakudobrew builds from HEAD; Star is a
release, which happens to be close to HEAD at the moment because it was
just created. HEAD will keep moving; Star will stay stable for a while
(used to be monthly, but they're considering releasing less often now)
before the next release.



So, to clarify:  If I want to get this week's release of Rakudo Star on,
say, Linux, I have to download this tarball:

http://rakudo.org/downloads/star/rakudo-star-2016.01.tar.gz

... and build from source -- correct?  I cannot use rakudobrew for
Rakudo Star -- correct?


Correct on both.


Re: Confused about rakudobrew and Rakudo Star

2016-02-04 Thread Moritz Lenz

Hi,

On 02/04/2016 01:44 PM, Brock Wilcox wrote:

If my understanding is correct (might not be), the tarball should be
ALMOST equivalent to:

 rakudobrew build moar 2016.01.1 # Install rakudo 2016.01.1
 rakudobrew global 2016.01.1 # Make this the default
 rakudobrew build panda  # Build panda for this rakudo
 panda install Task::Star# Get the latest Task::Star,
needs --force to do again

I just did these steps on my Debian machine with no problems.

The main issue I can think of is the last step -- installing Task::Star
installs the current version of all the packages, whereas the tarball
rakudo-star release includes a specific version of each of the Star
modules. If someone updates SVG then this will get the LATEST, not the
one in the official release. I think this is a weakness of the
versioning system -- ideally you'd be able to do something like "panda
install Task::Star=2016.01" and get the exact same thing.

I see Moritz replied to this also saying that the tarball is the way to
go. I'd love to know what I'm missing out on by doing it this way.


Exactly what you speculated above.

The correct approach would be to have releases from each module, and 
depend on these versions, and then one could make a Task::Star release 
that depends on these specific versions.


Cheers,
Moritz




Re: Rationale for $!

2016-01-28 Thread Moritz Lenz
Hi,

On 01/28/2016 04:06 PM, Todd C. Olson wrote:
> Is there a way to make the exception be thrown eagerly, at the devision 
> statement rather than waiting until use, at the say statement?

Yes, 'use fatal;'

Cheers,
Moritz


Re: Rationale for $!

2016-01-27 Thread Moritz Lenz

On 01/27/2016 04:32 PM, Felipe Gasper wrote:

On 27 Jan 2016 10:15 AM, Moritz Lenz wrote:


On 01/27/2016 03:15 PM, Felipe Gasper wrote:

So, what *is* the scoping of $!?


Scoped to a routine, iirc (sub, method, regex)


Interesting. JavaScript programmers that I’ve known bemoan that their
language uses function scoping rather than block scoping.

That also seems incongruent with the built-in block scoping for try/CATCH.

Has Perl 6 embraced function scoping as a major paradigm, then?


I wouldn't say "major paradigma", but it's not the only construct that 
uses routine scoping. return() and fail() come to mind, which are also 
routine-scoped.



But, what is the point of $! at all?


Convenience. It makes it easy to write commonly-used constructs much faster.

My mostly unscientific approach to gather usage of try vs. CATCH in the 
ecosystem:
moritz@hack:~/p6/perl6-all-modules$ git grep --word CATCH | wc -l 


461
moritz@hack:~/p6/perl6-all-modules$ git grep --word try | wc -l
864

CATCH is also rather clunky by comparison (requires an explicit block, 
whereas 'try' can be used as a statement prefix; requires a "when" or 
"default" blocks).



$! is also not mentioned here: http://perl6intro.com/#_exception_handling


Feel free to fix that by submitting a pull request :-)

Cheers,
Moritz


Re: Rationale for $!

2016-01-27 Thread Moritz Lenz

Hi,

On 01/27/2016 07:17 AM, Felipe Gasper wrote:

Hello,

 What is the purpose of having $! in Perl 6?

 The global variables in Perl 5 are a constant headache, prompting
us to need to local()ize variables like $@, $!, and $? to avoid
unforeseen consequences like RT #127386 and those documented in
Try::Tiny’s POD.

 Perl 6 seems to give us both the “right” and the “wrong” solution
to accessing exception variables: we get $_ within a CATCH block
(right), but we also get that global $!--which, to me, seems
pathologically wrong.


But it's not global! None of $_, $/, $! are global.

Cheers,
Moritz


Re: Rationale for $!

2016-01-27 Thread Moritz Lenz


On 01/27/2016 03:15 PM, Felipe Gasper wrote:

So, what *is* the scoping of $!?


Scoped to a routine, iirc (sub, method, regex)


Re: Is there another way to define a regex?

2016-01-17 Thread Moritz Lenz


On 01/17/2016 06:07 PM, Tom Browder wrote:
> I'm trying to write all new Perl code in Perl 6.  One thing I need is
> the equivalent of the Perl 5 qr// and, following Perl 6 docs, I've
> come to use something like this (I'm trying to ignore certain
> directories):
> 
> # regex of dirs to ignore
> my regex dirs {
>   \/home\/user\/\.cpan |
>   \/home\/tbrowde\/\.emacs
> }

Better written as

my regex dirs {
   | '/home/user/.cpan'
   | '/home/tbowde/.emacs'
}

Yes, quoting does now work in regexes too. Cool, right? :-)

(The leading | is ignored, it just allows you to format the alternation
more consistently)

> for "dirlist.txt".IO.lines -> $line {
>   # ignore certain dirs
>   if $line ~~ m{} {
>  next;
>   }
> }
> 
> My question: Is there a way to have Perl 6 do the required escaping
> for the regex programmatically, i.e., turn this:
> 
> my $str = '/home/usr/.cpan';
> 
> into this:
> 
> my regex dirs {
>   \/home\/usr\/\.cpan
> }
> 
> automatically?

Even better: No need to escape anymore. If you use $str in a regex, and
it actually contains a Str, it is always taken to match literally, so


my $dir1 = '/home/user/.cpan';
my $dir2 = '/home/tbowde/.emacs';
my regex ignore_dirs { $dir1 | $dir2 }

does what you want.

If you want the interpolated string to be treated as a regex, you have
to use it as   my regex dirs { <$dir1> }.

Cheers,
Moritz


Re: [perl #127263] Cannot pass a Method object to .^can

2016-01-14 Thread Moritz Lenz

Hi Dave,

On 01/14/2016 07:47 AM, Dave Rolsky (via RT) wrote:

# New Ticket Created by  Dave Rolsky
# Please include the string:  [perl #127263]
# in the subject line of all future correspondence about this issue.
# https://rt.perl.org/Ticket/Display.html?id=127263 >


If I do a get errors like:

Method object coerced to string (please use .gist or .perl to do that)  in any 
can at gen/moar/m-Metamodel.nqp line 1109
Method object coerced to string (please use .gist or .perl to do that)  in any 
can at gen/moar/m-Metamodel.nqp line 1114
Method object coerced to string (please use .gist or .perl to do that)  in any 
can at gen/moar/m-Metamodel.nqp line 1115
Method object coerced to string (please use .gist or .perl to do that)  in any 
can at gen/moar/m-Metamodel.nqp line 1114
Method object coerced to string (please use .gist or .perl to do that)  in any 
can at gen/moar/m-Metamodel.nqp line 1115
Method object coerced to string (please use .gist or .perl to do that)  in any 
can at gen/moar/m-Metamodel.nqp line 1114
Method object coerced to string (please use .gist or .perl to do that)  in any 
can at gen/moar/m-Metamodel.nqp line 1114

I find it a bit surprising that this doesn't work. I'm not sure if this is 
intentional or not.


The documentation at
https://doc.perl6.org/routine/can calls the parameter $method-name and 
talks about method names, not Method object. Why does it surprise you 
that you when you pass in something that's not a method name, you get 
weird behavior?


Please also read the disclaimers at 
https://doc.perl6.org/language/mop#Power%2C_Convenience_and_Pitfalls


Cheers,
Moritz


Re: Jonathan's "Perl 6 Introductory course"

2015-12-31 Thread Moritz Lenz


On 12/31/2015 04:26 PM, Sitaram Chamarty wrote:
> On 31/12/15 20:43, Tom Browder wrote:
>> Jonathan's intro course, in pdf, here:
>> 
>>   https://github.com/rakudo/star/raw/master/docs/2015-spw-perl6-course.pdf
>> 
>> is excellent, of course.  But I really like the presentation theme and
>> the slide formatting!
>> 
>> Does anyone know what slide-making process he uses?
>> 
>> So far the best I have found that meets my needs is using asciidoc
>> input with Asciidoctor's Deck.js backend. I think I can convert from
>> the generated html to pdf but can't say for sure yet, but it is the
>> good looks of his slides that I'm primarily interested in.
> 
> Looks like Beamer (latex+beamer).

The meta data of the PDF agrees, it says "LaTeX with Beamer class
version 3.10" in the "creator" field.

Cheers,
Moritz


Re: Constants as members of a class

2015-12-18 Thread Moritz Lenz
Hi,

On 12/18/2015 03:46 AM, TS xx wrote:
> Hello dear perl6 users,
> 
> I was in the need of declaring a member variable as a constant integer.

I don't understand this. If it's a constant, why does it need to be
member at all? A member is per-instance storage, which seems to be a
waste for a constant.

Just do

class MyClass {
method TheConstant { 42 }
}

Then you can use it both on the class:

say MyClass.TheConstant

or on an instance:

say MyClass.new.TheConstant


Cheers,
Moritz


Re: Gather/take & return, PHP7-style

2015-12-10 Thread Moritz Lenz

On 12/09/2015 07:35 PM, yary wrote:

This feature builds upon the generator functionality introduced into
PHP 5.5. It enables for a return statement to be used within a
generator to enable for a final expression to be returned (return by
reference is not allowed). This value can be fetched using the new
Generator::getReturn() method, which may only be used once the
generator has finishing yielding values.

getReturn(), PHP_EOL;

The above example will output:

1
2
3

Being able to explicitly return a final value from a generator is a
handy ability to have. This is because it enables for a final value to
be returned by a generator (from perhaps some form of coroutine
computation) that can be specifically handled by the client code
executing the generator. This is far simpler than forcing the client
code to firstly check whether the final value has been yielded, and
then if so, to handle that value specifically.


So this is meant as some sort of "EOF" (or rather EOL) marker, right?

Perl 6 does not do this, because there's already an EOF mechanism, and 
you can use LAST phasers to execute after the final iteration, but still 
inside the scope of the loop that works with the list.


Cheers,
Moritz


Re: signature to preserve @*ARGFILES ?

2015-11-28 Thread Moritz Lenz
Hi,

On 11/28/2015 05:49 PM, Marc Chantreux wrote:
> hello,
> 
> i would like to write a better version of the unix `column` with some
> options like 'preserve separator' so i started to write it down.
> 
> sub padded-cols ($sep,@sheet) {
> my $fmt =
> join $sep,
> @sheet[0].keys.map: 
> -> $col { "\%-{ [max] @sheet[*;$col].map: *.chars }s" };
> @sheet.map: {$fmt.sprintf(|$_)}
> }
> 
> my $sep = @*ARGS.shift;
> .say for padded-cols $sep, $*ARGFILES.lines.map: (*.split($sep)).eager;
> 
> now i would like to add options like -mean -max 1:25 and it would be
> nice to write a MAIN function to delegate borring stuff to perl6. 
> 
> i googled, tried to read the doc and grep in roast but i found no way to
> do it. any idea to help me. so thanks thanks for reading and helping.

Since $*ARGFILES (the thing behind lines() for example) uses @*ARGS to
determine what files to open, you can say


sub MAIN(*@*ARGS, Bool :$mean) { ... }

Cheers,
Moritz


Announce: Rakudo Star Release 2015.11

2015-11-28 Thread Moritz Lenz
On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the November 2015 release of "Rakudo Star", a useful and usable
distribution of Perl 6. The tarball for the November 2015 release is
available from .

This Rakudo Star release comes with support for the MoarVM
backend (all module tests pass on supported platforms).

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 2015.11] of the
[Rakudo Perl 6 compiler], version 2015.11 of [MoarVM], plus various
modules, documentation, and other resources collected from the
Perl 6 community.

[release 2015.11]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.11.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[MoarVM]: http://moarvm.org/

Some of the new compiler features since the ast Rakudo Star release include:

+ There is now an `infix:<.>` operator that does method calls with slightly
  looser precedence than the postfix unary method call.
+ New operator `infix o` for function composition
+ `fc` for Unicode-correct case folding implemented
+ grep now accepts :k, :v, :kv, :p attributes
+ `Supply.throttle` for rate-limiting
+ Array.push is now used for pushing one element (mostly); Array.append
  exists for pushing multiple values. Same for `unshift`/`prepend`
+ Basic arithmetic operations (`+`, `*`, `-`, `/`) on Range objects
  that shift or scale the end points while maintaining exclusions
+ The v notation now allows alphabetic components: v1.2.beta.  (Incompatible
  because method calls on a version must be protected by \ or () now.)
+ `use v6b+;` notation is now recognized and enforced
+ Many built-in methods that return iterables are now much faster
+ Better error messages when comparing version strings with numbers
+ Several error messages that were lacking line numbers now include them
+ Initial shaped array support
+ `\r\n` (Carriage Return/LineFeed) is now a single (synthetic) grapheme
+ Unicode support adheres to Unicode Annex #29
+ Unicode quotes are now also allowed in regular expressions
+ Improved newline support with "use newline" and updates to IO::Handle
+ Added List.head, List.tail, List.repeated methods
+ Str.encode now allows :replacement parameter for unencodable sequences
+ Str.split now accepts multiple strings to split on
+ New Range.int-bounds returns first/last value for integer ranges
+ Auto-generated meta-ops vivified by referring to them, instead of
executing
+ Illegal assignment of different Numeric values now caught at compile time
+ `` implemented, which returns the routine that `nextsame`
would invoke
+ Many speedups

The Rakudo Perl 6 compiler is now officially in beta for the upcoming
production release around Christmas 2015.

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.

Notable changes in modules shipped with Rakudo Star:

* Bailador: Add MIT License
* DBIish: Improved Windows support
* doc: More documentation; generated HTML is better searchable
* Template::Mustache: Switched from LGPL to Artistic License 2.0
* panda: Default action is no longer `install`; better help messages
* Digest::MD5: Now accepts non-ASCII input (internally encodes as Latin-1)
* LWP::Simple: Support for successful return codes besides 200
* Shell::Command: `which` routine for locating executables
* Updated docs/2015-spw-perl6-course.pdf from Nov 21

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)
  * much of Synopsis 9 and 11

There is an online resource at 
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 .

See  for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
Perl 6 tutorial is available as docs/2015-spw-perl6-course.pdf 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
, ask on the 
mailing list, or join us on IRC \#perl6 on freenode.


Re: [perl #126664] .roll on a Range of Num ain't random

2015-11-27 Thread Moritz Lenz

On 11/26/2015 03:36 PM, Wenzel P. P. Peppmeyer wrote:


On Thu, 26 Nov 2015, Elizabeth Mattijsen via RT wrote:


(0.1 .. 0.3).roll(10).say;



What did you expect?  a selection of 0.1, 0.2, 0.3 ??  or 10 random
values between 0.1 and 0.3 inclusive?


I would (naive) expect 10x a value between 0.1 and 0.3 . Analog to:

(0.1, 0.2, 0.3).roll(10).say;
# OUTPUT«(0.3 0.2 0.1 0.2 0.1 0.2 0.3 0.2 0.2 0.1)␤»

However, S03 is quite clear how Range is iterating.

0.1.succ == 1.1;

So incrementing by 0.1 can't work. It may be reasonable to fail as early
as possible for Range.roll on any Range that is neither Int nor Str on
both end points.


I don't think so. What's wrong with (1.1 .. 10.1).roll for example? It 
has well-defined semantics.


People need to read docs occasionally, there's nothing we can do to 
prevent them from abusing the core APIs, except by crippling them -- 
which isn't traditionally perl's approach.



Cheers,
Moritz


Re: confused about 'try'

2015-11-24 Thread Moritz Lenz
Hi,

On 11/24/2015 06:39 AM, brad clawsie wrote:
> Been playing with perl6 and it is truly amazing.
> 
> I'm somewhat confused as to when I should should wrap subroutine
> invocations with `try`. My `CATCH` clauses seem to be able to catch
> thrown Exception instances if I use `try` or not.

That's correct. "try" is merely a convience for catching all exceptions,
and not needed when you have an explicit CATCH block.

> I see in the
> "Exceptional Perl 6" slide deck
> ( http://moritz.faui2k3.org/files/talks/2013-yapc-p6-exceptions/ ),
> there seems to be an indication that `try` should be used when I want to
> access a Backtrace...is there something here I am missing?

The exception object always gives you access to the backtrace. If you
use CATCH, then the exception is in $_ inside the CATCh block. If you
use try, the exception is in $! outside the try block.

Here are two examples that do the same thing:

try { die "oh noez" };
say $!.message; # oh noez
say $!.^name;   # X::AdHoc

do {
die "oh noez";
CATCH {
default {
say .message;   # oh noez
say .^name; # X::AdHoc
}
}
}

Why bother with the more verbose form at all? There are basically two
reasons:
1) you can chose to only catch some exceptions, like
EVAL $some-code;
CATCH {
   when X::Comp {  say "Your code didn't even compile" };
   # let run-time exceptions fall through
}

2) When you want to access some variables from the inner scope that
produced the exception. Since CATCH runs before the stack is unwound,
you can even inspect dynamic variables.

Cheers,
Moritz


Re: combine hashes

2015-11-07 Thread Moritz Lenz
On 11/07/2015 10:17 AM, Marc Chantreux wrote:
> hello Moritz, 
> 
> On Sat, Nov 07, 2015 at 08:17:21AM +0100, Moritz Lenz wrote:
>> my %x = < login jdoe first john last doe >;
>> my %y = flat (:enable, %x< login first >:p);
> 
> i tried :p but the thing is i was searching for something straight as
> the perl5 
> 
> my %y = (%x, qw( enable 1 ));
> 
> si i really loved  
> 
> my %x = < login jdoe first john last doe >;
> my %y = ( :enable, %x< login first >:p);  
> 
> to work. thanks for showing me this working code. 
> 
> actually, it rises a new question to me: why the parenthesis around
> flat are mandatory?
> 
> my %x = < login jdoe first john last doe >;
> my %y = flat (:enable, %x< login first >:p);
> 
> is ok but 
> 
> my %x = < login jdoe first john last doe >;
> my %y = flat :enable, %x< login first >:p;
> 
> give me 
> 
>> first => john, last => doe, login => jdoe
>> Unexpected named parameter 'enable' passed

Because some of the pair literal syntaxes (:enable, :enable(1), enable
=> 1, but for example not "enable" => 1) are also used for named
arguments, and sub flat doesn't want a named argument.

Putting the parens around it force it not be a named argument.

Cheers,
Moritz


Re: combine hashes

2015-11-06 Thread Moritz Lenz
Hi,

On 11/07/2015 02:45 AM, Marc Chantreux wrote:
> hello,
> 
> using perl6 version 2015.09 built on MoarVM version 2015.09,
> i'm trying to create a hash with a slice of another one and some extra 
> pairs. as exemple: 
> 
> my %x = < login jdoe first john last doe >;
> my %y = :enable, |( %x< login first >.kv);
> 
> gives 
> 
> 0 => jdoe, 1 => john, enable => True

That's because %x< login first> returns a List of values:

say %x< login first >.perl; # ("jdoe", "john")

At this point you have lost the keys, and .kv helpfully supplies the
integer indexes of the list as keys.

What you really want is

%x< login first >:p

This works for me:

my %x = < login jdoe first john last doe >;
my %y = flat (:enable, %x< login first >:p);
say %y.perl;# {:enable, :first("john"), :login("jdoe")}

Cheers,
Moritz


Re: Ecosystem problems

2015-11-02 Thread Moritz Lenz
Hi,

On 11/02/2015 05:22 AM, Richard Hainsworth wrote:
> Dear All,
> 
> I'm working on a sort of citation index of Perl6 modules. One general 
> problem:
> 
> There are two modules in the ecosystem, viz. io-prompt and lolsql, that 
> do not have ether META.info or META6.json file.
> 
> This is probably because they are old modules and worked for a 
> predecessor to panda. But they are not now in compliance with the 
> Modules requirements.
> 
> What procedure - if any - has been set in place for getting authors to 
> update modules

In general, one open github issues, since all modules are also gibhut
repos, and msot have issues enabled.

> or for the ecosystem maintainer to remove them?

You open a pull request that removes them from the META.list in
perl6/ecosystem.

Cheers,
Moritz


Re: Missing documentation

2015-10-29 Thread Moritz Lenz
On 10/29/2015 09:14 AM, Steve Mynott wrote:
> I renamed it to 5to6-nutshell.html.

... and I created a redirect from 5to6 to 5to6-nutshell:

https://github.com/perl6/doc/commit/df1b189dec

Cheers,
Moritz


Re: How to call a super class method?

2015-10-28 Thread Moritz Lenz


On 10/28/2015 08:03 AM, Patrick R. Michaud wrote:

On Wed, Oct 28, 2015 at 03:31:09AM +, TS xx wrote:


Can I call the Person's constructor (in non static context),
pass the required parameter and do more things before returning?


There are two answers to this question, both of which likely deserve
a few lines in doc.perl6.org/language/faq.  Lloyd alludes to both
answers in his replies to the original post.

1.  The typical answer to this question is to use "callwith",
"callsame", "nextwith", or "nextsame".

2.  Constructors already have some special support for building
the superclass portions of an object -- see the BUILD submethod
described in Synopsis 12.


Or more to the point, read the documentation on 
http://doc.perl6.org/language/objects#Object_Construction


(The design documents are meant for compiler writers, doc.perl6.org is 
meant for users; this has consequences on the number of examples, 
language, information density etc.)


Cheers,
Moritz


Re: How to profile Perl 6 applications?

2015-10-24 Thread Moritz Lenz
Hi Gabor,

On 10/24/2015 09:26 AM, Gabor Szabo wrote:
> The Devel::NYTProf helped me a lot locating the source of slowness on
> the Perl Maven site.
> Is there something similar for Perl 6 so I can try to improve the speed
> of the Perl 6 Maven site too?

Rakudo has a --profile command line option, which generates a HTML file
containing a single-page JS app that presents the profiling data.

But you should take care to only profile short program executions that
way (a few seconds at most), otherwise the result will be unusable in
the browser.

Cheers,
Moritz


Re: Forking or running external process in background

2015-10-24 Thread Moritz Lenz


On 10/24/2015 10:06 AM, Gabor Szabo wrote:
> I am trying to test the Perl6::Maven web application by launching the
> full application (which is uses Bailador) and then accessing the pages
> using LWP::Simple.
> 
> 
> Unfortunately so far I could not figure out how to launch an external
> program in the background
> or how to fork an exec ?
> 
> I tried QX{"command &") but it waited till the command finished.
> I tried run(), but that insisted I pass each argument as a separate value
> 
> my $p = run("/usr/bin/perl", "-V", :out);

There's a shell() function that might be closer to what you want, if you
don't want to pass each argument separately.

There's also Proc::Async: http://doc.perl6.org/type/Proc::Async

But to me, it also looks like a perfect use case for threads. Have you
tried that?

Cheers,
Moritz


Re: How to profile Perl 6 applications?

2015-10-24 Thread Moritz Lenz
Hi,

On 10/24/2015 09:52 AM, Timo Paulssen wrote:
> On 24/10/15 09:40, Moritz Lenz wrote:
>> Hi Gabor,
>>
>> On 10/24/2015 09:26 AM, Gabor Szabo wrote:
>>> The Devel::NYTProf helped me a lot locating the source of slowness on
>>> the Perl Maven site.
>>> Is there something similar for Perl 6 so I can try to improve the speed
>>> of the Perl 6 Maven site too?
>> Rakudo has a --profile command line option, which generates a HTML file
>> containing a single-page JS app that presents the profiling data.
>>
>> But you should take care to only profile short program executions that
>> way (a few seconds at most), otherwise the result will be unusable in
>> the browser.
>>
>> Cheers,
>> Moritz
> 
> It's a common tip to "only profile short program executions", but that 
> misses the actual point by a few centimeters. The things that makes the 
> profiler super slow are:

The profiler, or the web app generated by the profiler? Curently I
mostly care about the latter.

> 1) having a gigantic amount of different subs and methods that get 
> touched by the program at some point
> 2) having very, very deep call chains
> 3) having the GC run thousands of collections
> 
> if I understand correctly.
>
>
> Recently, Coke++ switched the profiler JS app from a kind of old version 
> of angular.js to a newer version that has had lots of performance 
> improvements done to it by the google devs; i expect that helps 
> tremendously, though i have not actually measured anything beyond a new 
> feeling of "snappyness".

I've tried to profile htmlify.p6 in the perl6/doc repo; it has a
--sparse option to make it process fewer files and thus generate less
profiler output.

With --sparse=200, it takes about 22s to run on hack.p6c.org. I managed
to run it with --profile, but the generated profile still doesn't work
in any browser I tried. See
http://hack.p6c.org/~moritz/profile-1445674278.30788.html for the output.

If anybody manages to get it to render, please send me some screenshot :-)

I don't know if htmlify.p6 has deep call chains; it does some recursion
along the Pod tree, but I'd be surprised if that's more than 20 levels deep.

Cheers,
Moritz


Re: Backwards compatibility and release 1.0

2015-10-15 Thread Moritz Lenz



On 10/15/2015 10:47 AM, Smylers wrote:

Moritz Lenz writes:


On 10/13/2015 10:52 AM, Richard Hainsworth wrote:


Following on the :D not :D thread, something odd stuck out.

On 10/13/2015 03:17 PM, Moritz Lenz wrote:


We have 390+ modules, and hand-waving away all trouble of
maintaining them seems a bit lofty.


Surely, the idea of keeping the release number below 1.0 is to warn
early adopter developers that code is subject to change and thus in
need of maintenance?


... a large percentage of the module updates are done by group of
maybe five to a dozen volunteers. ... 5 people updating 70% of 390
modules. Modules they are usually not all that familiar with, and
usually don't have direct access. So they need to go through the pull
request dance, waiting for reaction from the maintainer. In short, it
sucks.


Thanks for the explanation, Moritz. That does make sense.

I'm still a _little_ uneasy because that sounds a bit like the
explanation of why Makefiles have to use tab characters:

   I just did something simple with the pattern newline-tab. It worked,
   it stayed. And then a few weeks later I had a user population of about
   a dozen, most of them friends, and I didn't want to screw up my
   embedded base. The rest, sadly, is history.

 — Stuart Feldman http://stackoverflow.com/a/1765566/1366011


The problem is, that with this kind of argument one can defer the 
declaration of a "stable" version indefinitely.


May I remind everybody that we want a stable release this Christmas?

Cheers,
Moritz



Re: Backwards compatibility and release 1.0

2015-10-14 Thread Moritz Lenz

On 10/13/2015 10:52 AM, Richard Hainsworth wrote:

Following on the :D not :D thread, something odd stuck out.

On 10/13/2015 03:17 PM, Moritz Lenz wrote:



But hopefully none of them breaking backwards compatibility on such a
large scale. The last few backwards incompatible changes still cause
pain in the ecosystem. We have 390+ modules, and hand-waving away all
trouble of maintaining them seems a bit lofty.



Surely, the idea of keeping the release number below 1.0 is to warn
early adopter developers that code is subject to change and thus in need
of maintenance?


It is. But we still should try to limit the module author's burden.

In Practice, there's a small number of people who try to update modules 
to match when the compiler changed. Most module authors don't hang out 
in #perl6, eager to update their modules to the lastest rakudo change.


So a large percentage of the module updates are done by group of maybe 
five to a dozen volunteers. So, do the math: 5 people updating 70% of 
390 modules. Modules they are usually not all that familiar with, and 
usually don't have direct access. So they need to go through the pull 
request dance, waiting for reaction from the maintainer. In short, it sucks.


The ecosystem hasn't yet fully recovered from the s/done/done-testing/ 
change, nor from the GLR, nor from the need to prefix 'unit' to some 
declarations.


And this is why I'm getting increasingly frustrated and angry when 
people propose major breaking changes, brushing off the implications for 
the ecosystem and its maintainers with "but it's not 6.0", "shouldn't be 
a problem", "we aren't stable yet".


We want to release Perl 6 by Christmas, and it'll reflect *very* badly 
on us and the language if many modules in the ecosystem are broken. And 
any change that requires us to touch all .pm files will result in that.


Richard, I'm sorry that I'm writing the response in an email of yours; 
Mark or any number of p6l participants in the last few years triggered 
the same mental response from me. I only just now articulated it.




Cheers,
Moritz


Re: To :D or not to :D

2015-10-13 Thread Moritz Lenz



On 10/12/2015 09:51 PM, Mark Overmeer wrote:

* Moritz Lenz (mor...@faui2k3.org) [151012 15:32]:

   . are they using :D correctly?


Yes, though not everybody uses :D as much as they do. Do you check that
all the parameters that your Perl 5 methods/subs receive are defined? If
not, you wouldn't use :D in Perl 6 either.


In Perl5, you get slower code when you test for definedness... in Perl6
you get faster (better optimized) code.  That's a big difference.


Do you? Did you actually measure that?


FWIW you can now (as of a few days ago) control the default with
use invocant :D;


How can de invocant not be defined?


Well, if you call a constructor, you call it on the type object. Hence 
the type object is the class, and not defined.



use parameters :D;


The new "use warnings"/"use strict"...


which means all those :D annotations can go away, and you have to use :_
explicitly if you want to allow all.


Oh, use :U for that.  Ehhh already in use.


:U means "undefined", :_ means "defined or undefined, I don't care"


And I don't know if we can change it now without creating a huge havoc
in the existing ecosystem.


There shouldn't be a problem making :D a superfluous option.  Of swiftly
add  "use parameters $_;"  to all modules.


Why shouldn't this be a problem?


 And there still quite a
number of other crucial changes going in anyway...


But hopefully none of them breaking backwards compatibility on such a 
large scale. The last few backwards incompatible changes still cause 
pain in the ecosystem. We have 390+ modules, and hand-waving away all 
trouble of maintaining them seems a bit lofty.



   . :D looks really ugly, don't you think?  Try to explain to students
 to add this smiley everywhere.


It's not uglier than a 'die "Must be defined" unless defined $x'


Much too expensive in Perl5.


Then don't do in Perl 6 either. If you can argue away the need for 
safety based on the need for performance, you can also argue away the 
need for safety based on the need for cleaner code.


Cheers,
Moritz


Re: To :D or not to :D

2015-10-12 Thread Moritz Lenz
Hi,

On 10/12/2015 03:41 PM, Mark Overmeer wrote:
> 
> Hi all,
> 
> Liz and Tux demonstrate powerful Perl6 code at each monthly meeting of
> our Mongers in Amsterdam.  Looking at their examples, I collected a few
> questions of which I want to discuss the first one in this thread.
> 
> 
> When I look at Merijns (Tux') code, I see a huge number of :D attributes.
> https://github.com/Tux/CSV/blob/master/lib/Text/CSV.pm
> 
> Close to all scalar positional parameter (51x) carry the :D flag.  I count
> only 3 where the parameter does accept undef and the method is able to
> handle it.  I count another 3 where the :D is missing, but the method is
> not able the handle it.
> 
> The same for examples Liz shows us in our core code: most scalar
> positional parameters have :D.
> 
> Writing a sub which is able to handle undef is usually more work than
> implementing "I expect sane values for all of the parameters".
> 
> 
> Questions:
>   . are they using :D correctly?

Yes, though not everybody uses :D as much as they do. Do you check that
all the parameters that your Perl 5 methods/subs receive are defined? If
not, you wouldn't use :D in Perl 6 either.

>   . the simpelest code does not handle the undef case... but now needs
> the more complex prototype to be correct.
>   . it feels like the wrong default: usually you have to do something
> extra for the unusual cases, not the 90%+ usual cases.

FWIW you can now (as of a few days ago) control the default with

use invocant :D;

and

use parameters :D;

which means all those :D annotations can go away, and you have to use :_
explicitly if you want to allow all.

That said, I agree that it's the wrong default. And the design documents
even mandate a default to :D, though at the time it was written, it
wasn't clear how to switch off that default, nor how to avoid having to
write

method new(MyClassHere:U: *@args) { ... }

in the constructor, which would be quite hostile to newbies. It's still
not clear to me how to avoid that.

And I don't know if we can change it now without creating a huge havoc
in the existing ecosystem.

Another concern is that if "everything" defaults to :D, then classes
(and other type objects) aren't really first class objects anymore,
which is a really neat thing to have.

>   . :D looks really ugly, don't you think?  Try to explain to students
> to add this smiley everywhere.

It's not uglier than a 'die "Must be defined" unless defined $x'

Cheers,
Moritz


Re: Misunderstanding when usng elems on undefined Array

2015-09-28 Thread Moritz Lenz

Hi,

On 09/25/2015 05:46 PM, mt1957 wrote:

Found the following using Array;

 > my Array $a;
 > say $a.elems;
1
 > $a.push(1)
[1]
 > say $a.perl
[1]
 > say $a.elems
1


 > my Array $a .= new;
[]
 > say $a.elems;
0

Seems that an uninitialized Array reports one element but pushing values
on the array will define the properly. In this case it is important to
initialize.


I know that this can be surprising, but it's actually quite sensible.

If you iterate over the Array type object, you get one iteration:

for Array { .say }

so it makes sense that Array.elems returns 1.

if .push wouldn't autovivify a defined array, thinks like

my %h;
%h.push: $new_value;

couldn't work.

But  the real advise is it use @-sigiled variables when dealing with 
arrays; they don't exhibit such interesting corner cases.


Cheers,
Moritz


Re: [perl #126208] [BUG] Many threads results in data corruption

2015-09-28 Thread Moritz Lenz


On 09/27/2015 11:58 PM, Benjamin Goldberg (via RT) wrote:

# New Ticket Created by  Benjamin Goldberg
# Please include the string:  [perl #126208]
# in the subject line of all future correspondence about this issue.
# https://rt.perl.org/Ticket/Display.html?id=126208 >


The code at https://gist.github.com/BenGoldberg1/bc39a9a31eaeb733012a creates 
many threads for the task of sorting numbers as they are sent to a channel.  
Roughly twice as many threads are created as there are distinct values.

The output should be a list of random numbers, sorted.

Instead, it produces a error message; changing the number of element to be 
sorted causes the error message to change.  This leads me to conclude that the 
problem is memory corruption of some sort.

One of the error messages was:
Attempt to return outside of any Routine␤  in block  at /tmp/4c1CWudfwj:33


I think this error message is correct

#!/usr/bin/env perl6
use v6;

sub sort-promise ($c) {
   start {
  my @same;
  earliest $c {
 more $c { push @same, $c.receive }
 done $c { return }
  }

You try to return from a routine through a start { } boundary -- I don't 
think that's allowed.



Another error message was:
Cannot send a message on a closed channel␤  in block  at 
/tmp/T9gWZ7YfGJ:33


Can be correct as well. I don't think you wait with the .close until all 
the other tasks are done.



Another error message was:
Cannot receive a message on a closed channel␤  in block  at 
/tmp/rPtHPIxsTw:33


Same here.


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

2015-09-26 Thread Moritz Lenz

On 09/26/2015 02:26 PM, Aristotle Pagaltzis wrote:
> 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?” 

Yes, that's what type Slip is for: http://doc.perl6.org/type/Slip

It's useful for returning more than one list item from a .map call, for
example.

Cheers,
Moritz


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

2015-09-26 Thread Moritz Lenz
Hi,

On 09/26/2015 07:58 AM, Gabor Szabo wrote:
> In the first two cases the hash was converted to Pairs before assigning
> to the array.
> Only the third case gave what I hoped for. How can I push a hash onto an
> array as a single entity?
> 
> 
> use v6;
> 
> my %h = x => 6, y => 7;
> say %h.perl; #  {:x(6), :y(7)}
> 
> my @a = %h;
> say @a.elems;   #
> say @a[0]; # x => 6

A trailing comma helps:

my %h = a => 1, b => 2;
my @a = %h, ;
say @a.perl;# [{:a(1), :b(2)},]


> my @c;
> @c.push(%h);
> say @c.elems; # 2
> say @c[0];   # x => 6

I would have expected the traiing comma to help here too:

my @b; @b.push: %h, ;
say @b.perl;# [:a(1), :b(2)]

but alas, not. I wonder if this is a bug.

This works:
my @b; @b.push: $%h;
say @b.perl;# [{:a(1), :b(2)},]

Cheers,
Moritz


Re: require on string stopped working in rakudo 2015.09

2015-09-26 Thread Moritz Lenz
Hi,

On 09/26/2015 06:47 AM, Gabor Szabo wrote:
> Hi,
> 
> 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 stumbled across the same thing in DBIish, and was told that the proper
way to require a module name (and not a file name) is

require ::($name);

which does work in 2015.09.

I guess there's no deprecation, because it was only an accident that the
string form worked before.

Cheers,
Moritz


Re: require on string stopped working in rakudo 2015.09

2015-09-26 Thread Moritz Lenz

On 09/26/2015 01:07 PM, Elizabeth Mattijsen wrote:
>> 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  :-)

I've opened https://rt.perl.org/Ticket/Display.html?id=126096 and later
rejcted it when learning about the desired behavior.

Cheers,
Moritz


Re: Method 'send' not found for invocant of class 'IO::Socket::INET'

2015-09-26 Thread Moritz Lenz
Hi,

method .send was deprecated in favor of .print (for strings) and .write
(with bufs/blobs)

Maybe Bailador or one of its dependencies needs updating.

Cheers,
Moritz


Announce: Rakudo Star Release 2015.09

2015-09-26 Thread Moritz Lenz
On behalf of the Rakudo and Perl 6 development teams, I'm excited to
announce the September 2015 release of "Rakudo Star", a useful and
usable distribution of Perl 6. The tarball for the September 2015
release is available from .

This Rakudo Star release comes with support for the MoarVM backend (all
module tests pass on supported platforms).
Please note that this release of Rakudo Star is not fully functional
with the JVM backend from the Rakudo compiler. Support should be
restored shortly.

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 2015.09] of the [Rakudo Perl 6
compiler], version 2015.09 of [MoarVM], plus various modules,
documentation, and other resources collected from the Perl 6 community.

[release 2015.09]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.09.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[MoarVM]: http://moarvm.org/

Some of the new compiler features added to this release include:

* Great List Refactor (GLR) - See http://design.perl6.org/S07.html
* All Deprecations removed in preparation for Christmas release
* Added support for calling into C++ libraries and calling methods on
C++ classes
* New slurpy parameter, +args or +@args, to allow for one-argument style
binding
* New with/orwith/without conditionals allow you to check for .defined
but topicalize to the actual value returned
* New `supply`, `whenever` and `react` blocks for easy reactive programming
* All Unicode digits can now be part of literal numbers
* `val()` and allomorphic types implemented
* Most European quoting styles are now supported
* New $[...] and ${...} constructs allow prefix itemization
* The .gist and .perl methods can now deal with self-referential structures


Notable changes in modules shipped with Rakudo Star:

* All modules fixed to work with GLR where needed
* Panda now includes JSON::Fast and no longer precompiles to byte code
* Terminal::ANSIColor replaces the deprecated Term::ANSIColor
* New Perl 6 tutorial replaces original perl6 book draft

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)
  * much of Synopsis 9 and 11

There is an online resource at 
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 .

See  for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
Perl 6 tutorial is available as docs/2015-spw-perl6-course.pdf 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
, ask on the 
mailing list, or join us on IRC \#perl6 on freenode.


Re: [perl #126113] [BUG] Cannot bind to &::("CORE")::foo

2015-09-20 Thread Moritz Lenz
On 09/20/2015 09:55 AM, Tobias Leich (via RT) wrote:
> # New Ticket Created by  Tobias Leich 
> # Please include the string:  [perl #126113]
> # in the subject line of all future correspondence about this issue. 
> # https://rt.perl.org/Ticket/Display.html?id=126113 >
> 
> 
> t/spec/S02-names/pseudo.t expects that you can do:
> 
> use Test; plan 1;
> sub f3() { }
> &::("CORE")::none := 
> ok  =:= , 'works';

I'm pretty sure that test is incorrect.

Lexical scopes are read-only after compile time, and &::CORE is a
lexical scope, after all.


Re: What are Perl 6's killer advantages over Perl 5?

2015-08-26 Thread Moritz Lenz

Hi,

On 11.08.2015 14:12, Tom Browder wrote:

I have seen several lists of new Perl 6 features (versus Perl 5) but
they all seem to be lists that intermix features with varying degrees of
value to ordinary Perl 5 users.  If one wants to sell long-time Perl 5
users (already using the latest Perl 5, Moose, etc.) on the value of
Perl 6, what should be on the important feature list?


on a more meta level: Perl 6 has the ability to evolve, and lots of 
things that Perl 5 most likely will never have.


Just as an example: when I started to get involved with Perl around 2003 
or '04 or so, people seemed to be aware that subroutine signatures were 
a good thing to have. They probably were aware of that much longer. And 
yet it took until perl 5.20 in 2014 to get even the most basic 
subroutine signatures (and still marked as experimental).


Another one is the inability to reliably introspect strings for whether 
they are text or binary data, which means enormous care must be taken to 
not accidentally mix the two. Again, known for ages that it's a problem, 
afaict no practical solution in sight.


These are just two examples of things that people take for granted in a 
modern programming language, yet Perl 5 has real trouble with.


I could continue with other Perl 5 deficiencies (no strict by default, 
lack of easy threading, too many globals, obscure regex syntax), but the 
individual problems aren't the point. My main point is that large parts 
of Perl 5 are still stuck in the past, with no good way forward.


Cheers,
Moritz


Re: [perl #125745] Custom infix:~~ multi not used by rakudo

2015-08-04 Thread Moritz Lenz

Hi,

On 04.08.2015 00:52, Faye (via RT) wrote:

# New Ticket Created by  Faye
# Please include the string:  [perl #125745]
# in the subject line of all future correspondence about this issue.
# URL: https://rt.perl.org/Ticket/Display.html?id=125745 


ShimmerFairy m: class Foo { }; multi sub infix:~~(Foo $a, Foo $b) { 42.6 }; say 
Foo.new ~~ Foo; say infix:~~(Foo.new, Foo)
camelia rakudo-moar a38b59: OUTPUT«True␤42.6␤»
ShimmerFairy (basically, the Perl 6 grammar treats ~~ specially, so stuff 
like this and the chaining bug pop up)


I'd argue that it's permissible to not consider custom infix:~~, 
because we already provide an avenue for customizing smart-match 
behavior (method ACCEPTS of the RHS type).


Also note that the standard infix:~~ cannot be a normal operator, 
because it topicalizes the RHS.


So, not a bug.

(But I cannot reject it in rt.perl.org right now because of login 
problems; I hope I'll be able to do so later).


Cheers,
Moritz


Re: Is creating and Array or Parcel ?

2015-08-02 Thread Moritz Lenz

Hi,

On 02.08.2015 06:43, Gabor Szabo wrote:



On Fri, Jul 31, 2015 at 4:16 PM, Moritz Lenz mor...@faui2k3.org
mailto:mor...@faui2k3.org wrote:



On 07/31/2015 03:02 PM, Gabor Szabo wrote:

The following code (with comments) is confusing me.
Can someone give some explanation please?
Specifically the difference between

my @x = a b;


It's the assignment to the Array variable that makes the Array here;
  by itself just creates a Parcel:

$ ./perl6-m -e 'say a b.^name'
Parcel
$ ./perl6-m -e 'say (my @ = a b ).^name'
Array

# we can assign that array to a scalar variable and it is still
and array
my $y = @x;


that's because assignment to $ isn't coercive in the same way as
assignment to @ or %.

It just wraps things into a Scalar, which is normally invisible.

But, you can observe the difference still

my @a = a b;
my $s = @a'

for @a { } # two iterations
for $s { } # one iteration


Thanks though this just shows I still don't get the whole sigil and
Array thing in Perl 6.
I thought you can put an array in a $ -ish variable and that will still
be a real array, but
now I see it is not an array.


It's an Array inside a Scalar.

If you want to extract it from the scalar, use the @ again, this time as 
a prefix:


for @$s { } # two iterations again.

Cheers,
Moritz


Re: Is creating and Array or Parcel ?

2015-07-31 Thread Moritz Lenz



On 07/31/2015 03:02 PM, Gabor Szabo wrote:

The following code (with comments) is confusing me.
Can someone give some explanation please?
Specifically the difference between

my @x = a b;


It's the assignment to the Array variable that makes the Array here;   
by itself just creates a Parcel:


$ ./perl6-m -e 'say a b.^name'
Parcel
$ ./perl6-m -e 'say (my @ = a b ).^name'
Array


# we can assign that array to a scalar variable and it is still and array
my $y = @x;


that's because assignment to $ isn't coercive in the same way as 
assignment to @ or %.


It just wraps things into a Scalar, which is normally invisible.

But, you can observe the difference still

my @a = a b;
my $s = @a'

for @a { } # two iterations
for $s { } # one iteration

Cheers,
Moritz


Announce: Rakudo Star Release 2015.07

2015-07-27 Thread Moritz Lenz

A useful, usable, early adopter distribution of Perl 6

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the July 2015 release of Rakudo Star, a useful and usable
distribution of Perl 6. The tarball for the July 2015 release is
available from http://rakudo.org/downloads/star/.

This Rakudo Star release comes with support for the MoarVM
backend (all module tests pass on supported platforms).

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 2015.07.2] of the
[Rakudo Perl 6 compiler], version 2015.07 of [MoarVM], plus various
modules, documentation, and other resources collected from the
Perl 6 community.

[release 2015.07.2]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.07.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[MoarVM]: http://moarvm.org/

Some of the new compiler features added to this release include:

* Cool.substr(-rw) and substr(-rw) now also accept a Range
* Added trait is required on class attributes
* ?ROUTINE and ?BLOCK
* words implemented (to completement .words)
* Numeric comparison ops (==  etc) for DateTimes
* samewith() now also works in subs
* Calling the .clone method with alternate values no longer changes original
* .grep and grep now consume multiple elements for many-param blocks
* ENTER phaser now can be used as an r-value

Notable changes in modules shipped with Rakudo Star:

* Bailador: Add links to documentation
* DBIish: Use Postgres environment variables for test configuration
* doc: More documentation, mostly for IO-related classes and methods

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)
  * much 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 http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf 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.


Re: perl6/book fonts: why Adobe commercial fonts?

2015-07-23 Thread Moritz Lenz

Hi,

On 07/23/2015 01:03 AM, Tom Browder wrote:

Is there any reason to use Adobe commercial fonts for the book?  As I
read the instructions to copy fonts from Adobe Reader, I worry that
that is prohibited by the license from Adobe.  Building the book
without the fonts results in an ugly book in some parts.  (There are
plenty of free and handsome fonts to be had.)

Some other questions:

1.  Are there plans for a table of contents?

2.  Are there plans for page numbering?


No and no. perl6/book is a dead project, only good for salvaging pieces 
of it for perl6/doc.


Cheers,
Moritz


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

2015-07-03 Thread Moritz Lenz


On 07/03/2015 10:02 PM, yary wrote:
 On Fri, Jul 3, 2015 at 3:03 PM, Timo Paulssen t...@wakelift.de wrote:
 but this does not

 sub takes_int_array(Int @bar) { say @bar }
 takes_int_array([1, 2, 3])

 because the type match is against the defined type. We do not
 automatically infer that [1, 2, 3] could be a Positional[Int].
 
 How would one call takes_int_array with a literal [1,2,3]?  Can we
 declare it to be a Positional[Int] or create an object of that type
 in-line?

take_int_array( my Int @ = 1, 2, 3 );

rant

Perl 6 types are, by default (and with some exceptions), not coercive.
If you declare a function to take an Int, and you try to call it with a
Str that happens to represent an integer, you still get a type error.

But one of the exceptions mentioned above is that assignment to an array
(or hash) variable is coercive in nature. 'my @a = 1, 2, 3;' works, even
though the RHS isn't an Array.

So when people write `sub sum(Numeric @a)`, they typically expect
coercive semantics from the parameter, because it's an array, right?
Instead they get the non-coercive rigor of a normal type constraint.

Which is why I tend to tell people not to use typed arrays -- they are
clumsy to use (by the standards that Perl 6 sets, at least), because
they seem to lack the magic of untpyed arrays.

Though seem is the key here: on assignment, they are just as magical
as normal arrays: 'my Int @a = 1, 2, 3' works as you would expect. It's
binding in a signature that surprises and frustrates people.

When we say 'sub take_int_array( Int @a )', we don't want an Int-typed
Array; we any array, and have the runtime validate for us that each
element is an Int. This interpretation (which is explicitly not what the
design docs state right now, nor what rakudo implements) would also make
sense with slurpies (Int *@a) and/or coercion types (Int() *@a).

Unfortunately, I have no idea how that could be realized, since binding
to a parameter binds the caller's object unchanged, pretty much by
definition.

/rant

yours ranting,
Moritz


Re: Sub args: choose one of two?

2015-06-28 Thread Moritz Lenz
Hi,

On 06/28/2015 12:39 AM, Tom Browder wrote:
 I'm trying to take advantage of the MAIN suroutine to handle most all of
 my routine command line arg handling.  One idiom I use a lot is for the
 user to choose only one of two args, but one must be chosen.

So since it's not optional, you might consider not making it an option
(prefixed with --), but rather a simple command:


$ cat door
#!/usr/bin/env perl6

multi MAIN('open') {
say Opening door;
}
multi MAIN('close') {
say Closing door;
}
$ ./door
Usage:
  ./door open
  ./door close
$ ./door open
Opening door

Cheers,
Moritz


Re: Problem documentation and/or compiler

2015-06-18 Thread Moritz Lenz

Hi Marcel,

On 06/18/2015 11:17 AM, mt1957 wrote:

Sorry I've been too fast, It's in the doc. However, why can't I assign
it to a Buf with automatic coercion from utf8 to Buf which is more generic?


The docs are wrong; it should be Blob, not Buf.

I've fixed it in
https://github.com/perl6/doc/commit/ec673618159fc85249c105d76f4157bf76880759

The right place to report errors to the docs is 
https://github.com/perl6/doc/issues/


Cheers,
Moritz


Re: New Logo Design for perl6 modules

2015-06-11 Thread Moritz Lenz

Hi,

On 06/10/2015 02:01 PM, Lin Yo-an wrote:

Hi folks!

I designed a logo for CPAN, and I think it can be used for perl6
modules, don't know if you're interested in it?
https://twitter.com/c9s/status/608549774648692736


Great, I like it!

Is there a high-res version available? What's the license?

Any chance we can get a p5/p6 twin theme (like, one with a butterfly, in 
addition to the one with the camel)?
It would be awesome to have cpan.org or metacpan.org and 
modules.perl6.org with clearly related but distinct art work.


One word of caution: the use of the camel in relation to Perl is a 
trademark by O'Reilly.


Cheers,
Moritz


Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME

2015-05-30 Thread Moritz Lenz
Hi,

On 05/30/2015 04:36 PM, Paul Cochrane wrote:
 Thanks for pointing out the $*PROGRAM omission!  I've just added it to the
 list of special variables and it should be available online within the next
 10-15 minutes.

Minor nit pick: according to the last log on
http://doc.perl6.org/build-log/ building the docs alone takes ~17min;
the cron job runs every 5 minutes, so it's more likely 17-22min before
it becomes available :-)

And thanks for adding $*PROGRAM to the docs!

Cheers,
Moritz


Re: [perl #125211] Error Function X::Panda needs parens to avoid gobbling block when running panda on JVM, but not on Moar

2015-05-18 Thread Moritz Lenz



On 05/18/2015 04:07 AM, Rob Hoelz (via RT) wrote:

# New Ticket Created by  Rob Hoelz
# Please include the string:  [perl #125211]
# in the subject line of all future correspondence about this issue.
# URL: https://rt.perl.org/Ticket/Display.html?id=125211 


The full error message:

===SORRY!===
Function X::Panda needs parens to avoid gobbling block
at bin/panda:21
-- Panda { %failed{$x}.push($_)  say $_ }⏏ };
Missing block (apparently taken by 'X::Panda')
at bin/panda:21
-- anda { %failed{$x}.push($_)  say $_ } ⏏};


Could you please supply a self-contained sample code that triggers this 
error?


Thanks!




Re: Can a user cheat and call a class's private method?

2015-05-12 Thread Moritz Lenz
Hi,

On 05/12/2015 09:40 PM, R. Ransbottom wrote:
 On Mon, May 11, 2015 at 03:22:46PM -0700, Darren Duncan wrote:
 
 you can use trusts.  Also having to do this may indicate bad code
 design. -- Darren Duncan
 
 I saw Moritz' and Carl's responses and I agree with the smell
 issue.  
 
 Given that the code exists and needs testing,

I'm curious, what's a case where private state of a class needs to be
tested, and tests agains the public interface are not enough?

In my experience, testing against private parts only makes the tests
more brittle (that is, every implementation change causes test failures,
even if the public interface is unchanged).

Also, are you talking about an actual Perl 6 code base that needs
testing, but that is too large for a refactoring? If yes, I'd be curious
where such a beast exists.

 Is class finalization implemented?

I don't think so.

Cheers,
Moritz


Re: [perl #125153] Pod nesting needs some clarity

2015-05-11 Thread Moritz Lenz



On 05/11/2015 02:47 PM, (via RT) wrote:

# New Ticket Created by
# Please include the string:  [perl #125153]
# in the subject line of all future correspondence about this issue.
# URL: https://rt.perl.org/Ticket/Display.html?id=125153 


It's not clear which =begin is not terminated here, based on the error.
Maybe '=begin at line 1 not terminated by matching '=end pod' would be a
clearer error statement.


I think the clearest error message would be

Expected =end Documentation to terminate =begin Documentation; found 
=end pod instead.





--cut here--
=begin pod

=begin Documentation

=end pod
--cut here--

===SORRY!=== Error while compiling /home/jgoff/bug.pm
'=begin' not terminated by matching '=end Documentation'
at /home/jgoff/bug.pm:5
-- BOL⏏=end pod
  expecting any of:
  horizontal whitespace
  whitespace

--cut here--
=begin pod

=begin Documentation

=end Documentation
--cut here--
===SORRY!=== Error while compiling /home/jgoff/bug.pm
'=begin' not terminated by matching '=end pod'
at /home/jgoff/bug.pm:6
-- BOL⏏EOL
  expecting any of:
  horizontal whitespace
  whitespace



Re: class/object variables

2015-04-23 Thread Moritz Lenz



On 04/21/2015 10:37 PM, mt1957 wrote:

L.s.

The following piece of code shows that one must be careful using my or
state variables in a class. They have the same behavior as an our
variable if I am right.


The difference is that 'our'-variables can be accessed from the outside 
($A::p), 'my' and 'state'-varaibles can't.


The difference between 'my' and 'state' is that 'state' retains its 
state (sic) between several executions of the block, but since a class 
block is only executed once (while it's compiled), the distinction is 
moot here.



Are they all kind of global to the class/object?
---
class A {

   my $a;
   has $.a;
   our $p;
   state $q;

   method set ($b) {
 $a = $b;
 $!a = $b+10;
 $p = $b+20;
 $q = $b+30;
   }

   method get {
 $!a //= 'undefined';
 return my=$a, has=$!a, our=$p, state=$q;
   }
}

my $x = A.new;
$x.set(2);# Set variables in x object
say X: , $x.get;

my $y = A.new;
say Y: , $y.get;  # Only attribute undefined
$y.set(4);# Set variables in y object
say X: , $x.get; # Modified in $x except for the attribute
---


The results are;

X: my=2, has=12, our=22, state=32
Y: my=2, has=undefined, our=22, state=32
X: my=4, has=12, our=24, state=34

Only the attribute is kept local to the object but all other variables
are shared between $x and $y.

Should one use only attributes in a class and use our variables to share
between objects?


If you want per-object local storage, use attributes, yes.

Cheers,
Moritz


Re: Fancy sub arg handling: ability to expand error message?

2015-03-28 Thread Moritz Lenz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

On 28.03.2015 12:27, Tom Browder wrote:
 I like the subroutine arg handling in Perl 6.  Is there any simple 
 way to attach a short error msg in place of or additive to the 
 default for, say, a missing arg?

You can always use multi subs, and use a catch-all candidate which
produces the error message.

multi thingy($x) { $x + 42 }
multi thingy(|c) { die Must call thingy with exactly one argument }

Though IMHO that's usually not worth the trouble; you get the error
message only for programming errors, not for user errors; and
programmers should be able to understand the error message (or we need
to improve the error messages, if that's not the case).

Also it makes it harder for others to extend your API by providing
additional multi candidates.

Cheers,
Moritz
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iEYEARECAAYFAlUWsnQACgkQT81LMIj/VkTbAwCfTsQumtjPKj1lxXZlnQ+U+0Xz
uTQAn287aU2xU7m6iMFGWD+j2R+Bouy6
=LWsI
-END PGP SIGNATURE-


Re: Example module and its use

2015-03-28 Thread Moritz Lenz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


On 28.03.2015 11:05, Tom Browder wrote:
 On Sat, Mar 28, 2015 at 5:01 AM, Tom Browder
 tom.brow...@gmail.com wrote:
 On Fri, Mar 27, 2015 at 8:27 PM, Nathan Brown
 nbrow...@gmail.com wrote:
 
 Okay, this works:
 
 use Bar :DEFAULT;
 
 but this does not:
 
 use Bar foo;
 
 So is S11 in error!!

It is, but not for the reasons you think.

The examples in S11 are wrong, because 'sub common' must be imported
as 'use Sense common;'.

We can get away with leaving out the sigil on subroutine calls,
because the parens of the subroutine call disambiguate subs from
constants, types and other sigilless terms, but I'm pretty sure we
can't get away with this imprecision.

And if I remember correctly, that error in S11 confused me enough not
to implement 'use Module list' correctly when I last meddled with
these things.

Cheers,
Moritz
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iEYEARECAAYFAlUWsPkACgkQT81LMIj/VkQm1wCdFvFkU/PQfEqlKqx/AQC4C3ql
yFEAnRkc81DvlWd5veoehXAHw8m0iMnQ
=AsJT
-END PGP SIGNATURE-


Re: Can a user cheat and call a class's private method?

2015-03-26 Thread Moritz Lenz
Hi,

On 26.03.2015 16:55, Tom Browder wrote:
 I need to test some private routines, so is there a way to do that?

The easiest way to do that is when the class with the private methods
trusts the class that calls them. See for example
http://doc.perl6.org/type/Metamodel::Trusting
http://design.perl6.org/S12.html#Trusts
https://github.com/perl6/roast/blob/master/S12-attributes/trusts.t

But you should ask yourself if you really, really want this.

And then you can also do something like:

my $private_method = $obj.^private_method_table{$methodname};
$obj.$private_metnod(arguments here)

but it is rather questionable use of the MOP.

Cheers,
Moritz


Re: How to get indirect access to a class attribute?

2015-03-25 Thread Moritz Lenz
Hi,

On 25.03.2015 13:44, Tom Browder wrote:
 Given a class like:
 
 our %attrs = (age=1,wgt=2);
 class foo { has $.age = rw;}

should be 'has $.age is rw'. The is indicates a trait (not an
assignment).

 method a {
   for %attrs.kv - $k, $v {
  my $aval = self.$k();  # supposed to work for a method name


Etiher method a needs to be inside class foo, or it needs to be a
subroutine, and refer to foo instead of self here.

A method outside a class doesn't ususally make sense, which is why you
get this message:

Other potential difficulties:
Useless declaration of a has-scoped method in mainline (did you mean
'my method a'?)

  say attr { $k } has value '{ $aval }';
   }
 }
 
 Question:
 
 1. How can I indirectly refer to the attributes in a method?  The
 above doesn't work (with or without the '()').

the indirect method call syntax is the right approach, you just got too
many other details wrong to make it work.

Cheers,
Moritz


Re: rakudo Test module: expanding tests considered?

2015-03-24 Thread Moritz Lenz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



On 24.03.2015 13:51, Nicholas Clark wrote:
 On Tue, Mar 24, 2015 at 09:44:19AM +0100, Moritz Lenz wrote:
 
 I'd suggest developing those test functions in a separate module,
 and after gathering some experience with it, when can discuss
 putting them into rakudo's Test.pm.
 
 Seems a good plan (for these functions)
 
 However, does Rakudo's lib/Test.pm scale in the way that Perl
 5's Test::* do?
 
 By which I mean, all the (sane) Perl 5 test modules use
 Test::Builder, which means that the test counting, plan
 manipulation (etc) is coherent and co-ordinated, even if you're
 using Test::More, Test::Deep, etc.
 
 
 It doesn't look to me like there's a way to do that (yet) in the
 Perl 6 ecosystem. Am I missing a way to mix in new test functions
 without having to replace/redo the existing ones?

We don't have such a fine API as Test::Builder, but you still can call
Test.pm's ok() from within your own test modules.

Cheers,
Moritz
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iEYEARECAAYFAlURXrEACgkQT81LMIj/VkQGaQCeLCP2pM0HTlkPTuxkgeeJQsu0
tNEAnjW3PR9mbWTiVhJS+tpc4ueVPXZ1
=QLjU
-END PGP SIGNATURE-


Re: rakudo Test module: expanding tests considered?

2015-03-24 Thread Moritz Lenz
Hi,

On 24.03.2015 00:15, Tom Browder wrote:
 On Mon, Mar 23, 2015 at 5:53 PM, Elizabeth Mattijsen l...@dijkmat.nl wrote:
 On 23 Mar 2015, at 23:50, Tom Browder tom.brow...@gmail.com wrote:
 Question:  Would it be better to submit pull requests for some (or
 all) for the rakudo Test module or start creating a new Test::*
 module?
 Good question.
 What functionality are you currently missing in Test.pm ??
 
 From CPAN Test::Number::Delta:
 
 # Equality test with default tolerance
 delta_ok( 1e-5, 2e-5, 'values within 1e-6');
 
 # Provide specific tolerance
 delta_within( 1e-3, 2e-3, 1e-4, 'values within 1e-4');
 
 # Compare arrays or matrices
 @a = ( 3.14, 1.41 );
 @b = ( 3.15, 1.41 );
 delta_ok( \@a, \@b, 'compare @a and @b' );
 
 # Set a different default tolerance
 use Test::Number::Delta within = 1e-5;
 delta_ok( 1.1e-5, 2e-5, 'values within 1e-5'); # ok
 
 # Set a relative tolerance
 use Test::Number::Delta relative = 1e-3;
 delta_ok( 1.01, 1.0099, 'values within 1.01e-3');
 
 Note that the functions can be used for scalars or suitable arrays
 (and they each have a 'not' version for convenience).
 
 So far I've used the core's 'is_approx' for the 'delta_ok' emulation,
 but 'is_approx' doesn't allow the user to specify tolerances as
 'delta_ok' does.  The ability to specify tolerances would be useful
 for the core 'is_approx' function.

I'd suggest developing those test functions in a separate module, and
after gathering some experience with it, when can discuss putting them
into rakudo's Test.pm.

Cheers,
Moritz


Re: Object Introspection for Existence of Methods: How?

2015-03-23 Thread Moritz Lenz

Hi,

On 03/23/2015 01:48 AM, Henk van Oers wrote:


On Sun, 22 Mar 2015, Tom Browder wrote:

On Sun, Mar 22, 2015 at 7:13 PM, Henk van Oers h...@signature.nl wrote:

On Sun, 22 Mar 2015, Tom Browder wrote:

I'm trying to write a test.

To test what? Your own typo's?


The tests are for a public Perl 6 module translated from an existing
Perl 5 module.

Do Perl 6 modules not need tests?


Yes they need tests.


If so, which ones do they need?


The public interface.


I agree with this part (test the public interface), but if you really 
want/need to, you *can* introspect the private methods too. See 
http://doc.perl6.org/type/Metamodel::PrivateMethodContainer#method_private_method_table


Note that private methods aren't inherited, so getting the private 
methods from one level in the class hierarchy (the one that you want to 
call the private method of) is enough.


That said, I wonder why tests need introspection at all. I mean, you 
test by doing example calls and comparing to expected example return values.


(If those are generated methods, IMHO there is no point in testing all 
generated instances).


Cheers,
Moritz


Announce: Rakudo Star Release 2015.03

2015-03-21 Thread Moritz Lenz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

## A useful, usable, early adopter distribution of Perl 6

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the March 2015 release of Rakudo Star, a useful and usable
distribution of Perl 6. The tarball for the March 2015 release is
available from http://rakudo.org/downloads/star/.

This Rakudo Star release comes with support for the MoarVM
backend (all module tests pass on supported platforms) along with
experimental support for the JVM backend (the modules `Bailador`,
`Digest::MD5` and `Grammar::Profiler::Simple` are known to fail tests).

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 2015.03] of the
[Rakudo Perl 6 compiler], version 2015.03 of [MoarVM], plus various
modules, documentation, and other resources collected from the
Perl 6 community.

[release 2015.03]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.03.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[MoarVM]: http://moarvm.org/

Some of the new compiler features added to this release include:

+ several renames of semi-internal methods. Please refer to [the Rakudo
  2015.02 release
notes](https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.03.md)
for the full list
+ Allow `Buf.AT-POS` to return an l-value.
+ Implement `method ^foo($) { ... }` syntax.
+ Implemented [PairMap](http://doc.perl6.org/type/PairMap) (the simple
case only, for now).
+ Implemented `.antipairs` (pairs with value = key).
+ Implemented [pairup](http://doc.perl6.org/type/Any#method_pairup)
for creating pairs from lists.
+ Implemented `LEXICAL`, `OUTERS` and `CALLERS` pseudo-packages
+ Add `array[T]`, usable for native `int`/`num` (MoarVM only for now)
+ Other native improvements, e.g. `my int $a; $a++`
+ Implement `IO::Path.resolve` on r-m/POSIX

In future, the `nqp::` namespace willl only be available after a
declaration
like `use nqp;`.

Changes to modules included in Rakudo Star:

- - [DBIish](https://github.com/perl6/DBIish) supports local Sockets on
mysql,
  and now correctly handles returned NULL values in the Pg backend
- - [doc](https://github.com/perl6/doc) ships with much more documentation

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
  * threads and concurrency (in progress)
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O (in progress)
  * much 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 http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf 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.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iEYEARECAAYFAlUN3iYACgkQT81LMIj/VkTYSACfeumxLQzxeRPfNHIYge6ZHEwU
L9sAn0rfiVwi5CB0RSFJ125UKvv5P7OG
=+CBE
-END PGP SIGNATURE-


Re: Need help with: Cannot find method 'postcircumfix:( )'...

2015-03-20 Thread Moritz Lenz



On 03/20/2015 11:00 AM, Timo Paulssen wrote:

On 03/20/2015 03:40 AM, Brandon Allbery wrote:


On Thu, Mar 19, 2015 at 10:33 PM, Tom Browder tom.brow...@gmail.com
mailto:tom.brow...@gmail.com wrote:

Why do you say that is not a method?  The first line says


Sorry, somehow I managed to misread that.

So you want what I have already said twice: the accessor `self.elem`.
If you want to access the variable directly for some reason, you use
the form `$.elem`. (By the way, that shadowing is generally bad form,
and not just in Perl 6. It makes code confusing to read)


Actually, $.elem is just short for $(self.elem); if you want direct
access to the variable you'd write $!elem. Also, an indirect method
call would be self.$elem,


small correction: self.$elem().
self.$elem is an error, which is useful to catch p5 programmers who 
use . for string concatenation.


Cheers,
Moritz


Re: Can a class have an attribute and a method with the same name?

2015-03-19 Thread Moritz Lenz

Hi,

On 03/19/2015 12:40 AM, Tom Browder wrote:

I have a class with an attribute and a method with the same name and
it looks so far like they clash.


Attributes are always private. If you write 'has $.x', that generates 
not only the attribute, but also an accessor method of name 'x'. See 
also http://doc.perl6.org/language/objects#Attributes


So, you can have an attribute $!x and a method x, but if you write

class A {
has $.x;
method x() {... }
}

then the method will prevent the automatic accessor from being generated.


Cheers,
Moritz


Re: [perl #124108] [BUG] reduce meta-operator fails with 'max' on list larger than 2**15 with MoarVM

2015-03-19 Thread Moritz Lenz



On 03/19/2015 10:14 AM, Nicholas Clark wrote:

On Wed, Mar 18, 2015 at 05:13:54AM -0700, David Hoekman wrote:

Thanks for the concise and interesting bug report.
There might be a whole bunch more things that break in a similar way...


perl6-m -e 'say [max] 1..(1+2**15)'

arg flag is empty in slurpy positional
   in sub infix:max at src/gen/m-CORE.setting:2181
   in sub  at src/gen/m-CORE.setting:20740
   in block unit at -e:1


$ ./perl6-m -Ilib -e 'say [max] 1..(1+2**15)'
ASAN:SIGSEGV
=
==1476==ERROR: AddressSanitizer: SEGV on unknown address 0x0004 (pc 
0x7fa75096588a sp 0x7fffda54e0e0 bp 0x7fffda54e210 T0)
 #0 0x7fa750965889 in flatten_args src/core/args.c:711
 #1 0x7fa75095aff7 in MVM_args_checkarity src/core/args.c:140
 #2 0x7fa750979e30 in MVM_interp_run src/core/interp.c:573
 #3 0x7fa750bf4f8b in MVM_vm_run_file src/moar.c:210
 #4 0x4019bf in main src/main.c:189
 #5 0x7fa750267d5c in __libc_start_main (/lib64/libc.so.6+0x1ed5c)
 #6 0x400fc8 (/home/nicholas/Sandpit/moar-san/bin/moar+0x400fc8)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV src/core/args.c:711 flatten_args
==1476==ABORTING

and a non-ASAN build under valgrind reports

==17316==
==17316== Invalid write of size 8
==17316==at 0x4F4D91B: flatten_args (args.c:711)
==17316==by 0x4F4A427: MVM_args_checkarity (args.c:140)
==17316==by 0x4F54721: MVM_interp_run (interp.c:573)
==17316==by 0x5039D5C: MVM_vm_run_file (moar.c:210)
==17316==by 0x401250: main (main.c:189)
==17316==  Address 0x4 is not stack'd, malloc'd or (recently) free'd
==17316==
==17316==
==17316== Process terminating with default action of signal 11 (SIGSEGV)
==17316==  Access not within mapped region at address 0x4
==17316==at 0x4F4D91B: flatten_args (args.c:711)
==17316==by 0x4F4A427: MVM_args_checkarity (args.c:140)
==17316==by 0x4F54721: MVM_interp_run (interp.c:573)
==17316==by 0x5039D5C: MVM_vm_run_file (moar.c:210)
==17316==by 0x401250: main (main.c:189)


Is this something to do with P6Int having alternative storage representations?


sounds more like the number of arguments is a signed 16 bit int 
somewhere, and overflows for calls with = 2**15 arguments (which a long 
list flattened into an argument list can cause).


Cheers,
Moritz


Re: Passing arrays to subroutines

2015-03-19 Thread Moritz Lenz



On 03/19/2015 04:05 PM, Tom Browder wrote:

In Perl 5 I can do this:

my @a = (1, 2);
my @b = (3);

foo(@a,@b);

sub foo { my $n = @_;  die Wrong num args: $n if ($n != 3);}

In Perl 6 I think this is correct (or nearly so):

sub foo(*@args) { die Wrong num args: { @args.elems } if @args.elems != 3;}

Questions for Perl 6:

foo is now defined as:

sub foo($a, $b, $c) { # do something with $a, $b, $c }

but I want to call it with a flattened array arg.

1.  How can I combine arrays @a and @b into one array?


generally with the comma operator:

my @combined = @a, @b;


2.  Can I flatten the arrays into elements inside the foo call?


foo(|@combined)

Cheers,
Moritz


Re: Object Contruction

2015-03-18 Thread Moritz Lenz

Hi

On 03/18/2015 01:06 PM, Tom Browder wrote:

My new object needs some methods run during construction.  How can I
do that without defining my own new method?


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.


Cheers,
Moritz


Re: Perl 6 Debugging

2015-03-15 Thread Moritz Lenz
On 15.03.2015 00:05, Tom Browder wrote:
 On Sat, Mar 14, 2015 at 5:25 PM, Elizabeth Mattijsen l...@dijkmat.nl wrote:
 On 14 Mar 2015, at 23:19, Tom Browder tom.brow...@gmail.com wrote:
 ...
 Could you post the code of test_ellipsoid.pl for others to see (e.g. on
 gist.github.com)?  That would help in tracing the problem (which is causing
 you to not be informed of where the code has gone wrong).
 
 I'm happy to, but I'm a little embarrassed for you to see how little
 progress I've made since I've been working one statement or so at a
 time expecting a detailed error traceback.  Nevertheless, it's here:
 
   https://gist.github.com/08e881d7f1c7a7072dc9.git

Without the .git it works in the browser:
https://gist.github.com/tbrowder/08e881d7f1c7a7072dc9

 I don't expect anything more than:
 
 1. The offending statement.

When I run your code with perl6-m (Rakudo with the MoarVM backend), I get

===SORRY!=== Error while compiling /home/moritz/Ellipsoid.pm6
Variable '$class' is not declared
at /home/moritz/Ellipsoid.pm6:154
--   my( $class⏏, %args ) = @_;
expecting any of:
postfix

Which is because my() (with parens immediately after the 'my') is being
interpreted as a subroutine call, not a declarator.

Somehow, this still very much looks like Perl 5 code to me :-)

 2. A pointer to perl 6 debugging.

* use the MoarVM backend :-)
* For runtime errors, https://github.com/jnthn/rakudo-debugger/ can help
you.

Cheers,
Moritz


  1   2   3   4   5   6   7   8   9   10   >