Re: Observations from a C++/Python developer that never used Perl5

2016-09-08 Thread Aaron Sherman
>
> it is combining too many new things at once:


Well, it is meant to be the up-front example of everything at once before
the step-by-step...


> * BUILD
> * new


These are the heart of construction. I don't think there's any avoiding
that in a class tutorial.

* submethod
> * bless


These are simply necessary components of the above. BUILD is a submethod.
new uses bless. These are non-negotiable aspects of the tutorial.

* named arguments syntax
> * slurping parameter syntax


Named arguments are pretty standard stuff. Slurpy args... I suppose it's
one more thing, but is it really that unusual that we expect someone
reading this not to understand variadic arguments?


> * code golfing cleverness of mapping arguments to identically named named
> arguments


Again, this is how you take arguments to BUILD that set attributes. That's
the correct form, not code golfing.

Constructors in a language that supports a flexible metaobject protocol
aren't trivial beasts.


The real nail in the coffin though is that it's an example that doesn't
> need to use any of those features (nothing about Task really require
> special construction),
>

This is, I think, the only really significant problem with that example.
The BUILD method is doing no work, and doesn't need to. An example where
new and BUILD were actually required would be vastly more useful.


> * If I have a member that is read-only, when am I allowed to initialize it
> and after what point must already be initialized? Can I assign to it in
> BUILD but not new or vice versa?
>

You always get a free initializer, so if the user is going to provide it or
it's going to get a static default, you're good to go. But let's say you
have this:

class Foo {
  has $.a;
  has $.b;
  submethod BUILD(:$!a) { $!b = $!a * 10 }
}

In this case, you need the BUILD submethod because you wanted to have a
dynamic value for the .b attribute that is based on whatever the .a
attribute was set to.

Now, that out of the way, let's make $.b readonly:

  has $.b is readonly;

This doesn't make $.b constant, it merely affects the automatically
generated constructors. So your BUILD routine keeps working. The private
form ($!b) only works within the class, but is not affected by such
strictures.

* If I want a constructor that takes positional arguments, do I write new
> or BUILD?
>

For positionals, you have to define a new. Here's another example that does
unecessary work, but in this case to show you what's going on:

$ perl6 foo.p6
new(1, 2) pre-bless
BUILD(1, 2)
12
$ cat foo.p6
class Foo {
has $.a;
has $.b is readonly;
multi method new($a, $b) {
say "new($a, $b) pre-bless";
self.bless(:$a, :$b);
}
submethod BUILD(:$!a, :$!b) {
say "BUILD($!a, $!b)";
}
}

my $f = Foo.new(1,2);
say $f.a, $f.b;




>
> * If I need to do some computation when the object is constructed in order
> to properly initialize the members, do I write new or BUILD? What if one of
> the members I need to initialize is read-only?
>

All best suited to BUILD.


> * Can either new or BUILD be a multimethod?
>

Both, sort of. BUILD is a submethod, not a method. It's a sub that looks
like a method. But both can be multi.



> Functions (including operators since they are just functions with a
> different calling syntax after all) normally just operate on their
> arguments without knowing anything about the context with the function was
> called.
>

This is never a valid assumption in Perl. Perl is all about context. That's
why we have so many operators for enforcing a context (e.g. the prefix ops
?, +, !, so, ~)


> But the pair constructor operator **reaches back magically into the place
> where it was called and changes the argument it was given into a string**
>

Not really. It's a quoting operator and a binary operator rolled into one.
As such, it's no more strange that it has this "contextual" behavior than
the more traditional quoting operators. You don't balk at the fact that the
doublequotes "reach back" and change the way their parameter is parsed, do
you? In Perl 6, it's just more explicit that quoting operators are actually
operators and can be treated as such.


Re: Observations from a C++/Python developer that never used Perl5

2016-09-08 Thread Joseph Garvin
On Thu, Sep 8, 2016 at 12:25 AM, Kaare Rasmussen  wrote:

> I wonder what you miss from https://docs.perl6.org/language/classtut. To
> me, it explains the hows and whys very thoroughly. Now, I now people have
> been hard at work improving the documentation, so if you can point to
> what's missing or unclear, I'm sure it will help a lot.


I forgot I looked at this before. The Task example doesn't really help a
newcomer because it is combining too many new things at once:

* BUILD
* submethod
* new
* bless
* named arguments syntax
* slurping parameter syntax
* code golfing cleverness of mapping arguments to identically named named
arguments

