Re: Observations from a C++/Python developer that never used Perl5
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
Observations from a C++/Python developer that never used Perl5
For the last couple weeks I've been experimenting with Perl6 because I finally became sufficiently annoyed with Python's lack of real (No GIL) threading and a quick inspection of the Perl6 feature list looked promising. I'm trying to keep an open mind because Perl is pretty culturally different than the languages that I'm used to working with (C++ may give optimized code but it is not trying to be -Ofun) so although I've run into a few stumbling blocks I mean for the points below to just be observations -- I don't have a feel yet for whether or not some of these things are hard for me because I'm not used to them or because they are problem in the language design. Maybe you all can set me straight. I've read both the "Perl 6 Introduction" and the "Learn Perl 6 in Y minutes" (and a smattering of the advent calendar and the official documentation). They are both well-written and super useful but they don't cover some things that a new Perl6 programmer will run into immediately and where the official documentation is almost completely opaque to an outsider: * Sigils are initially explained in a way that makes them look like a shorthand way to indicate whether or not you have an array or hash or a scalar. But since you can store an array or hash in a $ variable, and because you can put a sigil before the sigil, e.g. @$foo it's not immediately obvious what to prefer and when. Examples using other container types to illustrate that the built-in array and hash types are not special would be useful to make this more clear. The temptation is for me to always use $ and if it turns out I need to loop over something use @$x or %$x. I'm not sure why you wouldn't just want that to be the way to do it in general in the language. Also an explanation of how you implement your own container to be @ or % compatible. * 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. * 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. * 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. * 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. Then there were some more issues that took longer to come up: * 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 to have an intuition about what kinds of errors are detectable at compile time versus runtime so that you can prefer the former when designing an API to make it harder for users to hang themselves. There are also instances where it's not clear whether or not something is part of the type system -- I had an undefined method in a role that subclasses/roles were meant to override and I had a derived role that defined it but used different sigils, and a different explicit type on one of the arguments, and Perl6 gave me no errors. Finally if I want to implement my own container I haven't been able to find any documentation explaining how to parameterize my type, e.g. I specifically want MyContainer[int, float]. Also tying in to the point about object construction :D did not appear to work on arguments to overrides of new(). Also sometimes when you get a type error at runtime no line number information is given so where the error occurred is anyone's guess. * :D is a great idea for function signatures, and is what you probably want for 99% percent of all your function arguments but surprisingly is not the default in the otherwise very terse Perl6. Why not? * set/SetHash are confusing on multiple levels. Set can be parameterized by a type but Set
Re: Justification for the "reversed" instruction format
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? On 9/6/16, Trey Harris wrote: > There’s a very common functional programming pattern, usually called flip; > its implementation in Haskell is simply: > > flip :: (a -> b -> c) -> b -> a -> cflip f x y = f y x > > Getting the same behavior out of a bespoke function in Perl 6 would be easy > for any particular case, but writing a general version of flip that would > work universally with all binary operators would be a pain to get right > (while maintaining *exactly* the same behavior and errors as the original > in all conditions), wouldn’t it? > > If so, R is syntactic sugar, but very helpful syntactic sugar. > > On Tue, Sep 6, 2016 at 12:59 PM Aaron Sherman > wrote: > > Oh, and note that you can pass R'd reductions as if they were normal prefix >> ops: >> >> $ perl6 -e 'sub dueet(&op, *@list) { op @list }; say dueet >> &prefix:<[R-]>, >> 1..100' >> -4850 >> >> >> >> On Tue, Sep 6, 2016 at 12:51 PM, Aaron Sherman >> wrote: >> >>> >>> >>> $ perl6 -e 'my @numbers = 1..100; say [-] @numbers; say [R-] @numbers' >>> -5048 >>> -4850 >>> >>> In general, it's kind of pointless with bare infix ops, as you can just >>> reverse the arguments, but when reducing or the like, it becomes much >>> more >>> valuable. >>> >>> >>> >>> On Tue, Sep 6, 2016 at 12:43 PM, Parrot Raiser <1parr...@gmail.com> >>> wrote: >>> I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3 in the documentation. I'm curious to know why the language includes them? I'm having trouble understanding where they would be useful. >>> >>> >> >
Re: Justification for the "reversed" instruction format
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, xmonadhttp://sinenomine.net
[perl #129080] [LTA] Missing bit in error message about R?? in Rakudo
Fixed in https://github.com/rakudo/rakudo/commit/c98ab93552 Tests needed
Help mechanism in REPL?
This isn't a request for a feature, merely a thought experiment. We're still in the phase where it's more important to ensure that existing features work properly than add new ones. How difficult would it be to include a mechanism within the REPL to select either documentation or an example, (possibly from the test suite), for a particular command? Selection might be by some control key combination, cursor positioning, or an alternative to "enter" at the end of the line. The purpose would be to speed development, by enabling an inexperienced developer to look up details while testing. Syntax errors generate messages which attempt to provide help; could this provide the basis for a "help" mechanism? Would this be useful? Opinions?
Re: [perl #129221] [BUG][UNI] Combinators get matched by regex even when no ignoremark is set
On Wed, Sep 7, 2016 at 5:12 PM, jn...@jnthn.net via RT < perl6-bugs-follo...@perl.org> wrote: > Actually, this is intended behavior. NFG synthetics take on the character > properties of their base character. How do you match any base Unicode digit (i.e. not just the ASCII 0-9) without any marks? -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
[perl #129221] [BUG][UNI] Combinators get matched by regex even when no ignoremark is set
On Wed Sep 07 10:35:51 2016, c...@zoffix.com wrote: > The expectation is this would fail to match, because I'm only asking > for digits: > > m: say "7\x[308]" ~~ /^ \d+ $/ > <+camelia> rakudo-moar f0bb58: OUTPUT«「7̈」» > Actually, this is intended behavior. NFG synthetics take on the character properties of their base character. /jnthn
[perl #128469] [BUG] done() on first entry to whenever block does not exit react {}
This now appears to have been fixed by some of the recent async fixes. Tests now pass and have been unfudged in https://github.com/perl6/roast/commit/92951b39ee
[perl #128469] [BUG] done() on first entry to whenever block does not exit react {}
This now appears to have been fixed by some of the recent async fixes. Tests now pass and have been unfudged in https://github.com/perl6/roast/commit/92951b39ee
[perl #129221] [BUG][UNI] Combinators get matched by regex even when no ignoremark is set
# New Ticket Created by Zoffix Znet # Please include the string: [perl #129221] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=129221 > The expectation is this would fail to match, because I'm only asking for digits: m: say "7\x[308]" ~~ /^ \d+ $/ <+camelia> rakudo-moar f0bb58: OUTPUT«「7̈」» There's a bunch of variants of this in http://irclog.perlgeek.de/perl6/2016-09-07#i_13166009 Fixing this should automagically fix https://rt.perl.org/Ticket/Display.html?id=128545#ticket-history
Re: [perl #129220] [BUG] .list,.List, (Real,) inconsistencies
I Realised what's happening. Real is a role so calling .list on it puns it. so the phenomenon can be boiled down to: Real ~~ Real.^pun # False I'm not sure if it should be that way. I will accept notabug though :) On Thu, Sep 8, 2016 at 12:33 AM Lloyd Fournier wrote: > # New Ticket Created by Lloyd Fournier > # Please include the string: [perl #129220] > # in the subject line of all future correspondence about this issue. > # https://rt.perl.org/Ticket/Display.html?id=129220 > > > > say (Real,) ~~ Real.list; # False > say (Real,) ~~ Real.List; # False > say Real.list ~~ (Real,); # True > say Real.list ~~ Real.List; # True > say Real.List ~~ (Real,); # True > say Real.List ~~ Real.list; # True > > say (Cool,) ~~ Cool.list; # True > say (Cool,) ~~ Cool.List; # True > say Cool.list ~~ (Cool,); # True > say Cool.list ~~ Cool.List; # True > say Cool.List ~~ (Cool,); # True > say Cool.List ~~ Cool.list; # True > > (Real,) seems to be a special snowflake and that's not Cool. >
[perl #129220] [BUG] .list,.List, (Real,) inconsistencies
# New Ticket Created by Lloyd Fournier # Please include the string: [perl #129220] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=129220 > say (Real,) ~~ Real.list; # False say (Real,) ~~ Real.List; # False say Real.list ~~ (Real,); # True say Real.list ~~ Real.List; # True say Real.List ~~ (Real,); # True say Real.List ~~ Real.list; # True say (Cool,) ~~ Cool.list; # True say (Cool,) ~~ Cool.List; # True say Cool.list ~~ (Cool,); # True say Cool.list ~~ Cool.List; # True say Cool.List ~~ (Cool,); # True say Cool.List ~~ Cool.list; # True (Real,) seems to be a special snowflake and that's not Cool.
[perl #129214] Initialization of variables explicitly declared as Hash[...]
# New Ticket Created by Peter Pentchev # Please include the string: [perl #129214] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=129214 > Hi, While trying to write a function returning Hash[Array[Str]], I came up against what looks like two related problems. All of this is with both 2016.08.1 and a current one - "This is Rakudo version 2016.08.1-116-gf648d3b built on MoarVM version 2016.08-35-g5108035". First of all, if a variable is declared, but not initialized, it seems that some kind of initialization is delayed until an assignment is made and then a type check breaks. Here's an example: #!/usr/bin/env perl6 use v6.c; my Hash[Int] $data; say 'Created, not initialized yet'; dd $data; say 'About to initialize it...'; $data = 5; say 'We never get here, do we?'; dd $data; The output is: [roam@straylight ~/lang/perl/misc/rt/hash/01-init]$ perl6 hash-init.p6 Created, not initialized yet Hash[Int] $data = Hash[Int] About to initialize it... Type check failed in assignment to $data; expected Hash[Int] but got Hash (${}) in block at hash-init.p6 line 11 And this leads almost directly to the second problem. I tried to work around this message by initializing the hash at creation time, and this seems to actually lose the value type constraint! Here's an example: #!/usr/bin/env perl6 use v6.c; my Hash[Int] $data .= new(); say 'Created and initialized'; dd $data; say 'About to assign to it...'; $data = 3/5; say 'So did we really store a Rat into a hash of Ints?'; dd $data; dd $data; And the output is: [roam@straylight ~/lang/perl/misc/rt/hash/02-weird-types]$ perl6 hash-int-rat.p6 Created and initialized Hash[Int] $data = (my Int %) About to assign to it... So did we really store a Rat into a hash of Ints? Hash[Int] $data = (my Int % = :key(0.6)) Rat = 0.6 Thanks in advance for looking into this! G'luck, Peter
Re: Justification for the "reversed" instruction format
There’s a very common functional programming pattern, usually called flip; its implementation in Haskell is simply: flip :: (a -> b -> c) -> b -> a -> cflip f x y = f y x Getting the same behavior out of a bespoke function in Perl 6 would be easy for any particular case, but writing a general version of flip that would work universally with all binary operators would be a pain to get right (while maintaining *exactly* the same behavior and errors as the original in all conditions), wouldn’t it? If so, R is syntactic sugar, but very helpful syntactic sugar. On Tue, Sep 6, 2016 at 12:59 PM Aaron Sherman wrote: Oh, and note that you can pass R'd reductions as if they were normal prefix > ops: > > $ perl6 -e 'sub dueet(&op, *@list) { op @list }; say dueet &prefix:<[R-]>, > 1..100' > -4850 > > > > On Tue, Sep 6, 2016 at 12:51 PM, Aaron Sherman > wrote: > >> >> >> $ perl6 -e 'my @numbers = 1..100; say [-] @numbers; say [R-] @numbers' >> -5048 >> -4850 >> >> In general, it's kind of pointless with bare infix ops, as you can just >> reverse the arguments, but when reducing or the like, it becomes much more >> valuable. >> >> >> >> On Tue, Sep 6, 2016 at 12:43 PM, Parrot Raiser <1parr...@gmail.com> >> wrote: >> >>> I've just stumbled across "reversed operators", e.g. say 4 R/ 12; # 3 >>> in the documentation. I'm curious to know why the language includes >>> them? I'm having trouble understanding where they would be useful. >>> >> >> >
[perl #129215] Passing a Hash[...] as a parameter to an imported sub
# New Ticket Created by Peter Pentchev # Please include the string: [perl #129215] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=129215 > Hi, So here's the main program: #!/usr/bin/perl6 use v6.c; use lib '.'; use trap; sub woof-local(Hash[Str:D] $data) { return $data[0]; } { my %opts = title => 'Something something something dark side'; say 'Invoking the local sub...'; say woof-local(Hash[Str:D].new(%opts)); %opts = "It's a trap!"; say 'Invoking the remote sub...'; say woof-remote(Hash[Str:D].new(%opts)); } And here's the trap.pm6 module: #!/usr/bin/env perl6 unit module trap; sub woof-remote(Hash[Str:D] $data) is export { return $data[0]; } And here's the result of the execution: [roam@straylight ~/lang/perl/misc/rt/hash/03-param]$ perl6 hash-param.p6 Invoking the local sub... Something something something dark side Invoking the remote sub... Type check failed in binding to $data; expected Hash[Str:D] but got (my Str:D % = :title(... in sub woof-remote at /home/roam/lang/perl/misc/rt/hash/03-param/trap.pm6 (trap) line 5 in block at hash-param.p6 line 20 G'luck, Peter
[perl #129219] [LTA] PERL6_TEST_DIE_ON_FAIL doesn't die in non-TODOed subtests
# New Ticket Created by Zoffix Znet # Please include the string: [perl #129219] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=129219 > Opening this mostly to serve as a reminder for myself. Currently, when PERL6_TEST_DIE_ON_FAIL is used, it won't die when tests fail inside a subtest and will wait until the outer-most subtest fails before dying. This (currently) is done to prevent it from dieing when failures are inside TODOed subtests. A better implementation would detect that the failed test is not a descendant of a todo-ed subtest and fail accordingly. As I mentioned, I hope to refactor the code of Test.pm6 in relatively near future to make it easier to maintain and at that point I'll resolve this ticket.
[perl #129213] [CONC] Bailador + start + IO hangs
On Tue Sep 06 08:58:37 2016, coke wrote: > See attached files. > > I have seen variations of this problem in 2016.07, .08, and just today > with f648d3b / 67b6836 / 5108035 - however the issues with the most > recent version seem to happen even sooner. (2016.08, for example, It > looked like even more work was being done in the start block before > the hang occurred0 > > Run 'perl6 wtf.p6' - this starts the bailador server listening on port 7890. > > Run the curl.sh command - you'll see an "A" in the log - if you > wait... no "B" appears. > Now run the curl.sh command multiple times - you'll see an "A" appear > for each request, but you won't get a "B" until a few requests have > been posted. > > Remove the start block and restart - "B" comes back very quickly. > > Revert wtf.p6, replace the slurp line with a "sleep 4" and rerun: now > A still emits immediately with each curl request, but B emits for each > of those requests, just after the expected delay. > > So, triggering the issue seems to require HTTP::Easy's .run method > (used in Bailador), an async start block, and then additional IO in > the start block. > Attaching gdb to see where it was hanging showed up that the thread waiting to accept was preventing others from running GC. Fixed that in MoarVM. Also boiled the bug down to the test case now in roast as S32-io/socket-accept-and-working-threads.t, which covers it. /jnthn