Re: How to do a substring replacement in Perl 6

2015-06-09 Thread Paul Cochrane
  Hi all!
  
  From http://perldoc.perl.org/functions/substr.html:
  
  substr has a 4th argument (or you can use substr as an lvalue) for 
  replacement.
  substr EXPR,OFFSET,LENGTH,REPLACEMENT
  
  From http://doc.perl6.org/routine/substr I don't see any way to do a 
  replacement. What is the idiomatic way of doing a positional string 
  replacement in Perl 6? Thanks!
 
 Method form:
 $ perl6 -e 'my $s = abc; $s.substr-rw(1,1) = z; say $s;'
 azc
 
 Function form:
 $ perl6 -e 'my $s = abc; substr-rw($s, 1,1) = z; say $s;'
 azc
 
 I also do not see substr-rw in doc.perl6.org.
 It needs to be added.
 In the meantime, you can find it here:
   http://design.perl6.org/S32/Str.html

thanks, Bruce, for the examples!  I've added these to the doc.perl6.org
documentation.  The entry for substr-rw should appear in roughly half an
hour.

Cheers,

Paul


Re: How to do a substring replacement in Perl 6

2015-06-08 Thread Paul Cochrane
Hi Douglas,

 From http://perldoc.perl.org/functions/substr.html:
 
 substr has a 4th argument (or you can use substr as an lvalue) for
 replacement.
 substr EXPR,OFFSET,LENGTH,REPLACEMENT
 
 From http://doc.perl6.org/routine/substr I don't see any way to do a
 replacement. What is the idiomatic way of doing a positional string
 replacement in Perl 6? Thanks!

I believe `substr-rw` is what you're looking for:


$ perl6
 my $s = The black cat climbed the green tree;
The black cat climbed the green tree
 my $z = substr-rw($s, 14, 7) = jumped from;
jumped
 $s.say
The black cat jumped from the green tree


As far as I know, not all of its behaviour has been implemented yet (FWIW it
looks like it shouldn't have returned jumped above; my guess is that it
should have been climbed.  Nevertheless, it seems to do that which you're
looking for.

Hope that helps!

Cheers,

Paul


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

2015-05-30 Thread Paul Cochrane
On 30 May 2015 3:00:25 pm GMT+02:00, Tom Browder tom.brow...@gmail.com wrote:
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

Hi Tom,

I believe what you are looking for is called $*PROGRAM_NAME. See also 
http://doc.perl6.org/language/variables#Special_Variables

Cheers,

Paul

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

2015-05-30 Thread Paul Cochrane
Hi Tom,

On Sat, May 30, 2015 at 09:03:17AM -0500, Tom Browder 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:
 
   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

the docs at tablets.perl6.org aren't as up to date as those on
doc.perl6.org.  The doc.perl6.org docs are currently the reference work for
Perl6, however please note that they are very much a work in progress.

 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.

This I can understand.  We're doing our best to provide current and
accurate documentation.  Perl6 is a very large language, and thus gaps in
the documentation are to be expected; especially considering the volunteer
based nature of the project.

Thanks for pointing out the $*PROGRAM omission!  I've just added it to the
list of special variables and it should be available online within the next
10-15 minutes.

Kind regards,

Paul


Re: Is there an equivalent env var to PERL5LIB for Perl 6 module locations?

2015-03-31 Thread Paul Cochrane
On Tue, Mar 31, 2015 at 05:40:44AM -0500, Tom Browder wrote:
 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?

http://doc.perl6.org/language/5to6#Environment_variables

to be honest I cheated and have written the docs just today.  :-)

A `git grep LIB` in the spec sources turned up the text on environment
variables in S19, so that'd be one place to check as well.  In general, if a
search like that doesn't seem to turn up much, a `git grep` in the Rakudo
sources also turns up quite a bit of info.

Cheers,

Paul


Re: Example module and its use

2015-03-28 Thread Paul Cochrane
Hi Tom,

   use Bar :DEFAULT;
 
 but this does not:
 
   use Bar foo;
 
 So is S11 in error!!

That might not necessarily be the case (however S11 certainly isn't clear
about exactly how to import selected routines while `use`-ing a module).
All subs/methods that are marked with `is export` are exported by default,
thus there's actually no need to import anything, hence:

use Bar;

will ensure that the foo() routine is available within the scope of the
`doit.pl` script.

From what I can gather from S11, is that if one wants to override the
default behaviour of importing into the current namespace everything which
is exported by the module, then an EXPORT sub needs to be defined.  AFAICT
this is what the error:

no EXPORT sub, but you provided positional argument in the 'use' statement

is trying to tell you.

Nevertheless, I've not been able to work out how to create an EXPORT sub
which does the Right Thing(TM).  Reading 'Perl6/Grammar.nqp' in the Rakudo
sources shows that a sub by the name of `EXPORT` is expected which returns
an `EnumMap`, which I suspect contains the names of the subs/methods to be
exported.  I'm fairly sure this is getting much too low-level for the
current use-case.  Also, sharing this information might simply be muddying
the waters somewhat, so in order that you can get further with what you're
trying to do, your example will work with the following code:

== Bar.pm ==
module Bar;

use v6;

sub foo($a, $b, $c) is export {}

# vim: expandtab shiftwidth=4 ft=perl6


= doit.pl ==
use v6;

use lib .;
use Bar;
my @t = foo(1, 2, 3);

# vim: expandtab shiftwidth=4 ft=perl6


BTW: please don't use the shortcut 'v6;': AFAIU it's been deprecated in
favour of 'use v6;'

Hope this helps a bit.

Cheers,

Paul


Re: Trig Functions to-radians and from-radians

2015-03-17 Thread Paul Cochrane
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.

Hope that helps,

Paul