The real nail in the coffin though is that it's an example that doesn't
need to use any of those features (nothing about Task really require
special construction), so a quick read just makes it look like it's a very
verbose syntax for doing something you normally get for free, rather than
showing how it allows you to do things that you otherwise wouldn't be able
to do.

The rust developers talk about having a "strangeness budget", because if
you introduce too many strange things at once people give up. Every
object-oriented language I've used has one constructor-like method that you
define. That Perl6 has two is really strange and unusual (at least coming
from the background of somebody who has "only" been exposed to
C++/Java/Python/Lisp/Haskell). Strange and unusual enough that it seems
like there should be an example that specifically focuses on what you get
out of having two, and when you should be using one versus the other. And
frankly I'm not sure if it's actually two, because bless is also apparently
a method (that may be you can override as well?!), even though it is
supposed to be what you call to construct the object that hasn't yet been
constructed... see why this might be confusing? It would be especially
great if it contrasted with another language where you could demonstrate
that it's awkward to do something without the feature.

Here are some fairly simple things that I was left wondering how to do:

* If I have a member that is read-only, when am I allowed to initialize it
and after what point must already be initialized? Can I assign to it in
BUILD but not new or vice versa?

* If I want a constructor that takes positional arguments, do I write new
or BUILD?

* If I need to do some computation when the object is constructed in order
to properly initialize the members, do I write new or BUILD? What if one of
the members I need to initialize is read-only?

* Can either new or BUILD be a multimethod? Overloading constructors is
fairly common in C++ at least.

>> The pair operator is explained here https://docs.perl6.org/languag
e/operators#index-entry-pair_constructor and word quoting here
https://docs.perl6.org/language/quoting#Word_quoting:_qw - perhaps they're
more Perl 5-like, but both are very handy features. Perhaps you can expand
a little as to what you'd like explained. Coming from Perl 5, I'm certainly
damaged in that respect.

Functions (including operators since they are just functions with a
different calling syntax after all) normally just operate on their
arguments without knowing anything about the context with the function was
called. But the pair constructor operator **reaches back magically into the
place where it was called and changes the argument it was given into a
string** (because otherwise it would be an undeclared variable name).
That's the kind of thing that in most languages you either can't do or you
can only do by defining a macro. I've never seen anything like it. And
going with the strangeness theme none of the tutorials seemed to be the
least bit fazed by it, while I think somebody coming from a background
without Perl will be bewildered by it.


[perl #129228] [SEGV] concurrent network access segfaults in libmoar.so

2016-09-08 Thread via RT
# New Ticket Created by  Robert Lemmen 
# Please include the string:  [perl #129228]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=129228 >


this simple program:

---8<---

use v6;

use HTTP::Client;

my $n = 4;

my @promises;
for 1..$n {
push @promises, start {
my $i = 0;
# when increasing n above, the total runtime changes as expected
#for 1..(5/$n) {
#say $*THREAD.id;
#sleep 1;
#}
# funkyly, it increases dramatically from n=1 to n=2 , and then
# stays there for n=3 and n=4
my $client = HTTP::Client.new;
for 1..100 {
say sprintf("%2i %2i", $*THREAD.id,  $i++) ~ ' ' ~ now;
for 1..(100/$n) {
   my $response = $client.get('http://localhost:80/');
   }
}
}
}
await Promise.allof(@promises)
--->8---

segfaults for me every now and then if n>=2. core dumps show:

Program terminated with signal SIGABRT, Aborted.
#0  0x7fa0e1435067 in __GI_raise (sig=sig@entry=6) at 
../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x7fa0e1435067 in __GI_raise (sig=sig@entry=6) at 
../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x7fa0e1436448 in __GI_abort () at abort.c:89
#2  0x7fa0e14731b4 in __libc_message (do_abort=do_abort@entry=1, 
fmt=fmt@entry=0x7fa0e1568530 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/posix/libc_fatal.c:175
#3  0x7fa0e147898e in malloc_printerr (action=1, str=0x7fa0e1568718 "double 
free or corruption (fasttop)", ptr=)
at malloc.c:4996
#4  0x7fa0e1479696 in _int_free (av=, p=, 
have_lock=0) at malloc.c:3840
#5  0x7fa0e190eb42 in MVM_interp_run (tc=0x5e09, tc@entry=0x43b72e0, 
initial_invoke=0x0, invoke_data=0x6, invoke_data@entry=0x43dfde0)
at src/core/interp.c:1601
#6  0x7fa0e19238de in start_thread (data=0x43dfde0) at src/core/threads.c:77
#7  0x7fa0e19ea267 in uv.thread_start () from 
//home/rlemmen/perl6env/rakudobrew/moar-nom/nqp/MoarVM/../../install/lib/libmoar.so
#8  0x7fa0e0eea0a4 in start_thread (arg=0x7fa0ddd36700) at 
pthread_create.c:309
#9  0x7fa0e14e887d in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:111

