Re: Perl 6 Debugging
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 I don't expect anything more than: 1. The offending statement. 2. A pointer to perl 6 debugging. Thanks! Best, -Tom
Re: Perl 6 Debugging
On Mar 14, 2015 6:46 PM, yary not@gmail.com wrote: For some reason your github link comes up as an empty page when I click on it. I was able to find it here: https://gist.github.com/search?q=test_ellipsoid.pl I've never used gist.github.com before and probably murfled it. There should be a single repo with two files (test_ellipsoid.pl and Ellipsoid.pm6). Gist.git seems to take the repo name from the least ordered file name! I tried several times to get it right but I need to do some more reading and try again. -Tom
Perl 6 Debugging
I am trying to convert a fairly simple Perl 5 program and supporting modules to Perl 6 and making slow progress. Executing 'perl6 -v': This is perl6 version 2015.02-247-gab55cb7 built on MoarVM version 2015.02-25-g3d0404a I am trying to get something equivalent to Carp to show me the exact failure in my code but I haven't found out how yet. At the moment I am executing my program like this: perl6 --ll-exception perl 6 prog expecting to see the complete call stack and source code lines, but I don't see my code at all. Here is the result of my last execution: dump juvat2:test$ test_ellipsoid.pl Unhandled exception: This type cannot unbox to a native integer at unknown:1 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/perl6/runtime/CORE.setting.moarvm:print_exception:4294967295) from src/gen/m-CORE.setting:13775 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/perl6/runtime/CORE.setting.moarvm:anon:40) from gen/moar/stage2/NQPHLL.nqp:1381 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/nqp/lib/NQPHLL.moarvm:command_eval:374) from src/Perl6/Compiler.nqp:17 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/nqp/lib/Perl6/Compiler.moarvm:command_eval:93) from gen/moar/stage2/NQPHLL.nqp:1321 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/nqp/lib/NQPHLL.moarvm:command_line:116) from src/gen/m-main.nqp:39 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/perl6/runtime/perl6.moarvm:MAIN:18) from src/gen/m-main.nqp:35 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/perl6/runtime/perl6.moarvm:mainline:197) from unknown:1 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/perl6/runtime/perl6.moarvm:main:8) from unknown:1 (/home/tbrowde/.rakudobrew/moar-nom/install/languages/perl6/runtime/perl6.moarvm:entry:9) /dump Can anyone point me in the right direction? Thanks. -Tom
Object Contruction
My new object needs some methods run during construction. How can I do that without defining my own new method? I think something like this is supposed to work: class Geo::Ellipsoid; has $.ellipsoid is rw = 'WGS84'; # this needs more processing whether user-entered or default has $.units is rw = 'radians'; # ... more attributes # I can either us this (or submethod BUILD) # don't really yet understand the difference method BUILDALL { # but how do I get access to the class's attributes to manipulate? self.set_ellipsoid($ellipsoid); # more methods used to initialize... } method set_ellipsoid($ell) { self.ellipsoid = $ell; # process further... } So, the question is: how do I get access to the class attributes and methods inside BUILDALL (or BUILD)? Do I have to explicitly pass values in its arg signature, including $self? Many thanks. Best regards, -Tom
Re: Object Contruction
On Wed, Mar 18, 2015 at 7:22 AM, Moritz Lenz mor...@faui2k3.org wrote: ... http://doc.perl6.org/language/objects#Object_Construction lists at least two possible ways. Probably the most interesting one is BUILDALL with a callsame; see the last example (or example skeleton) in that section. Thanks, Moritz, I read that but it's a bit confusing to me. I'll experiment with it some more and hopefully have some more specific questions. Best, -Tom
Re: Object Contruction
On Wed, Mar 18, 2015 at 11:32 AM, Tom Browder tom.brow...@gmail.com wrote: On Wed, Mar 18, 2015 at 7:22 AM, Moritz Lenz mor...@faui2k3.org wrote: ... http://doc.perl6.org/language/objects#Object_Construction lists at least two possible ways. Probably the most interesting one is BUILDALL with a callsame; see the last example (or example skeleton) in that section. For my purposes I think the BUILD is best. The BUILDALL method seems to put me in limbo as far as the constructed object and using self. I made a simple class and a driver Perl script: $ cat T.pm HERE_PM class T; has $.a is rw; has $.b is rw; has $.c is rw; submethod BUILD( # set defaults here :$!a = 15, :$!b, :$!c, ) { self.set_b; } multi method set_b { if (self.a 10) { self.b = 1; } else { self.b = 0; } } multi method set_b($x) { self.b = $x; } HERE_PM $ cat T.pl HERE_PL #!/usr/bin/env perl6 use v6; use lib '.'; use T; my $t = T.new; say \$t.a = {$t.a}; say \$t.b = {$t.b}; say \$t.c = {$t.c.defined ?? $t.c !! 'undefined'}; $t.set_b(20); $t.c = 'defined'; say \$t.a = {$t.a}; say \$t.b = {$t.b}; say \$t.c = {$t.c.defined ?? $t.c !! 'undefined'}; HERE_PM $ perl6 T.pl $t.a = 15 $t.b = 0 $t.c = undefined $t.a = 15 $t.b = 20 $t.c = defined Best, -Tom
Re: Object Introspection for Existence of Methods: How?
On Fri, Mar 20, 2015 at 2:02 PM, Tom Browder tom.brow...@gmail.com wrote: On Mar 20, 2015 1:51 PM, Tobias Leich em...@froggs.de wrote: if $obj.^can($method_name) {... That doesn't seem to work with private methods. Any trick to accomplish that? -Tom
Re: Object Introspection for Existence of Methods: How?
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? If so, which ones do they need? and which can be left off? -Tom
Re: Perl 6 Debugging
On Mar 15, 2015 1:26 AM, Moritz Lenz mor...@faui2k3.org wrote: 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 ) = @_; ... 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 :-) I know. As I said, I am embarrassed to show how little progress I've made. 2. A pointer to perl 6 debugging. * use the MoarVM backend :-) Okay... * For runtime errors, https://github.com/jnthn/rakudo-debugger/ can help you. Okay... Thanks so much, Moritz Now I have more tools to move along to my goal. Warmest regards, -Tom
Re: Placeholder Variable (was: Perl 6 Debugging)
On Sun, Mar 15, 2015 at 2:55 PM, Timo Paulssen t...@wakelift.de wrote: ... Thanks, Timo! Subroutine arg handling is an awkward but very exciting improvement for an old but non-expert Perl 5 user. Very briefly, how does one properly translate this to Perl 6: sub foo {my @a = @_; } Best, -Tom
Re: Perl 6 Debugging
On Sat, Mar 14, 2015 at 5:19 PM, Tom Browder tom.brow...@gmail.com wrote: I am trying to convert a fairly simple Perl 5 program and supporting modules to Perl 6 and making slow progress. I have made much progress since Moritz showed me how to use perl6-m. Now I have come to a point where I haven't yet found what the problem is or how to fix it. Using perl6-m version: 2015.02-247-gab55cb7 built on MoarVM version 2015.02-25-g3d0404a with the same file ('Ellipsoid.pm) but in its present state I execute: $ perl6-m Ellipsoid.pm and see: ===SORRY!=== Error while compiling Ellipsoid.pm Placeholder variables cannot be used in a method at Ellipsoid.pm:352 -- method� set_custom_ellipsoid make: *** [test-e] Error 1 The file is located here: https://gist.github.com/4f3651c350774e065d3b The initial part of the code for the offending method definition is: method set_custom_ellipsoid { my ($name, $major, $recip) = @_; $name = uc $name; $recip = 0 unless defined $recip; if ($major) { %ellipsoids{$name} = [ $major, $recip ]; } else { croak(set_custom_ellipsoid called without semi-major radius parameter); } set_ellipsoid($name); } I don't see the problem there. Is it possible the problem is in one of the calls to the method? I looked at all the calls but don't see an obvious problem. Thanks. -Tom
Carp and Croak
How can I replace Carp and Croak in Perl 6? Thanks. Best, -Tom
Trig Functions to-radians and from-radians
Those two functions are documented here: http://design.perl6.org/S32/Numeric.html#Trigonometric_functions but I have tried to use them with no luck: say 10.to-radians(Degrees); Undeclared name: Degrees used at line 9 So how does one use the two functions? Best, -Tom
Re: Trig Functions to-radians and from-radians
On Tue, Mar 17, 2015 at 1:54 PM, Paul Cochrane p...@liekut.de wrote: Hi Tom, On Tue, Mar 17, 2015 at 12:52:42PM -0500, Tom Browder wrote: Those two functions are documented here: http://design.perl6.org/S32/Numeric.html#Trigonometric_functions but I have tried to use them with no luck: say 10.to-radians(Degrees); Undeclared name: Degrees used at line 9 So how does one use the two functions? it seems that to-radians() is specified, but not yet implemented in Rakudo (see, for example line 71 in https://github.com/perl6/roast/blob/master/S32-num/cool-num.t; the test is skipped for Rakudo). BTW: doc.perl6.org is a good resource for documentation of the currently implemented parts of the spec. The written spec has also come to mean speculation rather than specification. The specification is basically the roast test suite at present. Thanks, Paul! -Tom
Re: Carp and Croak
On Sun, Mar 15, 2015 at 8:32 PM, Tom Browder tom.brow...@gmail.com wrote: How can I replace Carp and Croak in Perl 6? According to TimToady on #perl6, to be honest, we haven't thought much about carp/croak yet. So I'm using die until something better comes along. -Tom
Re: Object Contruction
You are correct, Liz, but I was trying those pieces to demonstrate to myself that all was available to me in the methods and all worked as I expected. It demos very roughly what I think I have to do to translate Geo::Ellipsoid to Perl 6. It's a WIP and I'm learning Perl 6 as I go. The prog is a toy and not otherwise useful. Thanks. BTW, will you or any other Perl 6 people be presenting at YAPC::NC? I don't see a speaking line-up yet. Best, -Tom
Re: Object Contruction
On Mar 18, 2015 5:25 PM, Elizabeth Mattijsen l...@dijkmat.nl wrote: YAPC::NC ?? You mean YAPC::NA? Yes, my fingers don't seem to work very well! I will be there, Good, meeting Perl 6 devs is the only reason I think I might attend. but haven’t had any inspiration for a presentation just yet. Do you know of any Perl 6 topics to be presented? Best, -Tom ople that might be presenting?
Can a class have an attribute and a method with the same name?
I have a class with an attribute and a method with the same name and it looks so far like they clash. If that should be possible (which I suspect is true), I'll continue to debug. Thanks. -Tom
Re: Function Signatures: Return Types (replace wantarray?)
On Thu, Mar 19, 2015 at 5:58 PM, Tobias Leich em...@froggs.de wrote: The multi dispatcher *only* chooses the multi candidate by matching arguments to parameters. The return type is not considered. Okay, I have now kind of found that in the synopses (which are a bit confusing for me considering the function return type is discussed as part of the function signature). However, you all are correct that I should break the old idioms where it is necessary anyway and this is clearly such a case. Thanks to all who responded: Darren and Tobias. Best regards, -Tom
Re: Can a class have an attribute and a method with the same name?
On Mar 19, 2015 3:02 AM, Moritz Lenz mor...@faui2k3.org wrote: On 03/19/2015 12:40 AM, Tom Browder wrote: 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. That looks like the clash I'm seeing: A.x calls the method and not the accessor! Thanks, Moritz. Best regards, -Tom
Re: Need help with: Cannot find method 'postcircumfix:( )'...
On Mar 19, 2015 9:30 PM, Brandon Allbery allber...@gmail.com wrote: On Thu, Mar 19, 2015 at 10:26 PM, Tom Browder tom.brow...@gmail.com wrote: On Mar 19, 2015 8:58 PM, Brandon Allbery allber...@gmail.com wrote: On Thu, Mar 19, 2015 at 9:32 PM, Tom Browder tom.brow...@gmail.com wrote: if (self.$elem) { # === LINE 995 === LINE 995 This is an indirect method call. Is that really what you intended? No, it's supposed to be the value of the self attribute whose name is the value of my $elem. I have to go back and see how to do that. Unless there is more that you didn't show, that function is not a method and has no `self`. Why do you say that is not a method? The first line says iAs I mentioned, if you *do* have an object reference `self` in scope somehow and want to access a `has $elem` defined within it, you use the automatically generated accessor `self.elem`. (If it was declared private, that is `has $!elem`, then I don't think you can get to it within that function unless it was passed in as a parameter.) -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Re: Need help with: Cannot find method 'postcircumfix:( )'...
Thanks for pointing out the error and the best practice comment. When I get the method to do what I really want I will post the solution. Best, -Tom
Need help with: Cannot find method 'postcircumfix:( )'...
The error message is: Cannot find method 'postcircumfix:( )' in method _normalize_output at /usr/local/people/tbrowde/mydata/tbrowde-home-bzr/perl6/my-perl6-repos/Geo-Ellipsoid/test/../lib/Geo/Ellipsoid.pm:995 in method to at /usr/local/people/tbrowde/mydata/tbrowde-home-bzr/perl6/my-perl6-repos/Geo-Ellipsoid/test/../lib/Geo/Ellipsoid.pm:678 in sub print_dist at test_ellipsoid.pl:181 in sub MAIN at test_ellipsoid.pl:69 in block unit at test_ellipsoid.pl:25 Line 995 is in this method: method !_normalize_output(*@args) { my @a = @args; my $elem = shift @a; # 'bearing' or 'longitude' # adjust remaining input values by reference for (@a) - $_ { # - is 'read-write' operator if (self.$elem) { # === LINE 995 === LINE 995 # normalize to range [-pi,pi) while ($_ -(pi)) { $_ += $twopi } while ($_ = pi) { $_ -= $twopi } } else { # normalize to range [0,2*pi) while ($_ 0) { $_ += $twopi } while ($_ = $twopi) { $_ -= $twopi } } $_ = self!rad2deg($_) if self.units eq 'degrees'; } return @a; } Any hints would be appreciated. Best regards, -Tom
Re: Need help with: Cannot find method 'postcircumfix:( )'...
On Mar 19, 2015 8:58 PM, Brandon Allbery allber...@gmail.com wrote: On Thu, Mar 19, 2015 at 9:32 PM, Tom Browder tom.brow...@gmail.com wrote: if (self.$elem) { # === LINE 995 === LINE 995 This is an indirect method call. Is that really what you intended? No, it's supposed to be the value of the self attribute whose name is the value of my $elem. I have to go back and see how to do that. Good pointer, Brandon. Thanks! Best, -Tom
Re: Need help with: Cannot find method 'postcircumfix:( )'...
On Mar 19, 2015 9:30 PM, Brandon Allbery allber...@gmail.com wrote: Unless there is more that you didn't show, that function is not a method and has no `self`. [Please ignore last msg sent prematurely.] Why do you say that? The first line says it is a private method. -Tom
Re: Need help with: Cannot find method 'postcircumfix:( )'...
On Thu, Mar 19, 2015 at 9:26 PM, Tom Browder tom.brow...@gmail.com wrote: On Mar 19, 2015 8:58 PM, Brandon Allbery allber...@gmail.com wrote: On Thu, Mar 19, 2015 at 9:32 PM, Tom Browder tom.brow...@gmail.com wrote: if (self.$elem) { # === LINE 995 === LINE 995 This is an indirect method call. Is that really what you intended? This is what I'm trying to achieve: No, it's supposed to be the value of the self attribute whose name is the value of my $elem. I have to go back and see how to do that. And this seems to work, new line 995 (my only change in the method): if (self.{$elem}) { # === LINE 995 === LINE 995 Best, -Tom
Function Signatures: Return Types (replace wantarray?)
I need to replace the Perl 5 'wantarray' and think a multi method with differing return types should do it. So I've tried this: multi method foo($a, $b -- {Num,Num}) { #... } multi method foo($a, $b -- Num) { #... } and get errors like: Missing block at Ellipsoid.pm:672 -- ethod to($lat1, $lon1, $lat2, $lon2 -- �{Rat, Rat}) from test_ellipsoid.pl:12 I've tried parentheses, square brackets, and no grouping characters instead of curly braces but that doesn't change the error. Question: How does one properly provide differing function return type signatures? Thanks. Best, -Tom
Writing New Modules for Submission
The guidance for the directory layout for a proposed module is very clear for mandatory items, and two other directories are also mentioned: bin and doc. What about other items such as a Makefile for developer use, development test scripts and modules, and miscellaneous files found in CPAN Perl 5 modules such as TODO, Changes, and MANIFEST? Should they be removed, or maybe moved to a directory hidden from the module ecosystem? Thanks. -Tom
Passing arrays to subroutines
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? 2. Can I flatten the arrays into elements inside the foo call? If not, what is the best way to pass the array elements to foo? Thanks. Best, -Tom
Object Introspection for Existence of Methods: How?
I am trying to create a testing subroutine to detect if a class object has a certain method. I want it to look something like this: my $obj = Foo.new(); can_ok($obj, 'method1'); sub can_ok($obj, Str $method_name) { if $obj.{$method_name}:exists { say ok; return True; } else { say not ok; return False; } } A similar function can detect valid attributes, but this or variants I've tried don't. How can I test for the existence of a method? Thanks. Cheers! -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 20, 2015 1:50 PM, Will Coleda w...@coleda.com wrote: class bar { method foo () {}} my bar $a = bar.new(); say so $a.can(foo); Great! I'm not sure this warrants a new _ok method. How would you do it with an existing test? Thanks, Will. Cheers! -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 20, 2015 1:51 PM, Tobias Leich em...@froggs.de wrote: if $obj.^can($method_name) {... Thanks, Tobias. Cheers! -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 20, 2015 2:07 PM, Will Coleda w...@coleda.com wrote: use Test; class bar { method foo () {}} ok bar.can(foo), stuff; ok 1 - stuff Oops (I say as I slap my forehead)! Thanks, Will. -Tom
Re: Perl 6 script beginning lines: 'v6;' required?
On Fri, Mar 13, 2015 at 8:01 AM, Brandon Allbery allber...@gmail.com wrote: On Fri, Mar 13, 2015 at 8:54 AM, Rob Hoelz r...@hoelz.ro wrote: ... Thanks Rob and Brandon. -Tom
Perl 6 script beginning lines: 'v6;' required?
I have seen the following beginning lines of Perl programs in some examples on the Perl 6 web site: #!/usr/bin/env perl6 v6; Isn't the 'v6' superflous given the first line? Best regards, -Tom
Re: rakudo Test module: expanding tests considered?
On Mar 24, 2015 3:44 AM, Moritz Lenz mor...@faui2k3.org 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? ... 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. Sounds like a good plan. Thanks. Cheers! -Tom
Re-installation of Perl 6 (Rakudo Star) via rakudobrew on Linux
I installed the 2015.02 version of Perl 6 (Rakudo Star) by following these instructions on the perl6.org site: quote To install Rakudo and Panda using rakudobrew: rakudobrew build moar rakudobrew build-panda Finally, install Task::Star. This will install all the modules that are shipped with the Rakudo Star Perl 6 distribution: panda install Task::Star /quote Since I saw no words regarding installation of a new version I blindly repeated the instructions above, and I see my perl6 is indeed updated to 2015.03. However, I got this error message during the last step (panda install task::Star) for the last module (LWP::Simple): quote == Fetching LWP::Simple == Building LWP::Simple Compiling lib/LWP/Simple.pm to mbc == Testing LWP::Simple t/000-load-module.t . ok t/basic-auth.t .. ok t/custom-headers-and-content.t .. ok t/get-binary-camelia.t .. ok t/get-chunked-6guts.t ... ok t/get-perl6-org.t ... ok t/get-unsized.t . ok t/get-w3-latin1-utf8.t .. ok t/get-w3-redirect.t . ok t/getstore.t ok t/parse-url.t ... ok Failed to connect: connection timed out in method initialize at src/gen/m-CORE.setting:24980 in method new at src/gen/m-CORE.setting:24964 in block unit at t/socket-sanity.t:6 t/socket-sanity.t ... Dubious, test returned 255 (wstat 65280, 0xff00) Failed 2/2 subtests t/stringify-headers.t ... ok Test Summary Report --- t/socket-sanity.t (Wstat: 65280 Tests: 0 Failed: 0) Non-zero exit status: 255 Parse errors: Bad plan. You planned 2 tests but ran 0. Files=13, Tests=53, 79 wallclock secs ( 0.05 usr 0.02 sys + 10.71 cusr 0.95 csys = 11.73 CPU) Result: FAIL test stage failed for LWP::Simple: Tests failed in method install at lib/Panda.pm:125 in block at lib/Panda.pm:1 in method resolve at lib/Panda.pm:185 in sub MAIN at /home/tbrowde/.rakudobrew/bin/../moar-nom/install/languages/perl6/site/bin/panda:20 in sub MAIN at /home/tbrowde/.rakudobrew/bin/../moar-nom/install/languages/perl6/site/bin/panda:18 in block unit at /home/tbrowde/.rakudobrew/bin/../moar-nom/install/languages/perl6/site/bin/panda:77 Failure Summary Task::Star *test stage failed for LWP::Simple: Tests failed /quote Questions: 1. Is there a better or proper way to upgrade to a new Rakudo Star release? 2. Is the failure of LWP::Simple a bug or just some weird misconfiguration on my system? Thanks. Cheers! -Tom
Re: Re-installation of Perl 6 (Rakudo Star) via rakudobrew on Linux
On Tue, Mar 24, 2015 at 10:44 AM, Steve Mynott steve.myn...@gmail.com wrote: The easiest thing is to delete everything and start again. Well, one reason to delete and start over is this time panda had changed paths so I was using the old panda. But now, even with the new panda, I still get the failed tests for LWP::Simple. I guess a bug report is in order. Maybe I'll ask on #perl6. Best, -Tom
Re: Re-installation of Perl 6 (Rakudo Star) via rakudobrew on Linux
On Tue, Mar 24, 2015 at 12:10 PM, Tom Browder tom.brow...@gmail.com wrote: I guess a bug report is in order. Maybe I'll ask on #perl6. A bug report is in order because I didn't get that failure with the previous version. -Tom
Re: How to get indirect access to a class attribute?
On Wed, Mar 25, 2015 at 8:29 AM, Moritz Lenz mor...@faui2k3.org wrote: the indirect method call syntax is the right approach, you just got too many other details wrong to make it work. Fair enough--my fingers fumbled a few important things. I'll correct and recheck; Thanks, Moritz (and Bruce). Cheers! -Tom
Re: How to get indirect access to a class attribute?
On Wed, Mar 25, 2015 at 8:47 AM, Tom Browder tom.brow...@gmail.com wrote: On Wed, Mar 25, 2015 at 8:29 AM, Moritz Lenz mor...@faui2k3.org wrote: the indirect method call syntax is the right approach, you just got too many other details wrong to make it work. This syntax works in a method as you said: self.$elem() Again I was getting errors that masked the correctness of that syntax--incomplete debugging! Thanks all. Cheers! -Tom Fair enough--my fingers fumbled a few important things. I'll correct and recheck; Thanks, Moritz (and Bruce). Cheers! -Tom
How to get indirect access to a class attribute?
Given a class like: our %attrs = (age=1,wgt=2); class foo { has $.age = rw;} method a { for %attrs.kv - $k, $v { my $aval = self.$k(); # supposed to work for a method name 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 '()'). 2. Do I have to write a custom accessor to do so? Thanks. Best regards, -Tom
Re: Fancy sub arg handling: ability to expand error message?
On Mar 28, 2015 8:54 AM, Moritz Lenz mor...@faui2k3.org wrote: 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. Agree--looks like we need some of Damien Conways wonderful CPAN modules ported ASAP! Cheers! -Tom
Please retract bug [perl #124169]
That bug should have been filed with LWP::Simple, and I have just done so. Please close this bug as a mistake. Best, -Tom
Is there an equivalent env var to PERL5LIB for Perl 6 module locations?
I would like an easy way to have a local search path for local Perl 6 modules (those not installed via Panda). I'm used to using the environment variable PERL5LIB for Perl 5 modules. Is there currently any equivalent way to do that for Perl 6? Thanks. -Tom
Re: Is there an equivalent env var to PERL5LIB for Perl 6 module locations?
On Mon, Mar 30, 2015 at 7:35 PM, Rob Hoelz r...@hoelz.ro wrote: Yup, PERL6LIB. =) And how did you find out about it, i.e., where is it documented? Thanks. -Tom
Re: Can a user cheat and call a class's private method?
On Fri, Mar 27, 2015 at 6:36 AM, Carl Mäsak cma...@gmail.com wrote: This feels like the same conversation we had earlier this week about accessing private methods. :) But maybe there are still a few new points that can be made. ... Okay, Carl, I think I understand. But what about this for my particular situation (this sounds like your method A I believe): Use a separate module (but included with the code for the whole package) for the non-class-specific, formerly-private methods to be public, but the use statement for the modules would be inside the class-specific methods that need them (a new, restricted scoping in Perl 6 I understand). That actually makes more sense to me now because some of the private methods are really general math subroutines. That way I can test those subroutines without breaking OOP (I think). Best, -Tom
Re: Fancy sub arg handling: ability to expand error message?
On Sat, Mar 28, 2015 at 5:43 PM, Tom Browder tom.brow...@gmail.com wrote: Agree--looks like we need some of Damien Conways wonderful CPAN modules That should be Damian Conway's -Tom
Fancy sub arg handling: ability to expand error message?
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? Thanks. Best, -Tom
Re: Example module and its use
On Mar 28, 2015 6:23 AM, Paul Cochrane p...@liekut.de wrote: BTW: please don't use the shortcut 'v6;': AFAIU it's been deprecated in favour of 'use v6;' Hope this helps a bit. It does, thanks! BTW, I think my fumbling in learning Perl 6 is giving me some ideas for the Coookbook, at least for p6 newbies. I am keeping track of my questions and resullting simple cases to show exactly how to do something with working code--not too advanced but definitely helpful I think. In that vein, the synopses could do a better job of showing real code--maybe that's part of the cookbook I haven't seen yet. Cheers! -Tom
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 7:04 AM, Tom Browder tom.brow...@gmail.com wrote: From your and Henk's comments, I think I need to learn a lot more about testing in general. Any recommendations for books on the subject? -Tom
Re: Object Introspection for Existence of Methods: How?
On Sun, Mar 22, 2015 at 7:48 PM, Henk van Oers h...@signature.nl wrote: On Sun, 22 Mar 2015, Tom Browder wrote: Do Perl 6 modules not need tests? Yes they need tests. If so, which ones do they need? The public interface. and which can be left off? The private stuff. You can not test for 'random_name'. This is not about Perl. It's OO-programming. Okay, Henk. Thanks. Best, -Tom
Re: Object Introspection for Existence of Methods: How?
On Sun, Mar 22, 2015 at 6:22 PM, Henk van Oers h...@signature.nl wrote: On Sun, 22 Mar 2015, Tom Browder wrote: On Fri, Mar 20, 2015 at 2:02 PM, Tom Browder tom.brow...@gmail.com wrote: On Mar 20, 2015 1:51 PM, Tobias Leich em...@froggs.de wrote: if $obj.^can($method_name) {... That doesn't seem to work with private methods. Any trick to accomplish that? What part of 'private' did you mis? If you write private methods you do not need introspection. I'm trying to write a test. -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 23, 2015 3:19 AM, Moritz Lenz mor...@faui2k3.org wrote: 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. No argument from me. I am at the point of trying to replicate, in Perl 6, somene else's test suite (done for a Perl 5 class) and I have not, in general, been questioning the need for each test. And I must admit I may have gone overboard doing some things just because they can be done in Perl 6 and seem to be in the spirit of the original author's intent. From your and Henk's comments, I think I need to learn a lot more about testing in general. Thanks. Best, -Tom
Need Help with Perl 6 Module Test::Builder
I need Perl 6 module Test::Builder to continue porting CPAN Perl 5 module Geo::Ellipdoid to Perl 6. Test::Builder currently is in the Task::Star module but it fails during the build process with Rakudo 2015.03 (it did NOT fail with Rakudo 2015.02). I have filed a bug report at the github source repo (https://github.com/soh-cah-toa/p6-test-builder), and have attempted to contact the original author (Kevin Polulak, Email: kpolu...@gmail.com, IRC: soh_cah_toa) with no success yet. The offending line with 'make test' is shown in the error message: ===SORRY!=== Error while compiling lib/Test/Builder/Plan.pm Virtual call $.expected may not be used on partially constructed objects at lib/Test/Builder/Plan.pm:102 -- alid or missing plan!' unless $.expected�.defined; expecting any of: prefix or term make: *** [blib/lib/Test/Builder/Plan.pm.moarvm] Error 1 Then, when I comment out the offending line, I get this with 'make test': ===SORRY!=== Error while compiling lib/Test/Builder.pm The following packages were stubbed but not defined: Test::Builder at lib/Test/Builder.pm:287 -- done unless $TEST_BUILDER.done_testing }�EOL expecting any of: statement end make: *** [blib/lib/Test/Builder.pm.moarvm] Error 1 And I, a mere noob, have no idea how to proceed. I think that it will take some careful study of the whole package to see how the class constructors interrelate, but that will take some time. Could the singleton use be the problem? In the meantime, does anyone have any idea what might have triggered the failure between Rakudo 2015.02 and 2015.03? Were there any significant changes in the class construction that might be a place to look? Singleton use? I did re-visit at the Rakudo 2015.03 announcement and didn't notice anything obvious that seemed to affect the modules involved. Final questions: 1. Am I the only person seeing this failure? 2. If the failure continues (assuming I'm not the only one, shouldn't it be marked bad and removed from Task::Star? Thanks for any ideas. Cheers! -Tom
Example module and its use
I'm trying to get the basic syntax down on creating and using a module. I've tried this and get an error: # file 1: Bar.pm module Bar; sub foo($a, $b, $c) is export {} # file 2: doit.pl v6; use lib .; use Bar foo; my @t = foo(1, 2, 3); # in a shell $ perl6 doit.pl ===SORRY!=== Error while importing from 'Bar': no EXPORT sub, but you provided positional argument in the 'use' statement I've tried to digest the S11 synopsis on compilation units and I don't see any obvious problem. Ideas, please. Thanks. Best regards, -Tom
Re: Can a user cheat and call a class's private method?
On Mar 26, 2015 11:04 AM, Moritz Lenz mor...@faui2k3.org wrote: On 26.03.2015 16:55, Tom Browder wrote: I need to test some private routines, so is there a way to do that ... And then you can also do something like: my $private_method = $obj.^private_method_table{$methodname}; $obj.$private_metnod(arguments here) That works great! but it is rather questionable use of the MOP. Nevertheless, it is very helpful for debugging. Thanks. Cheers! -Tom
Re: Passing arrays to subroutines
On Thu, Mar 19, 2015 at 10:15 AM, Moritz Lenz mor...@faui2k3.org wrote: On 03/19/2015 04:05 PM, Tom Browder wrote: In Perl 5 I can do this: ... 1. How can I combine arrays @a and @b into one array? generally with the comma operator: my @combined = @a, @b; It looks like I can also do this: my @combined = (@a, @b); # use parens (not needed, though) 2. Can I flatten the arrays into elements inside the foo call? foo(|@combined) Hm, it looks like this also works: foo(|@, |@b); My error messages are misleading now because of deeper problems. Sorry for the noise. Cheers! -Tom
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 10:41 AM, Elizabeth Mattijsen l...@dijkmat.nl wrote: On 23 Mar 2015, at 14:11, Tom Browder tom.brow...@gmail.com wrote: Any recommendations for books on the subject? Perl Testing - A Developer’s notebook: Thanks, Liz--getting it! -Tom
Can a user cheat and call a class's private method?
I need to test some private routines, so is there a way to do that? Or will I have to copy code to a test script or? BTW, the tests are for input/output checks during development--not for the public user. Thanks. Best, -Tom
Re: Example module and its use
On Fri, Mar 27, 2015 at 8:27 PM, Nathan Brown nbrow...@gmail.com wrote: If you put the attribute is export on a sub, then it is part of the :DEFAULT and :ALL tagsets. That means you can import them by: use Bar :DEFAULT; Okay, I'll try that. http://design.perl6.org/S11.html#Dynamic_exportation states: The default EXPORTALL handles symbol exports by removing recognized export items and tagsets from the argument list, then calls the EXPORT subroutine in that package (if there is one), passing in the remaining arguments. The bold text is my emphasis. It seems to imply that in perl6 you can only import by tagsets without implementing an EXPORT subroutine. This strikes me as weird because of this example in S11: use Sense common @horse; but I couldn't find any examples in the spec tests. Am I missing something? My question too. Thanks. -Tom
Re: Example module and its use
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!! Best, -Tom
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 11:28 AM, B. Estrade estr...@gmail.com wrote: As good as this book is, it's still Perl 5 specific. So watch out if you're coming from Perl 5 land and Heaven forbid you're looking to do traditional things, you might get scolded for asking a reasonable question. o_O. Roger! Thanks, Brett. -Tom
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 9:35 AM, Bruce Gray robertbrucegr...@gmail.com wrote: Any recommendations for books on the subject? http://shop.oreilly.com/product/9780596100926.do Perl Testing: A Developer's Notebook by Ian Langworth and Chromatic From 2005, but still a fantastic primer on testing in Perl. Thanks, Bruce. -Tom
rakudo Test module: expanding tests considered?
I have some tests needed for a Perl 5 module I'm trying to translate from Perl 5 to Perl 6 that aren't available yet. 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? Thanks. Best, -Tom
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 5:25 PM, Henk van Oers h...@signature.nl wrote: From 2005, but still a fantastic primer on testing in Perl. Sorry Tom. I think you must read a book about OO. I will go back and review OO, Henk. Thanks. Best, -Tom
Re: rakudo Test module: expanding tests considered?
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. Hope that is not too muddled a response. Best regards, -Tom
Re: Perl 6 Meetups in the Southeast US?
On Thu, May 7, 2015 at 10:25 PM, Bruce Gray bruce.g...@acm.org wrote: ... Hi Tom! Atlanta.PM meets on the first Thursday of each month, at the topmost point of the I-285 perimeter. Thanks for the kind invitation, Bruce. I have been eyeballing the Atlanta PM as the closest active PM group to me I can find. And I hope to make it to one of your meetings before too long. Best regards, -Tom P.S. I just joined the Atlanta PM mailing list and asked a Perl 6 Hackathon interest question there. P.P.S. Those are two very cute Util versions (modules?)!
Will Perl 6 save a compiled version of a source program like Python?
I found some discussion of such a capability on the Perl Mongers' site but haven't found anything official yet in the Synopses. But I did find there an option that might do something related: --output-format (which is implementation defined). However, I do not see that option in Rakudo Perl 6. Can anyone point me to more info or say yes or no to possible support of a save-compilation feature? Thanks. Cheers! -Tom
Re: Will Perl 6 save a compiled version of a source program like Python?
On Mon, May 18, 2015 at 7:47 AM, Elizabeth Mattijsen l...@dijkmat.nl wrote: On 18 May 2015, at 14:28, Tom Browder tom.brow...@gmail.com wrote: ... Can anyone point me to more info or say yes or no to possible support of a save-compilation feature? ... [good answer to my question...] Thanks Liz and Tobias! Cheers! -Tom
Perl 6 Meetups in the Southeast US?
Unfortunately, I cannot attend the upcoming YAPC::NA in June. Does anyone know of any upcoming public tech meetings or conferences to be held in the southeast or mid-Atlantic US where there might be a Perl 6 dev presence? Thanks. -Tom
panda: Should it have an 'uninstall' option?
Wouldn't an uninstall option be a good thing for panda? I don't know how insulated a Perl 6 package is from the rest of the installed packages, but I remember on more than one occasion wishing CPAN and Perl 5 packages had an uninstall option when an installation somehow got corrupted. Best regards, ~Tom
Fwd: Re: panda: Should it have an 'uninstall' option?
-- Forwarded message -- From: Tom Browder tom.brow...@gmail.com Date: Apr 7, 2015 6:46 AM Subject: Re: panda: Should it have an 'uninstall' option? To: Tadeusz Sośnierz tadeusz.sosni...@onet.pl Cc: On Apr 7, 2015 6:34 AM, Tadeusz Sośnierz tadeusz.sosni...@onet.pl wrote: On 07.04.2015 12:54, Tom Browder wrote: Wouldn't an uninstall option be a good thing for panda? It's planned: https://github.com/tadzik/panda/issues/99 Sorry, I just looked at TODO and saw nothing there--forgot about looking at issues. -Tom
Re: Favorite (Xe|E)macs mode script for Perl 6?
Thanks, Kamil! ~Tom
Favorite (Xe|E)macs mode script for Perl 6?
I've found a couple of references to *emacs modes for Perl 6 on the net. I use Xemacs and would appreciate hearing from anyone on a recommended Perl 6 mode script for it. Thanks. Best, ~Tom
Re: Need Help with Perl 6 Module Test::Builder
On Apr 1, 2015 4:57 PM, David Warring david.warr...@gmail.com wrote: I'm seeing the failure(s) as well. I've put in a PR that hopefully addresses this issue While we're waiting for the author, you can try checkout out, and building https://github.com/dwarring/p6-test-builder.git Thanks a heap, David! I'll give it a whirl soon. Cheers! -Tom
Re: Need Help with Perl 6 Module Test::Builder
On Wed, Apr 1, 2015 at 5:22 PM, Tom Browder tom.brow...@gmail.com wrote: On Apr 1, 2015 4:57 PM, David Warring david.warr...@gmail.com wrote: I'm seeing the failure(s) as well. I've put in a PR that hopefully addresses this issue While we're waiting for the author, you can try checkout out, and building https://github.com/dwarring/p6-test-builder.git Thanks a heap, David! I'll give it a whirl soon. Tried it and 'make test' works perfectly! Thanks again, David. Warmest regards, -Tom
Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
I finally found the Perl 6 version of Perl 5's $0 listed in: tablets.perl6.org/appendix-b-grouped.html#special-variables as '$*EXECUTABLE_NAME', and I expected it to act the same as $0 in Perl 6, but I have two problems with it: 1. When used it yields 'perl6' regardless of the script's name (a bug?). $ cat t.pl #!/usr/bin/env perl6 say $*EXECUTABLE_NAME; $ chmod +x t.pl $ ./t.pl perl6 2. It seems very ungainly to go from two characters to 17. Couldn't it be shortened a bit, say, '$*0' or '$*EXE_NAME' or '$*PROG' or something else? Am I doing something wrong or do I have the wrong expectations? $ perl6 --version This is perl6 version 2015.03-48-g9746e88 built on MoarVM version 2015.03 Best regards, -Tom
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
On Sat, May 30, 2015 at 8:30 AM, Tobias Leich em...@froggs.de wrote: Please also take a look at $*EXECUTABLE, $*PROGRAM and $*PROGRAM_NAME. Tobias, I didn't find $*PROGRAM in the doc listed by Paul: http://doc.perl6.org/language/variables#Special_Variables Also, the following were not in: http://tablets.perl6.org/appendix-a-index.html that I could find. $*EXECUTABLE_NAME $*PROGRAM $*PROGRAM_NAME From a Perl 6 newbie standpoint, it looks like there are too many docs with overlapping purposes referenced on perl.org and which, confusingly, have different pieces missing. Except for the Synopses, I'm not sure what document to go to for the definitive answer. And, as usual, I have no suggestions for an easy fix. Thanks Paul and Tobias. Best, -Tom
Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME
On Sat, May 30, 2015 at 9:03 AM, Tom Browder tom.brow...@gmail.com wrote: On Sat, May 30, 2015 at 8:30 AM, Tobias Leich em...@froggs.de wrote: Please also take a look at $*EXECUTABLE, $*PROGRAM and $*PROGRAM_NAME. Tobias, I didn't find $*PROGRAM in the doc listed by Paul: But it is the only one of the group I found in Synopsis 28 (Special names). In S28 I did find the Perl 5 to Perl 6 translation table in which I had overlooked $0 before. -Tom
Re: Sub args: choose one of two?
Perhaps you want that the named arguments are required rather than ... Thanks, Pm! Best, -Tom
Re: Problem with string index for substrings a position zero (a bug?)
On Fri, Jul 3, 2015 at 7:21 AM, yary not@gmail.com wrote: On Fri, Jul 3, 2015 at 8:07 AM, Tom Browder tom.brow...@gmail.com wrote: ... I completely missed the other obvious attempt to use Perl 5ish semantics: if $idx = 0 { ... Which worked also (surprisingly given S32 and your comments)! Thanks for all the help Carl and yary--I definitely should have used define, but I think the S32 wording is a bit confusing. Best, -Tom
Re: Problem with string index for substrings a position zero (a bug?)
On Fri, Jul 3, 2015 at 7:35 AM, Tom Browder tom.brow...@gmail.com wrote: On Fri, Jul 3, 2015 at 7:21 AM, yary not@gmail.com wrote: On Fri, Jul 3, 2015 at 8:07 AM, Tom Browder tom.brow...@gmail.com wrote: ... So, considering all the comments and S32 wording, I suspect that this would be sort of a best practice idiom: if defined $idx { ... Thanks for all the help. Best, -Tom
Re: Problem with string index for substrings a position zero (a bug?)
On Fri, Jul 3, 2015 at 7:27 AM, Elizabeth Mattijsen l...@dijkmat.nl wrote: Hi Tom, ... Apart from what Carl and yary said, I would like to add that *if* you’re just interested in knowing whether a string starts with a certain substring, you can use .starts-with: ... Thanks, Liz, Perl 6 certainly has a lot of new and neat features for strings! My first attempts at the moment are to translate my common Perl 5 usage as painlessly as possible. (There is a HUGE amount of new stuff I hope to absorb as I get more comfortable with the immediate Perl 5ish translation first And I Iook forward to Perl 6 Best Practices.) Best, -Tom
Re: Problem with string index for substrings a position zero (a bug?)
On Fri, Jul 3, 2015 at 7:40 AM, yary not@gmail.com wrote: On Fri, Jul 3, 2015 at 8:35 AM, Tom Browder tom.brow...@gmail.com wrote: if $idx = 0 { ... Which worked also (surprisingly given S32 and your comments)! That doesn't work when the line has no comment in it, it gives an error Oops--forgot about the no comment test. Thanks, yary. -Tom
Passing a hash to a subroutine: best method?
While experimenting I've found the first two methods of passing a hash to a subroutine work: # method 1 my %hash1; foo1(%hash1); say %hash1.perl; sub foo1(%hash) { %hash{1} = 0; } # method 2 my %hash2; my $href2 = %hash2; foo2($href2); say %hash2.perl; sub foo2($href) { $href{1} = 0; } # this is what I naively tried first # method 3 [DOESN'T WORK] my %hash3; my $href3 = \%hash3; foo3($href3); say %hash3.perl; sub foo3($href) { %($href}){1} = 0; } The perl dump shows the same results for the first two methods: {1 = 0} So which is the preferred method (or more correct)? Thanks. Best regards, -Tom
Re: Passing a hash to a subroutine: best method?
On Jul 3, 2015 11:14 AM, Brandon Allbery allber...@gmail.com wrote: On Fri, Jul 3, 2015 at 11:26 AM, Tom Browder tom.brow...@gmail.com wrote: # method 1 ... foo1(%hash1); This is what I would naïvely expect to work in any language except Perl 5. That comment, along with Liz's, has convinced me to use method 1 (less typing, too, I think). Thanks all. -Tom
Re: Passing a hash to a subroutine: best method?
On Fri, Jul 3, 2015 at 10:26 AM, Tom Browder tom.brow...@gmail.com wrote: While experimenting I've found the first two methods of passing a hash to a subroutine work: # method 1 my %hash1; foo1(%hash1); say %hash1.perl; sub foo1(%hash) { %hash{1} = 0; } Another question on method 1 above, please: What is the proper type to use for the %hash for a more complete signature in function foo1? I've tried various types such Associative, Hash, and Any and gotten an exception. Thanks, -Tom
Re: Passing a hash to a subroutine: best method?
On Fri, Jul 3, 2015 at 2:03 PM, Timo Paulssen t...@wakelift.de wrote: On 07/03/2015 07:20 PM, Tom Browder wrote: On Fri, Jul 3, 2015 at 10:26 AM, Tom Browder tom.brow...@gmail.com wrote: ... What is the proper type to use for the %hash for a more complete signature in function foo1? I've tried various types such ... When you define a parameter with a % sigil or a @ sigil (or even a sigil) in your signature, you'll get the right kind of type restriction for free. Okay, so that is fine then. Hope that helps and I've also successfully predicted your next stumbling block for you :) I think so, Timo--thanks! -Tom
Re: Sub args: choose one of two?
On Jun 27, 2015 8:05 PM, Brent Laabs bsla...@gmail.com wrote: http://design.perl6.org/S99.html#LTA Ah, I almost guessed right! Best, -Tom
Re: Sub args: choose one of two?
On Jun 27, 2015 7:39 PM, yary not@gmail.com wrote: This sort of works, in that it does the right thing when you give one correct arg, and fails when you give neither arg or both args. The error message is good when you give both args, but LTA with no args. Thanks, Yary, Good use of multi which I passed over in my search! Best regards, -Tom P.S. I assume LTA means less than adequate?
Sub args: choose one of two?
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. Reading S06, I don't yet see a way to do that without dropping back to handling the @*ARGV array in the same way I am used to handling the @ARGV array in Perl 5 (e.g., as each arg 1 or 2 is checked for in @ARGV, check if the other has been entered already and inform the user accordingly; then, after @ARGV is read, ensure one of the required args was found). Am I wrong? Thanks. Best regards, -Tom
Re: Sub args: choose one of two?
On Jun 28, 2015 5:24 AM, Moritz Lenz mor...@faui2k3.org wrote: 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: ... multi MAIN('open') {say Opening door;} Interesting idea for future use, Moritz, thanks! -Tom
Problem with string index for substrings a position zero (a bug?)
I originally had problems with the S32 description of string function index. S32 says that if the substring is not found then a bare Int is returned which evaluates to false, otherwise an Int with the position of the first substring match is returned. It goes on to say that one should not evaluate the result as a number. So my question was, how does one practically use that information for a substring that starts at position zero which evaluates as false? Based on the S32 description, I first tried this to remove a comment from a data line: my $str = '# a comment'; my $idx = $str.index('#'); if $index $index = 0 { $str = $str.substr(0, $idx); } It didn't work for a comment at position zero but it found one at any other position or no comment at all. Then I tried this: if $idx { $str = $str.substr(0, $idx); } Same result as the previous method: it would not report a substring at position zero. So what am I doing wrong for finding position zero substrings? Best, Tom P.S. The S32 description I believe should note that the default value of the index starting position is 0.
Re: Sub args: choose one of two?
On Tue, Jun 30, 2015 at 10:25 PM, Patrick R. Michaud pmich...@pobox.com wrote: On Sat, Jun 27, 2015 at 05:39:32PM -0500, Tom Browder wrote: ... multi sub MAIN(:$need!) { say need; } multi sub MAIN(:$hope!) { say hope; } I now have another problem, and I think I know the solution but I hope there is another way. When I just use one MAIN sub and the 'semicolon' form, the rest of the file acts like it is in the scope of the MAIN sub, BUT when I use the multi form it seems I'm not in the same scope so what are my choices? The only way out I see so far is: 1. Write the 'main' program as another subroutine and call it from each of the appropriate multi subs--aarghh! OR 2. Drop back to using just one MAIN sub and adding more code to handle the alternate options as I have tried to describe. OR 3. Translate all my perl 5 code and handle the @*ARGS array just as i have done with the @ARGV array (sigh!). Best, -Tom
Re: Sub args: choose one of two?
On Thu, Jul 2, 2015 at 2:59 PM, Patrick R. Michaud pmich...@pobox.com wrote: On Thu, Jul 02, 2015 at 03:22:17PM -0400, Brandon Allbery wrote: On Thu, Jul 2, 2015 at 3:08 PM, Tom Browder tom.brow...@gmail.com wrote: 1. Write the 'main' program as another subroutine and call it from each of the appropriate multi subs--aarghh! This seems like the right one to me; it also makes it easier to provide similar functionality as a library. This is the approach I would take, yes. Okay, a second look shows me that's not quite as bad as I first though. Thanks, all. Best, -Tom
Re: Sub args: choose one of two?
On Thu, Jul 2, 2015 at 3:08 PM, yary not@gmail.com wrote: Here's a hackish way to implement #1: ... Ugh, my head hurts, yary, I think I'll save those methods for the future. Thanks! Best, -Tom
Re: .perl method: any plans for allowing output format changes?
On Thu, Aug 13, 2015 at 3:51 AM, Steve Mynott steve.myn...@gmail.com wrote: The closest to Perl 5 Data::Dumper is Perl6 Data::Dump. Note also .perl will hang on many data structures. I find using YML dump also useful. Is that YAML dump? -Tom
Re: .perl method: any plans for allowing output format changes?
On Thu, Aug 13, 2015 at 8:59 AM, Steve Mynott steve.myn...@gmail.com wrote: On Thu, Aug 13, 2015 at 3:51 AM, Steve Mynott steve.myn...@gmail.com wrote: On 13 August 2015 at 11:36, Tom Browder tom.brow...@gmail.com wrote: The closest to Perl 5 Data::Dumper is Perl6 Data::Dump. Note also .perl will hang on many data structures. I find using YML dump also useful. Is that YAML dump? Yes, https://github.com/perl6-community-modules/yaml-pm6/ Thanks for a great link, Steve! Best. -Tom
What are Perl 6's killer advantages over Perl 5?
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? For me, stronger typing, named subroutine arguments, better classes and namespaces, object methods, and eventually better concurrency and compiled program persistence are among goodies long awaited. Thanks. -Tom The reason for my request is to help with a better introduction in my modest draft tutorial on converting Perl 5 to Perl 6 code at the Perl Monastery. I am comfortable with the example code I use there (which is not currently intended to showcase new features), but I am getting several comments on why one should even bother with Perl 6?