(perhaps)interestingly this program also hangs for a second or so every now and 
then

please let me know how I can help debug this!

regards  robert


Re: Justification for the "reversed" instruction format

2016-09-08 Thread Trey Harris
On Thu, Sep 8, 2016 at 9:23 AM Aaron Sherman a...@ajs.com
 wrote:

I don't know Haskell, but isn't flip just:
>
> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>
> And then:
>
> perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  = flip
>  yas(1,2,3)'
> 213
>
> Yes—but my worry about that was that it wouldn’t carry over signature
constraints and coercions as a specific argument-flipper sub written with
the same signature (flipped). Haskell does deep type inference, unlike Perl
6, so simply writing flip f x y = f y x is sufficient to get exactly the
same behavior in constrained or coercive contexts.


> Aaron Sherman, M.:
> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
> Toolsmith, developer, gamer and life-long student.
>
>
> On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery 
> wrote:
>
>> On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com> wrote:
>>
>>> There is a "flip" in P6, to reverse the characters in a string, and a
>>> "reverse", to return the elements of a list. Would either of those be
>>> an equivalent?
>>>
>>
>> Not without an "apply" mechanism used for function / method / operator
>> invocations. Which is almost viable in Perl 6 since the parameters get
>> passed as a list --- except that the list is only visible within the
>> implementation, not at the call site (which is what "apply" does).
>>
>> --
>> brandon s allbery kf8nh   sine nomine
>> associates
>> allber...@gmail.com
>> ballb...@sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>
> ​


Re: Justification for the "reversed" instruction format

2016-09-08 Thread Trey Harris
Ah, nice, good to know my concern was unwarranted.

On Thu, Sep 8, 2016 at 3:04 PM Aaron Sherman  wrote:

> In Perl 6, we apply those constraints when you pass off the call to the
> ultimate recipient, and that's important because that recipient can have
> multiple signatures (and signatures can be added *after* you define the
> flip).
>
> For example:
>
> $ cat foo.p6
>
>
> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>
> multi sub counter(Int $start, Int $end, :$by=1) {
> $start, *+$by ... $end
> }
> multi sub counter(Str $start, Str $end, :$by=1) {
> ($start.ord, *+$by ... $end.ord).map: {.chr}
> }
>
> my  = flip 
>
> say flip-counter  10,   2, :by(2);
> say flip-counter 'q', 'k', :by(2);
> say flip-counter 3.7,   1, :by(2);
>
> $ perl6 foo.p6
> (2 4 6 8 10)
> (k m o q)
> Cannot resolve caller counter(Int, Rat, Int); none of these signatures
> match:
> (Int $start, Int $end, :$by = 1)
> (Str $start, Str $end, :$by = 1)
>   in block  at foo.p6 line 3
>
>
>
>
>
> Aaron Sherman, M.:
> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
> Toolsmith, developer, gamer and life-long student.
>
>
> On Thu, Sep 8, 2016 at 2:41 PM, Trey Harris  wrote:
>
>> On Thu, Sep 8, 2016 at 9:23 AM Aaron Sherman a...@ajs.com
>>  wrote:
>>
>> I don't know Haskell, but isn't flip just:
>>>
>>> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>>>
>>> And then:
>>>
>>> perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  =
>>> flip  yas(1,2,3)'
>>> 213
>>>
>>> Yes—but my worry about that was that it wouldn’t carry over signature
>> constraints and coercions as a specific argument-flipper sub written with
>> the same signature (flipped). Haskell does deep type inference, unlike Perl
>> 6, so simply writing flip f x y = f y x is sufficient to get exactly the
>> same behavior in constrained or coercive contexts.
>>
>>
>>> Aaron Sherman, M.:
>>> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
>>> Toolsmith, developer, gamer and life-long student.
>>>
>>>
>>> On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery 
>>> wrote:
>>>
 On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com>
 wrote:

> There is a "flip" in P6, to reverse the characters in a string, and a
> "reverse", to return the elements of a list. Would either of those be
> an equivalent?
>

 Not without an "apply" mechanism used for function / method / operator
 invocations. Which is almost viable in Perl 6 since the parameters get
 passed as a list --- except that the list is only visible within the
 implementation, not at the call site (which is what "apply" does).

 --
 brandon s allbery kf8nh   sine nomine
 associates
 allber...@gmail.com
 ballb...@sinenomine.net
 unix, openafs, kerberos, infrastructure, xmonad
 http://sinenomine.net

>>>
>>> ​
>>
>
>


[perl #128123] [JVM] failing test in S03-metaops/hyper.t after change from postfix:<++> to prefix:<++>

2016-09-08 Thread Christian Bartolomaeus via RT
And now a lot of tests from roast exploded with "Expected a native int argument 
for '$a'" after this commit introduced two uses of postfix:<++> and 
postfix:<--> in lib/Test.pm6: 
https://github.com/rakudo/rakudo/commit/ffb5789f7eef1157c7556897c4805569df4f7aa4

Modifying the two relevant lines seems to fix those failures (did not run full 
spectest yet):

diff --git a/lib/Test.pm6 b/lib/Test.pm6
index 45bb86f..5d052e9 100644
--- a/lib/Test.pm6
+++ b/lib/Test.pm6
@@ -339,9 +339,9 @@ multi sub subtest(, $desc = '') is export {
 _push_vars();
 _init_vars();
 $indents ~= "";
-$subtest_level++;
+$subtest_level += 1;
 subtests();
-$subtest_level--;
+$subtest_level -= 1;
 done-testing() if nqp::iseq_i($done_testing_has_been_run,0);
 my $status =
   $num_of_tests_failed == 0 && $num_of_tests_planned == $num_of_tests_run;


[perl #129234] [CONC] `.hyper` and `.race` resume after exceptions

2016-09-08 Thread via RT
# New Ticket Created by  Sam S. 
# Please include the string:  [perl #129234]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=129234 >


If you `die` inside a `map/for` that is being `hyper/race`d...

for (1..1).hyper { die };  sleep 1;  say "Alive";

...it prints the exception's backtrace, but then resumes the program as if 
nothing had happened:

Died
  in block  at -e line 1

Alive



Re: Justification for the "reversed" instruction format

2016-09-08 Thread Aaron Sherman
In Perl 6, we apply those constraints when you pass off the call to the
ultimate recipient, and that's important because that recipient can have
multiple signatures (and signatures can be added *after* you define the
flip).

For example:

$ cat foo.p6

sub flip() { -> $b, $a, |c { f($a, $b, |c) } }

multi sub counter(Int $start, Int $end, :$by=1) {
$start, *+$by ... $end
}
multi sub counter(Str $start, Str $end, :$by=1) {
($start.ord, *+$by ... $end.ord).map: {.chr}
}

my  = flip 

say flip-counter  10,   2, :by(2);
say flip-counter 'q', 'k', :by(2);
say flip-counter 3.7,   1, :by(2);

$ perl6 foo.p6
(2 4 6 8 10)
(k m o q)
Cannot resolve caller counter(Int, Rat, Int); none of these signatures
match:
(Int $start, Int $end, :$by = 1)
(Str $start, Str $end, :$by = 1)
  in block  at foo.p6 line 3





Aaron Sherman, M.:
P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
Toolsmith, developer, gamer and life-long student.


On Thu, Sep 8, 2016 at 2:41 PM, Trey Harris  wrote:

> On Thu, Sep 8, 2016 at 9:23 AM Aaron Sherman a...@ajs.com
>  wrote:
>
> I don't know Haskell, but isn't flip just:
>>
>> sub flip() { -> $b, $a, |c { f($a, $b, |c) } }
>>
>> And then:
>>
>> perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  =
>> flip  yas(1,2,3)'
>> 213
>>
>> Yes—but my worry about that was that it wouldn’t carry over signature
> constraints and coercions as a specific argument-flipper sub written with
> the same signature (flipped). Haskell does deep type inference, unlike Perl
> 6, so simply writing flip f x y = f y x is sufficient to get exactly the
> same behavior in constrained or coercive contexts.
>
>
>> Aaron Sherman, M.:
>> P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
>> Toolsmith, developer, gamer and life-long student.
>>
>>
>> On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery 
>> wrote:
>>
>>> On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com>
>>> wrote:
>>>
 There is a "flip" in P6, to reverse the characters in a string, and a
 "reverse", to return the elements of a list. Would either of those be
 an equivalent?

>>>
>>> Not without an "apply" mechanism used for function / method / operator
>>> invocations. Which is almost viable in Perl 6 since the parameters get
>>> passed as a list --- except that the list is only visible within the
>>> implementation, not at the call site (which is what "apply" does).
>>>
>>> --
>>> brandon s allbery kf8nh   sine nomine
>>> associates
>>> allber...@gmail.com
>>> ballb...@sinenomine.net
>>> unix, openafs, kerberos, infrastructure, xmonad
>>> http://sinenomine.net
>>>
>>
>> ​
>


[perl #129228] [SEGV] concurrent network access segfaults in libmoar.so

2016-09-08 Thread Zoffix Znet via RT
I'm unable to reproduce this on HEAD Rakudo even with $n set to 40 and 
RAKUDO_MAX_THREADS set to 50.

What is your perl6 version (perl6 -v). Are you able to try this against HEAD 
[^1]? Yesterday a fix went in addressing issues in sockets and threads; and 
recently there have been many other async fixes.


[1] Steps to build:
cd $(mktemp -d) &&
git clone https://github.com/rakudo/rakudo/ . &&
perl Configure.pl --gen-moar --gen-nqp --backends=moar &&
make &&
make install;
./perl6-m your-script.p6



[perl #128862] [CONC] IO::Socket::Async server throws uncatchable exception in case of encoding errors

2016-09-08 Thread jn...@jnthn.net via RT
On Sat Aug 06 11:25:38 2016, sml...@gmail.com wrote:
> Golfed program to demonstrate the problem:
> 
> my $server = IO::Socket::Async.listen('localhost', );
> $server.tap: -> $conn {
> $conn.Supply.tap: -> $message { say $message.perl }
> }
> 
> my $client = IO::Socket::Async.connect('localhost', ).then: {
> .result.write(Blob.new: 144);
> }
> 
> await $client, $server;
> 
> It prints the following, and exits:
> 
> Unhandled exception: Malformed UTF-8
> 
> In practice, having a server than can be crashed at will by any (even
> not-authenticated) client is of course LTA.
> It seem the only way to prevent this, is to use .Supply(:bin) to work
> with Buf's, which is needlessly cumbersome for text-based protocols.
> 
> I tried to catch the exception in the following ways, to prevent it
> from exiting the program, but none had an effect:
> 
> 1) CATCH or try/CATCH in a bunch of different places
> 2) Assigning to $*SCHEDULER.uncaught_handler
> 3) Specifying a :quit handler for both .tap's

Fixed, and test added in S32-io/IO-Socket-Async.t for this and a couple of 
other related cases. (Under the hood, the whole way we handle decoding strings 
with async sockets has been given a good overhaul.)

The typical way to handle such errors would be your option 3 (or, if using the 
supply/whenever syntax, a QUIT phaser). It should now also, as a last gasp, be 
passed to option 2.

/jnthn



The use of $!attr vs self.attr in core libraries

2016-09-08 Thread Aaron Sherman
In working with Range a while back, I was frustrated to find that writing a
subclass that wanted to override an accessor (e.g. for $.min and $.max) was
quite difficult because most methods ignored the accessors and called $!min
and $!max or wrote to them directly. If I really wanted to change the
semantics, I pretty much had to re-write or at least wrap every existing
method, which would make my module nigh unmaintainable.

Is this for performance reasons? Would it make sense to try to find a way
to make this easier?

As a concrete example, here's how "elems" is defined on Range:

https://github.com/rakudo/rakudo/blob/32902f25ca753860067a34eb9741aa5524dbe64e/src/core/Range.pm#L96


--
Aaron Sherman, M.:
P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
Toolsmith, developer, gamer and life-long student.


Re: Justification for the "reversed" instruction format

2016-09-08 Thread Aaron Sherman
I don't know Haskell, but isn't flip just:

sub flip() { -> $b, $a, |c { f($a, $b, |c) } }

And then:

perl6 -e 'sub flip() { -> $a, $b, |c { f($b, $a, |c) } }; my  = flip
 yas(1,2,3)'
213


Aaron Sherman, M.:
P: 617-440-4332 Google Talk, Email and Google Plus: a...@ajs.com
Toolsmith, developer, gamer and life-long student.


On Wed, Sep 7, 2016 at 6:13 PM, Brandon Allbery  wrote:

> On Wed, Sep 7, 2016 at 6:08 PM, Parrot Raiser <1parr...@gmail.com> wrote:
>
>> There is a "flip" in P6, to reverse the characters in a string, and a
>> "reverse", to return the elements of a list. Would either of those be
>> an equivalent?
>>
>
> Not without an "apply" mechanism used for function / method / operator
> invocations. Which is almost viable in Perl 6 since the parameters get
> passed as a list --- except that the list is only visible within the
> implementation, not at the call site (which is what "apply" does).
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: Observations from a C++/Python developer that never used Perl5

2016-09-08 Thread Will Coleda
> As I recall it, macros where left out of the initial implementation. So you 
> have to wait for another Christmas Present :-)

The version of macros that was available in Rakudo when the 6.c spec
was cut was released with the compiler; It's marked experimental and
is therefore subject to change, but they are in there.

On Thu, Sep 8, 2016 at 1:25 AM, Kaare Rasmussen  wrote:
> Hi Joseph
>
> Welcome, and I hope you'll stick around.
>
> Now, I haven't had the time to dig into Perl 6 myself, only to poke at it
> from time to time. But, while waiting for people who know something to
> respond, I'll ask you to be a little concise in certain areas.
>>
>> * I can find no concise easy-to-understand explanation for how to define
>> what other languages would call constructors. Instead there is a mess of
>> bless, magic inside Mu, new, BUILD, BUILDALL... It's not clear when you
>> should prefer to override BUILD or new or both. I also assume there are some
>> benefits to teasing apart object construction this way, but right now I
>> don't know what they are. This is also an area where I think there are older
>> blog posts confusing the situation because they discuss semantics from an
>> older version of Perl6.
>
>
> I wonder what you miss from https://docs.perl6.org/language/classtut. To me,
> it explains the hows and whys very thoroughly. Now, I now people have been
> hard at work improving the documentation, so if you can point to what's
> missing or unclear, I'm sure it will help a lot.
>>
>>
>> * It would be nice for people coming from Python for a tutorial that
>> explained the basic module importing, the scope of things imported, and how
>> name collisions are avoided when importing from two modules that have the
>> same sub. The official documentation is trying to distinguish a bunch of
>> subtle and presumably useful for advanced users distinctions that are
>> completely lost on a newcomer. I just want to know what is the equivalent of
>> import, from foo import bar, and import foo as bar.
>
>
> It sounds like "arh, do it yourself", but I'd like to say that, coming from
> a Python background, you'd be the perfect person to do just that. At least
> take notes and post them, so it can go into a tutorial of some kind.
>
>> * Coming from almost any other language the => operator is dark magic
>> because of its implicit quoting of the left hand side. Likewise the implicit
>> quoting done by . Some explanation of why this is done, and how you
>> could write a sub or operator that does the same thing would probably go a
>> long way towards making it less confusing.
>
>
> The pair operator is explained here
> https://docs.perl6.org/language/operators#index-entry-pair_constructor and
> word quoting here https://docs.perl6.org/language/quoting#Word_quoting:_qw -
> perhaps they're more Perl 5-like, but both are very handy features. Perhaps
> you can expand a little as to what you'd like explained. Coming from Perl 5,
> I'm certainly damaged in that respect.
>
>> * I haven't been able to find any guidance on when I should be using a
>> role and when I should be using a class. The former seem to give you better
>> error messages when you forget to define a method from a base role... So
>> never use classes? I suspect it's more complicated than that.
>
>
> I guess this is something everybody can have an opinion about. There are a
> number of reasons to go one or the other way. Isn't it a topic for all
> modern languages?
>
>> * Types feel like second-class citizens. Without knowing the details of
>> the implementation it feels like the errors that Perl can statically detect
>> is chosen at random. It's generally useful
>
>
> I think your wording is misleading. The things that Perl 6 can detect when
> compiling shouldn't be a matter of choice, but of what's possible. Perhaps
> you can give some examples, I'm sure there are perfectly good reasons for
> the way things are. If not, it may be a bug, and the compiler can be
> improved.
>
>> argument constructors, are all pretty sweet as well. Macros look pretty
>> promising although again I had trouble finding good tutorials.
>
>
> As I recall it, macros where left out of the initial implementation. So you
> have to wait for another Christmas Present :-)
>
> /kaare
>



-- 
Will "Coke" Coleda


Re: Observations from a C++/Python developer that never used Perl5

2016-09-08 Thread yary
On Thu, Sep 8, 2016 at 6:41 AM, Kamil Kułaga  wrote:

> In perl6 default way is to not write new, BUILD or BUILDALL and also
> not to write accessors. When you create object you can provide
> attributes to initialize, default accessors are generated if field is
> declared with $. sigil.
>

Right, there's a default "new" method that takes care of attribute
initialization, and calling any ancestor class initializers.

To have your initializer pre-process the attributes before building the
object, or call other code on creation- declare a "submethod BUILD" - that
will get the arguments that "new" had and let you modify them, run code as
needed. Effectively it's intercepting the object creation process just
before the object is initialized.

That took me a long time to figure out when I was trying some Perl6 around
2013, and I didn't really get it until reading through the perl5 Moose
cookbook- and Moose is different enough from Perl6 that, while it helped me
get the big picture of Perl6 objects, it also took me a little more time to
unlearn some big details to get back into Perl6 (like how there is no
BUILDARGS). This paragraph is for anyone who is working on the docs- Perl6
could use an object tutorial and cookbook like Moose's!
https://docs.perl6.org/language/objects is actually pretty good, it just
wasn't around when I started- and Moose does have a lot of docs built up
from answering these kinds of questions.

 As for "new", I re-read https://docs.perl6.org/language/objects and see "if
you want a constructor that accepts positional arguments, you must write
your own new method: [example] ... However this is considered poor
practice, because it makes correct initialization of objects from
subclasses harder."

-y


[perl #128545] [LTA] [UNI] Date.new(Str) poor error message for digit with diacritic

2016-09-08 Thread Zoffix Znet via RT
Thanks for the report.

Fixed in https://github.com/rakudo/rakudo/commit/a2b6f74be1
Tests added in https://github.com/perl6/roast/commit/3ed2af4c42


[perl #129221] [BUG][UNI] Combinators get matched by regex even when no ignoremark is set

2016-09-08 Thread Zoffix Znet via RT
Not a bug.

See also http://irclog.perlgeek.de/perl6-dev/2016-09-08#i_13170729


[perl #129227] [SEGV] Concatenation of a large number of combining characters

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



 m:  7 ~ "\x[308]" x 100_000
 rakudo-moar 7925d6: OUTPUT«WARNINGS for :␤Useless use of "~" in 
expression "7 ~ \"\\x[308]\" x" in sink context (line 1)␤»
 m:  7 ~ "\x[308]" x 150_000
 rakudo-moar 7925d6: OUTPUT«(signal SEGV)»


Re: Observations from a C++/Python developer that never used Perl5

2016-09-08 Thread Kamil Kułaga
On Thu, Sep 8, 2016 at 4:00 AM, Joseph Garvin  wrote:
> * I can find no concise easy-to-understand explanation for how to define
> what other languages would call constructors. Instead there is a mess of
> bless, magic inside Mu, new, BUILD, BUILDALL... It's not clear when you
> should prefer to override BUILD or new or both. I also assume there are some
> benefits to teasing apart object construction this way, but right now I
> don't know what they are. This is also an area where I think there are older
> blog posts confusing the situation because they discuss semantics from an
> older version of Perl6.

In perl6 default way is to not write new, BUILD or BUILDALL and also
not to write accessors. When you create object you can provide
attributes to initialize, default accessors are generated if field is
declared with $. sigil. OOp was designed to not write the same code
everytime. When I started using perl6 the doc didn't told me it but
IMHO the best way to learn is read others code.

> I haven't been able to find any guidance on when I should be using a role and 
> when I should be using a class. The former seem to give you better error 
> messages when you forget to define a method from a base role... So never use 
> classes? I suspect it's more complicated than that.

Roles are similar to mixins. You can add something to class without
all complications of multi inheritance. IMHO *is* and *does* keywords
in most cases explain best whether you want class or role.  I
generally use classes for data and roles for code because I like  to
separate data form implementation. I hurt a lot of times while was
trying to do java programming with perl6 then I realized roles are not
interfaces and code is not compiled in static language sense.

-- 
Regards

Kamil Kułaga