Re: trouble returning a value from sub

2022-06-17 Thread Simon Proctor
Here's my new go to prime-factors function :

sub prime-factors( Int $n is copy where * > 1 ) {
gather {
while ( $n > 1 ) {
if ( $n.is-prime ) {
take $n;
last;
}
my $f = (2..^$n/2).grep($n %% *).first(*.is-prime);
take $f;
$n = $n div $f
}
}
}

On Fri, 17 Jun 2022 at 03:51, Simon Proctor  wrote:

> This is because if there isn't an explicit return the last statement
> evaluated is the implied return value.
>
> So the last call (which returns Nil) was your implicit return.
>
> Generally I try and avoid an implicit return if a function has more than a
> couple of lines.
>
> On Thu, 16 Jun 2022, 21:41 Rick Bychowski,  wrote:
>
>> For example here:
>>
>>
>> https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-168/rick-bychowski/raku/ch-2.raku
>>
>> I called the recursive function at various points in an if/else
>> statement, but each call was always the very last statement of the
>> branch/routine. Otherwise, even a trailing "last" or "exit" silently
>> "fails".
>>
>> All good!
>>
>> - Rick
>>
>> On 6/16/22 13:21, Rick Bychowski wrote:
>> > Yep, the "return factors($q, @f)" fixes it. I've not called a recursion
>> > from anywhere other than the end of a routine, so haven't run into this
>> > issue before. Learned something today!
>> >
>> > Thanks to Simon, William and Andinus for your assistance!
>> >
>> > - Rick
>> >
>> > On 6/16/22 11:07, Simon Proctor wrote:
>> >> I think, and I don't have my computer to hand to double check but I
>> >> think you want a return before your recursive.call to factors passing
>> >> in @f.
>> >>
>> >> When dealing with recursive functions you need to make sure what
>> >> you're returning back up the stack.
>> >>
>> >>
>> >>
>> >> On Thu, 16 Jun 2022, 18:10 Rick Bychowski, > >> <mailto:r...@hiranyaloka.com>> wrote:
>> >>
>> >> Hi Everyone,
>> >>
>> >> I've been lurking quite a while, this will be my first post to
>> perl6
>> >> users. I've written a lot of short scripts in perl5 for system
>> admin
>> >> type stuff at home and work. Lately I'm playing with Raku, which
>> is a
>> >> lot of fun. Error reporting is excellent, as is the online
>> >> documentation.
>> >>
>> >> To the point. I recently started the perl weekly challenge. Lots of
>> >> math/primes stuff. I wrote an algorithm to list all the prime
>> >> factors of
>> >> an integer, using a recursive subroutine. I'm able to print the
>> >> result
>> >> from the subroutine, but it always returns Nil. What am I missing?
>> >>
>> >> #!/usr/bin/env raku
>> >>
>> >> sub MAIN($n = 20) {
>> >>  .say for factors($n); # Nil
>> >> }
>> >>
>> >> sub factors($n, @factors?) {
>> >>   my @f = @factors.elems ?? @factors !! ();
>> >>   my $q;
>> >>   for 2 ..^ $n -> $i {
>> >>   if $n %% $i {
>> >>   $q = Int($n / $i);
>> >>   @f.push($i);
>> >>   if $q.is-prime {
>> >>   @f.push($q);
>> >>   say @f;    # [2 2 5]
>> >>   return @f;
>> >>   } else {
>> >>   factors($q, @f);
>> >>   }
>> >>   last;
>> >>   }
>> >>   }
>> >> }
>> >>
>> >> Returns
>> >> [2 2 5]
>> >> Nil
>> >>
>> >> -- Rick Bychowski
>> >>
>> >> The information in this email is confidential and may be legally
>> >> privileged. It is intended solely for the addressee(s). Access to
>> >> this
>> >> e-mail by anyone else is unauthorized.
>> >>
>> >
>>
>> --
>> Rick Bychowski
>>
>> The information in this email is confidential and may be legally
>> privileged. It is intended solely for the addressee(s). Access to this
>> e-mail by anyone else is unauthorized.
>>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: trouble returning a value from sub

2022-06-16 Thread Simon Proctor
This is because if there isn't an explicit return the last statement
evaluated is the implied return value.

So the last call (which returns Nil) was your implicit return.

Generally I try and avoid an implicit return if a function has more than a
couple of lines.

On Thu, 16 Jun 2022, 21:41 Rick Bychowski,  wrote:

> For example here:
>
>
> https://github.com/manwar/perlweeklychallenge-club/blob/master/challenge-168/rick-bychowski/raku/ch-2.raku
>
> I called the recursive function at various points in an if/else
> statement, but each call was always the very last statement of the
> branch/routine. Otherwise, even a trailing "last" or "exit" silently
> "fails".
>
> All good!
>
> - Rick
>
> On 6/16/22 13:21, Rick Bychowski wrote:
> > Yep, the "return factors($q, @f)" fixes it. I've not called a recursion
> > from anywhere other than the end of a routine, so haven't run into this
> > issue before. Learned something today!
> >
> > Thanks to Simon, William and Andinus for your assistance!
> >
> > - Rick
> >
> > On 6/16/22 11:07, Simon Proctor wrote:
> >> I think, and I don't have my computer to hand to double check but I
> >> think you want a return before your recursive.call to factors passing
> >> in @f.
> >>
> >> When dealing with recursive functions you need to make sure what
> >> you're returning back up the stack.
> >>
> >>
> >>
> >> On Thu, 16 Jun 2022, 18:10 Rick Bychowski,  >> <mailto:r...@hiranyaloka.com>> wrote:
> >>
> >> Hi Everyone,
> >>
> >> I've been lurking quite a while, this will be my first post to perl6
> >> users. I've written a lot of short scripts in perl5 for system admin
> >> type stuff at home and work. Lately I'm playing with Raku, which is
> a
> >> lot of fun. Error reporting is excellent, as is the online
> >> documentation.
> >>
> >> To the point. I recently started the perl weekly challenge. Lots of
> >> math/primes stuff. I wrote an algorithm to list all the prime
> >> factors of
> >> an integer, using a recursive subroutine. I'm able to print the
> >> result
> >> from the subroutine, but it always returns Nil. What am I missing?
> >>
> >> #!/usr/bin/env raku
> >>
> >> sub MAIN($n = 20) {
> >>  .say for factors($n); # Nil
> >> }
> >>
> >> sub factors($n, @factors?) {
> >>   my @f = @factors.elems ?? @factors !! ();
> >>   my $q;
> >>   for 2 ..^ $n -> $i {
> >>   if $n %% $i {
> >>   $q = Int($n / $i);
> >>   @f.push($i);
> >>   if $q.is-prime {
> >>   @f.push($q);
> >>   say @f;# [2 2 5]
> >>   return @f;
> >>   } else {
> >>   factors($q, @f);
> >>   }
> >>   last;
> >>   }
> >>   }
> >> }
> >>
> >> Returns
> >> [2 2 5]
> >> Nil
> >>
> >> -- Rick Bychowski
> >>
> >> The information in this email is confidential and may be legally
> >> privileged. It is intended solely for the addressee(s). Access to
> >> this
> >> e-mail by anyone else is unauthorized.
> >>
> >
>
> --
> Rick Bychowski
>
> The information in this email is confidential and may be legally
> privileged. It is intended solely for the addressee(s). Access to this
> e-mail by anyone else is unauthorized.
>


Re: trouble returning a value from sub

2022-06-16 Thread Simon Proctor
I think, and I don't have my computer to hand to double check but I think
you want a return before your recursive.call to factors passing in @f.

When dealing with recursive functions you need to make sure what you're
returning back up the stack.



On Thu, 16 Jun 2022, 18:10 Rick Bychowski,  wrote:

> Hi Everyone,
>
> I've been lurking quite a while, this will be my first post to perl6
> users. I've written a lot of short scripts in perl5 for system admin
> type stuff at home and work. Lately I'm playing with Raku, which is a
> lot of fun. Error reporting is excellent, as is the online documentation.
>
> To the point. I recently started the perl weekly challenge. Lots of
> math/primes stuff. I wrote an algorithm to list all the prime factors of
> an integer, using a recursive subroutine. I'm able to print the result
> from the subroutine, but it always returns Nil. What am I missing?
>
> #!/usr/bin/env raku
>
> sub MAIN($n = 20) {
> .say for factors($n); # Nil
> }
>
> sub factors($n, @factors?) {
>  my @f = @factors.elems ?? @factors !! ();
>  my $q;
>  for 2 ..^ $n -> $i {
>  if $n %% $i {
>  $q = Int($n / $i);
>  @f.push($i);
>  if $q.is-prime {
>  @f.push($q);
>  say @f;# [2 2 5]
>  return @f;
>  } else {
>  factors($q, @f);
>  }
>  last;
>  }
>  }
> }
>
> Returns
> [2 2 5]
> Nil
>
> --
> Rick Bychowski
>
> The information in this email is confidential and may be legally
> privileged. It is intended solely for the addressee(s). Access to this
> e-mail by anyone else is unauthorized.
>


Re: Easier way to load a buffer?

2022-06-10 Thread Simon Proctor
So Buf is expecting a list of integers. If' you've got one long one in a
string like "2A54FF53A5F1D36F1CEA7E61FC37A20D54A77FE7B78" you want to split
it into smaller values so something like this?

my $hex = "2A54FF53A5F1D36F1CEA7E61FC37A20D54A77FE7B78";
my Buf $b=Buf.new(comb(2).map( *.parse-base(16) ));

Which does the trick I think.

On Fri, 10 Jun 2022 at 15:49, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> I am looking for an easier way to load a buffer.
>
> I know about this way
>
> [4] > my Buf $b=Buf.new(0x2A, 0x54, 0xFF, 0x53);
> Buf:0x<2A 54 FF 53>
>
> I would like to do it on one big blast:
>
> my Buf $b=Buf.new(0x2A54FF53A5F1D36F1CEA7E61FC37A20D54A77FE7B78);
> Cannot unbox 170 bit wide bigint into native integer
>
> But do not know the proper syntax.
>
> Any words of wisdom?  Am I stuck with the hard way?
>
> Many thanks,
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Removing ' characters

2022-01-10 Thread Simon Proctor
Within the regex the ' character is just another string so rather than
escaping it you can write the regex as :

$s.subst( / "'" ~ "'" (.+) /, $0)

(That's " ' " (without spaces) to be exact.) And it does the trick.

You can do the same when defining it $s = "''"; or $s =
q['']; both work.


On Mon, 10 Jan 2022 at 16:12, Richard Hainsworth 
wrote:

> Aha. Thanks
>
> On 10/01/2022 15:59, Gianni Ceccarelli wrote:
> > On Mon, 10 Jan 2022 15:41:04 +
> > Richard Hainsworth  wrote:
> >
> >> Using REPL I got
> >>
> >>   > my $s = '\'\''
> >> ''
> >>   > $s.subst( / \' ~ \' (.+) /, $0)
> >> Use of Nil in string context
> >> in block  at  line 1
> > That error message (which is a bit LTA) refers to the `$0`. As
> > https://docs.raku.org/routine/subst#Callable shows, you need to write:
> >
> >  $s.subst( / \' ~ \' (.+) /, { $0 })
> >
> >>   > my $t = '{}'
> >> {}
> >>   > $t.subst( / \{ ~ \} (.+) /, $0)
> >> 
> > This only appear to work because you're running it in the same REPL
> > session; the previous `subst` had the side-effect of setting `$0`
> > (well, it sets `$/`, but `$0` is an alias for `$/[0]`…)
> >
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Grammar Help

2021-12-26 Thread Simon Proctor
Still waking up but I think the issue is your pairlist has a semi colon
divider but this should be after each pair.

So the trailing semi colon after b is causing it to fail.

On Sun, 26 Dec 2021, 06:01 Paul Procacci,  wrote:

> Hey all,
>
> Twas the night of Christmas, when all through the house, not a creature
> was stirring except Paul w/ his mouse.
>
> Hope everyone had a Merry Christmas and takes likings to corny opening
> statements.  ;)
>
> I was writing a little something tonight using Grammars and ran into
> something that I can't seem to wrap my head around.  I'm hoping someone
> could explain in detail.
>
> Given the following data:
>  data -
> objectKey:
> {
> a = "bi";
> b = "hi";
> }
>  end data -
>
>
>  and the following logic partially taken from JSON::Tiny:
>
>  code 
> grammar myTest {
> token TOP{ \s*  \s* }
> rule  object {  '{'  '}' }
> # rule  object {  '{' ~ '}'  }
> rule  objectKey  {  ':' }
> rule  pairlist   {  * % \; }
> rule  pair   {  '='  }
> token cstr   { + }
> token value  { '"' ~ '"' * }
> }
>
> class myTestActions {
> method TOP($/) {
> make $.made.hash.item;
> }
>
> method object($/) {
> say 'hello';
> }
>
> method objectKey($/) {
> make $.made;
> }l
> method pairlist($/) {
> make $>>.made.flat;
> }
>
> method pair($/) {
> make $.made => $.made;
> }
>
> method cstr($/)  { make ~$/ }
> method value($/) { make ~$/ }
> }
>  code 
>
>
> ... it'd be my hopes that this would match.  However, It's not matching on
> 'object' and I can't seem to figure out why.
>
> Adding Grammar::Tracer yields the following:
>
> TOP
> |  object
> |  |  objectKey
> |  |  |  cstr
> |  |  |  * MATCH "objectKey"
> |  |  * MATCH "objectKey:\n"
> |  |  pairlist
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * MATCH "a"
> |  |  |  |  value
> |  |  |  |  * MATCH "\"bi\""
> |  |  |  * MATCH "a = \"bi\""
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * MATCH "b"
> |  |  |  |  value
> |  |  |  |  * MATCH "\"hi\""
> |  |  |  * MATCH "b = \"hi\""
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * FAIL
> |  |  |  * FAIL
> |  |  * MATCH "a = \"bi\";\n\tb = \"hi\""
> |  * FAIL
> * FAIL
>
> What exactly am I doing wrong?  Does '{' ~ '}' not work as I expect here?
> Appreciate any insight.
>
> Thanks,
> Paul
> --
> __
>
> :(){ :|:& };:
>


Re: hope we have the distributed computing perl6

2021-11-28 Thread Simon Proctor
I've been watching this for a bit and was thinking that a combination of a
message bus (Rabbit MQ?) and Cro should provide most of what you'd need for
a backbone.

The fact that Raku has Supplies and Channels built in means it feels like a
problem that's easy enough to fix.

This is probably me coming from a position of not knowing rarely enough
about the problem space though.

On Mon, 29 Nov 2021 at 06:35, Piper H  wrote:

> William, I didn't use SparkR. I use R primarily for plotting.
>
> Spark's basic API is quite simple, it does the distributed computing of
> map, filter, group, reduce etc, which are all covered by perl's map, sort,
> grep functions IMO.
>
> for instance, this common statistics on Spark:
>
> >>> fruit.take(5)
> [('peach', 1), ('apricot', 2), ('apple', 3), ('haw', 1), ('persimmon', 9)]
> >>>
> >>>
> >>> fruit.filter(lambda x:x[0] == 'apple').reduceByKey(lambda
> x,y:x+y).collect()
> [('apple', 86)]
>
> Which is easily implemented by perl's grep and map functions.
> But we need a distributed computing framework of perl6.
>
> Yes there is already the perl-spark project:
> https://github.com/perl-spark/Spark
> Which didn't get updated for many years. I don't think it's still in
> active development.
>
> So I asked the original question.
>
> Thank you.
> Piper
>
>
> On Mon, Nov 29, 2021 at 1:44 PM William Michels 
> wrote:
>
>> Hi Piper!
>>
>> Have you used SparkR (R on Spark)?
>>
>> https://spark.apache.org/docs/latest/sparkr.html
>>
>> I'm encouraged by the data-type mapping between R and Spark. It
>> suggests to me that with a reasonable Spark API, mapping data types
>> between Raku and Spark should be straightforward:
>>
>>
>> https://spark.apache.org/docs/latest/sparkr.html#data-type-mapping-between-r-and-spark
>>
>> Best Regards,
>>
>> Bill.
>>
>>
>> On Sat, Nov 27, 2021 at 12:16 AM Piper H  wrote:
>> >
>> > I use perl5 everyday for data statistics.
>> > The scripts are running on a single server for the computing tasks.
>> > I also use R, which has the similar usage.
>> > When we face very large data, we change to Apache Spark for distributed
>> computing.
>> > Spark's interface languages (python, scala, even ruby) are not
>> flexible, but their computing capability is amazing, due to the whole
>> cluster contributing the computing powers.
>> > Yes I know perl5 is somewhat old, but in perl6 why won't we make that a
>> distributed computing framework like Spark? Then it will help a lot to the
>> data programmer who already knows perl.
>> > I expect a lot from this project.
>> >
>> > Thanks.
>> > Piper
>>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: What're native (i.e. high-machine-performance) hybrid development options with Raku?

2021-09-29 Thread Simon Proctor
I'm sure there are people who will be able to give some more information
than me but I will say you can do worse than reading the documentation on
NativeCall.

https://docs.raku.org/language/nativecall

I've played about with it a bit and it really is quite simple to get
started with. Generally you can directly map to a C/C++ call and then wrap
that in a nicer interface if you want to.

Some example modules already using it:

https://raku.land/cpan:MARTIMM/Gnome::Gtk3
https://raku.land/cpan:TIMOTIMO/SDL2::Raw
https://raku.land/github:JJ/SDL2
https://raku.land/github:hartenfels/Text::Markdown::Discount

(There's a bunch more too).

Good luck :)



On Wed, 29 Sept 2021 at 08:49, YueCompl via perl6-users <
perl6-users@perl.org> wrote:

> Also asked at
> https://www.reddit.com/r/rakulang/comments/pxqaxi/whats_native_ie_highmachineperformance_hybrid
>
>
> Greetings!
>
> u/raiph is really a great evangelist, months ago, he swept away my (wrong)
> assumption that Raku must be mostly old school PERL, and keep impressing me
> with fantasies already done by Raku. Recently being [compiler in minutes](
> https://www.youtube.com/watch?v=rxaB6m_sQKk).
>
> I'm considering seriously the realworld adoption of Raku in my work, so
> I'd like to ask this.
>
> My current (private) framework facilitates the writing of high performance
> tensor components in C++, those get assembled to computation networks with
> Python scripting at runtime, then run mostly in C++ code but occasionally
> call back to script code. There had been even older workflows with Boost,
> but I started with Pybind11 a few years ago, with the approach pretty much
> described in [this SO answer](https://stackoverflow.com/a/50125447/6394508
> ).
>
> As our business develops, more and more expressiveness is demanded, Python
> magic methods way of language tweaking becomes a limiting factor gradually.
> We are currently using a custom scripting language I implemented fresh new,
> atop Haskell/GHC, with script-assemblable high-machine-performance
> components writable in the `IO` and `STM` monad. I share many of Raku's
> design ideas in implementing that PL, but failed to discover that before
> u/raiph caught my attention to Raku.
>
> Apparently Raku is more mature and feature rich than my current piece,
> especially in syntax customization, that we demand heavily.
>
> But I'm not clear by far, what's the approach for Raku code with native
> parts get developed with good ergonomics?
>
> The native parts is not expected to be C/C++, but some PL with moderate
> raw machine performance, and ergonomics is very important, so manual memory
> management is a deal breaker for us. For example, Go's machine performance
> is acceptable by us, but Rust is not due to memory management burden (even
> though much more principled than C).
>
> The scripting part cries for flexibility and clean-ness in
> syntax/semantics, toward purity of business concerns, ideally no computer
> implementation concerns should surface to the scripting grammar, machine
> performance in scripting is not sensitive at all, since it is just to build
> one variant of the business program, the "real" run of the program should
> mostly consist of compiled native code. Though calling script parts back,
> meanwhile the high-performance run, is also desirable in a small number of
> scenarios.
>
> That said but Julia's approach - LLVM based JIT from scripting, is not
> affordable by us, we have no expertise in machine code generation, even the
> simpler IR manipulation.
>
> Also debuggability in the native code part is crucial, C++ served us well
> in this regard, VSCode etc. can attach to a Python process and set
> breakpoints on the C++ code, then step through the suspicious code path.
>
> Haskell is far from on par w.r.t. stepping debuggers, but bugs are
> interestingly less with it, for unutterable reasons.
>
> Best regards,
> Compl
>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Accurate conversion of Num to Rat (and comparing Num and Rat)

2021-04-07 Thread Simon Proctor
Would =~= be what you're looking for?

Personally I like Rationals and am looking forward to being able to signify
that they should automatically become FatRats.

But if you're wedded to floating point then :

say 3602879701896397/36028797018963968 =~= 0.1 => True

say 3602879701896397/36028797018963968 =~= 0.1e0 => True

(As you're dealing in approximations).

On Wed, 7 Apr 2021 at 15:01, sisyphus  wrote:

>
> On Wed, Apr 7, 2021 at 11:31 PM Vadim Belman  wrote:
>
>>
>> For exact match one can use eqv:
>>
>> say 1/10 eqv 0.1e0; # False
>> say 1/10*1e0 eqv 0.1e0; # True
>>
>
> I don't think this is quite what I'm after.
> I would want the following to be True, but it's False:
> C:\> raku -e "say 3602879701896397/36028797018963968 eqv 0.1e0"
> False
>
> And doing:
> C:\>raku -e "say 3602879701896397/36028797018963968*1e0 eqv 0.1e0"
> True
>
> C:\>raku -e "say 1/10*1e0 eqv 0.1e0"
> True
>
> seems to be essentially the same as doing:
> C:\_32>raku -e "say 3602879701896397/36028797018963968 == 0.1e0"
> True
>
> C:\_32>raku -e "say 1/10 == 0.1e0"
> True
>
> Cheers,
> Rob
>
>
>
>
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: I need help with sub MAIN

2020-05-05 Thread Simon Proctor
I would suggest starting by reading this page in the docs :
https://docs.raku.org/language/create-cli

Covers how $*USAGE is created and the various options you have for
providing help data.

On Tue, 5 May 2020, 06:46 ToddAndMargo via perl6-users, <
perl6-users@perl.org> wrote:

> Hi All,
>
> Just to prove I read the stinker:
> https://docs.raku.org/routine/MAIN
>
> I am trying to get the following to do
>
> #!/usr/bin/env perl6
> sub MAIN(:$these ="These", :$are="Are") { say "$these $are"; }
>
> This is working:
>
> $ MainTest.pl6 --are=our --these=those
> those our
>
>
> These two are not:
>
> 1) I am trying to get MAIN to give me an error I can
> call my help sub if a stray entry is placed in
> the run line
>
> $ MainTest.pl6 --are=our --these=those --saywhat=abc
> Usage:
>MainTest.pl6 [--these=] [--are=]
>
> Here it find `--saywhat=abc` and MAIN writes out the above
> usage statement.
>
> A) I want to write it out myself.  I would like the
>string too, but don't have to have it.
>
> B) I would like the stray entry.
>
>
> 2) Here I want to pick up the remainder (abc) at the end,
> but can't figure out the syntax in the sub declaration.
>
> Something like:
>   dnf --excluderepo=acb* install raku
>
> $ MainTest.pl6 --are=our --these=those abc
> Usage:
>MainTest.pl6 [--these=] [--are=]
>
> Instead of MAIN writing out usage.
>
> Many thanks,
> -T
>


Re: How to read a particular environmental variable?

2020-04-08 Thread Simon Proctor
Well he is me so let my try and explain.

The idea is to be able to simply assign Env vars to variables so for
example you might do

use Trait::Env;
my $windir is env;

And then $windir should be assigned the value of the %*ENV variable
at runtime.

There's a bunch of other stuff in it too, it's mostly intended to make
Docker environment setup easy to use but should be useful in other areas.

How could I make the documentation easier to understand?

On Wed, 8 Apr 2020 at 09:22, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Wed, 8 Apr 2020, 03:25 ToddAndMargo via perl6-users,
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> On 2020-04-07 18:25, Brad Gilbert wrote:
> >>  > Of course %*ENV is case sensitive, hashes are case sensitive.
> >>  >
> >>  >  say %*ENV.^name; # Hash
> >>  >
> >>  > %*ENV gets populated with the values before your code runs.
> >>  > Other than that it is fairly ordinary.
> >>
> >> My purpose for the case sensitive remark was that
> >> environmental variables are not case sensitive in
> >> Windows.  And I do not know how Raku interacts with
> >> them.
> >>
> >>   >echo %WINDIR%
> >> C:\WINDOWS
> >>
> >>   >echo %windir%
> >> C:\WINDOWS
> >>
> >>   >echo %WinDir%
> >> C:\WINDOWS
>
> On 2020-04-07 23:56, Simon Proctor wrote:
> > You might want to take a look at Trait::Env, partly because I've not
> > tested it in Windows and I'd be interested to know if it works well.
>
> https://modules.raku.org/dist/Trait::Env:cpan:SCIMON
>
> Not sure what he is trying to do.  :-(
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: How to read a particular environmental variable?

2020-04-08 Thread Simon Proctor
You might want to take a look at Trait::Env, partly because I've not tested
it in Windows and I'd be interested to know if it works well.


On Wed, 8 Apr 2020, 03:25 ToddAndMargo via perl6-users, <
perl6-users@perl.org> wrote:

> On 2020-04-07 18:25, Brad Gilbert wrote:
> > Of course %*ENV is case sensitive, hashes are case sensitive.
> >
> >  say %*ENV.^name; # Hash
> >
> > %*ENV gets populated with the values before your code runs.
> > Other than that it is fairly ordinary.
>
> My purpose for the case sensitive remark was that
> environmental variables are not case sensitive in
> Windows.  And I do not know how Raku interacts with
> them.
>
>  >echo %WINDIR%
> C:\WINDOWS
>
>  >echo %windir%
> C:\WINDOWS
>
>  >echo %WinDir%
> C:\WINDOWS
>


Re: Dropbox and IO?

2020-04-07 Thread Simon Proctor
Ok I don't have access to my windows box until this evening. I'm mostly
used to using Dropbox on a Linux box where it's just a folder.

Sorry for my mistake.

On Tue, 7 Apr 2020 at 07:51, Shlomi Fish  wrote:

> Hi Simon,
>
> On Tue, 7 Apr 2020 06:55:00 +0100
> Simon Proctor  wrote:
>
> > Don't see why not, Dropbox is just a folder that you should be able to
> > access as normal.
> >
>
> Is it a higher-level folder or a bona-fide filesystem direcory:
>
> https://en.wikipedia.org/wiki/Directory_(computing)#Folder_metaphor
>
> If it is not visible to the filesystem, one may need higher level APIs
> other
> than fopen ( https://en.cppreference.com/w/c/io/fopen ) and friends.
>
> > On Tue, 7 Apr 2020, 02:22 ToddAndMargo via perl6-users, <
> > perl6-users@perl.org> wrote:
> >
> > > Hi All,
> > >
> > > Do any of you using Windows and Dropbox know
> > > if Raku's file IO utilities can both read
> > > and write to a Drop Box drive?
> > >
> > > Many thanks,
> > > -T
> > >
>
>
>
> --
>
> Shlomi Fish   https://www.shlomifish.org/
> https://www.shlomifish.org/open-source/resources/tech-tips/
>
> How many “one-liners” do I actually write? I don’t know; maybe a couple
> dozen
> a day. But I guess I must be unusual, because as we all know, AWK was a
> complete failure and vanished into obscurity since it didn’t address
> anyone’s
> real needs. (That was sarcasm.) — “Twelve Views of Mark Jason Dominus”
>
> Please reply to list if it's a mailing list post - https://shlom.in/reply
> .
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Dropbox and IO?

2020-04-06 Thread Simon Proctor
Don't see why not, Dropbox is just a folder that you should be able to
access as normal.

On Tue, 7 Apr 2020, 02:22 ToddAndMargo via perl6-users, <
perl6-users@perl.org> wrote:

> Hi All,
>
> Do any of you using Windows and Dropbox know
> if Raku's file IO utilities can both read
> and write to a Drop Box drive?
>
> Many thanks,
> -T
>


Re: variable as subroutine?

2020-02-11 Thread Simon Proctor
The * * * call generates a WhateverCode block. This is expecting 2
arguments.

-> $x { $x * $x } is taking one argument.

The best documentation would probably be :
https://docs.raku.org/type/Whatever

Hope that helps.

(For giggles earlier I made this dumb example of functional programming)


my  = {$_};
my  = {$_ * $_};
sub trinar( , , , *@values ) { @values.map( -> $v {
($v) ?? ($v) !! ($v) } ) };
trinar( *.is-prime, ,, ^30 ).say

Enjoy. ;)

On Tue, 11 Feb 2020 at 15:22, Andy Bach  wrote:

> I have a few less related questions
> >> those are 3 ways to write the same sub:
>
> sub foo ($x) { $x * $x }
> my  = -> $x { $x * $x }
> my  = * * *;
>
> > A Note on Marc's comment:
> my  = * * *
> is not the same as:
> my  = -> $x { $x * $x }
> it is the same  as:
> my  = -> $x, $y { $x * $y }
>
> Okay, "* * *" - how does that work?  How is it different than
> -> $x { $x * $x }
> ?  It needs two params?
>
> I followed the callable link but that left me with more questions:
>
> method CALL-ME
> method CALL-ME(Callable:D $self: |arguments)
> This method is required for postfix:«( )» and postfix:«.( )». It's what
> makes an object actually call-able and needs to be overloaded to let a
> given object act like a routine. If the object needs to be stored in a
> &-sigiled container, is has to implement Callable.
>
> class A does Callable {
> submethod CALL-ME(|c){ 'called' }
> }
> my  = A;
> say a(); # OUTPUT: «called␤»
>
> That second "postfix" operator, means
> say a.();  # also outputs "called"
>
> but what is the "pipe c" signature doing for the submethod?
> --
> *From:* Simon Proctor 
> *Sent:* Tuesday, February 11, 2020 3:17 AM
> *To:* ToddAndMargo 
> *Cc:* perl6-users 
> *Subject:* Re: variable as subroutine?
>
> If you can store a subroutine in a variable then you can pass said
> subroutine to another one as an argument.
>
> This leads us into the joys of functional programming.
>
> And you may have used it already and not even realised.
>
> The .map and .grep methods (and .reduce and bunch of others) all expect a
> callable code block (that might be a subroutine) as a function.
>
> This :
>
> my @a = (1..10).map( * ** 2 )
>
> and this :
>
> my  = sub ($v) { $v ** 2 };
> my @a = (1..10).map(  );
>
> are doing the same thing. Except the second one has the  function
> available for other things.
>
> (A Note on Marc's comment * * * is not the same as -> $x { $x * $x } it is
> the same  as -> $x, $y { $x * $y } )
>
> You can then start doing things like storing functions as values in hashes
> and doing all *kinds* of fun stuff.
>
> Welcome to the tip of the iceberg.
>
> Simon
>
>
> On Tue, 11 Feb 2020 at 03:21, ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
> Hi All,
>
> Is Larry using his magic powder again?
>
> Can I declare a subroutine as a variable?
>
>  my $abc = my sub (UInt $u, Str $s, Int $I) {
>
> How would I use it?
>
> And why would do such a thing?
>
> -T
>
>
>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Question about Blob and Buf

2020-02-11 Thread Simon Proctor
Ok I 100% don't know after trying this out :

my Buf $a = Buf.new(1,2,3);
my Blob $b = Blob.new(4,5,6);
$a ~= $b;
say $a

And it worked fine so... I dunno.


On Tue, 11 Feb 2020 at 11:00, Simon Proctor  wrote:

> I think the problem is IO::Socket.read() returns a Blob not a Buf.
>
> ~ has a Buf, Buf variant :
> https://docs.raku.org/language/operators#infix_~
>
> But not a Blob one. Buf does Blob but not vice versa.
>
> I think you need to transform the output from .read into a Buf if you want
> to use the ~= how you want to.
>
> Would this work?
> my Blob $read = Buf.new;
> $read ~= Buf.new( $socket.read(1024) );
>
>
> On Tue, 11 Feb 2020 at 10:46, Kevin Pye  wrote:
>
>>
>> ~ works fine for concatenating Bufs; For example:
>>
>> my $a = Buf.new(1,2,3);
>> my $b = $a ~ Buf.new(4,5,6)
>>
>> will assign correctly to $b.
>>
>> I can't work out what the problem is here, despite trying various
>> combinations. Perhaps socket isn't really returning a Blob?
>>
>> Kevin.
>>
>> On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:
>>
>>> You are using ~, which stringifies. Bufs are not strings: you need to
>>> decode them to concatenate it to a string. If what you want is to
>>> concatenate the buffer, probably ,= will work (not sure about this, would
>>> have to check), or any other operator that works on Positionals.
>>>
>>> JJ
>>>
>>> El mar., 11 feb. 2020 a las 10:56, David Santiago ()
>>> escribió:
>>>
>>>> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
>>>> deman...@gmail.com> escreveu:
>>>> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
>>>> deman...@gmail.com> escreveu:
>>>> >>
>>>> >>Hi!
>>>> >>
>>>> >>Can someone explain me why this doesn't work:
>>>> >>
>>>> >>my Blob $read;
>>>> >>$read ~= $socket.read(1024);
>>>> >>
>>>> >>Dies with error:
>>>> >>
>>>> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the
>>>> Stringy method on it
>>>> >>
>>>> >>This also doesn't work:
>>>> >>
>>>> >>my Buf $read;
>>>> >>$read ~= $socket.read(1024);
>>>> >>
>>>> >>Dies with the same error as above.
>>>> >>
>>>> >>
>>>> >>But this works?
>>>> >>
>>>> >>my Blob $read = Buf.new;
>>>> >>$read ~= $socket.read(1024);
>>>> >>
>>>> >>
>>>> >>Best regards,
>>>> >>David Santiago
>>>> >
>>>> >
>>>> >Hi!
>>>> >
>>>> >Can someone explain me why this doesn't work:
>>>> >
>>>> >my Blob $read;
>>>> >$read ~= $socket.read(1024);
>>>> >
>>>> >Dies with error:
>>>> >
>>>> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the
>>>> Stringy method on it
>>>> >
>>>> >This also doesn't work:
>>>> >
>>>> >my Buf $read;
>>>> >$read ~= $socket.read(1024);
>>>> >
>>>> >Dies with the same error as above.
>>>> >
>>>> >
>>>> >But this works?
>>>> >
>>>> >my Blob $read = Buf.new;
>>>> >$read ~= $socket.read(1024);
>>>> >
>>>> >
>>>> >Best regards,
>>>> >David Santiago
>>>>
>>>>
>>>> Hi!
>>>>
>>>> Can someone explain me why this doesn't work:
>>>>
>>>> my Blob $read;
>>>> $read ~= $socket.read(1024);
>>>>
>>>> Dies with error:
>>>>
>>>> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>>>> method on it
>>>>
>>>> This also doesn't work:
>>>>
>>>> my Buf $read;
>>>> $read ~= $socket.read(1024);
>>>>
>>>> Dies with the same error as above.
>>>>
>>>>
>>>> But this works?
>>>>
>>>> my Blob $read = Buf.new;
>>>> $read ~= $socket.read(1024);
>>>>
>>>>
>>>> Best regards,
>>>> David Santiago
>>>>
>>>> --
>>>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>>>>
>>>
>>>
>>> --
>>> JJ
>>>
>>
>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Question about Blob and Buf

2020-02-11 Thread Simon Proctor
I think the problem is IO::Socket.read() returns a Blob not a Buf.

~ has a Buf, Buf variant : https://docs.raku.org/language/operators#infix_~

But not a Blob one. Buf does Blob but not vice versa.

I think you need to transform the output from .read into a Buf if you want
to use the ~= how you want to.

Would this work?
my Blob $read = Buf.new;
$read ~= Buf.new( $socket.read(1024) );


On Tue, 11 Feb 2020 at 10:46, Kevin Pye  wrote:

>
> ~ works fine for concatenating Bufs; For example:
>
> my $a = Buf.new(1,2,3);
> my $b = $a ~ Buf.new(4,5,6)
>
> will assign correctly to $b.
>
> I can't work out what the problem is here, despite trying various
> combinations. Perhaps socket isn't really returning a Blob?
>
> Kevin.
>
> On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:
>
>> You are using ~, which stringifies. Bufs are not strings: you need to
>> decode them to concatenate it to a string. If what you want is to
>> concatenate the buffer, probably ,= will work (not sure about this, would
>> have to check), or any other operator that works on Positionals.
>>
>> JJ
>>
>> El mar., 11 feb. 2020 a las 10:56, David Santiago ()
>> escribió:
>>
>>> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
>>> deman...@gmail.com> escreveu:
>>> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
>>> deman...@gmail.com> escreveu:
>>> >>
>>> >>Hi!
>>> >>
>>> >>Can someone explain me why this doesn't work:
>>> >>
>>> >>my Blob $read;
>>> >>$read ~= $socket.read(1024);
>>> >>
>>> >>Dies with error:
>>> >>
>>> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the
>>> Stringy method on it
>>> >>
>>> >>This also doesn't work:
>>> >>
>>> >>my Buf $read;
>>> >>$read ~= $socket.read(1024);
>>> >>
>>> >>Dies with the same error as above.
>>> >>
>>> >>
>>> >>But this works?
>>> >>
>>> >>my Blob $read = Buf.new;
>>> >>$read ~= $socket.read(1024);
>>> >>
>>> >>
>>> >>Best regards,
>>> >>David Santiago
>>> >
>>> >
>>> >Hi!
>>> >
>>> >Can someone explain me why this doesn't work:
>>> >
>>> >my Blob $read;
>>> >$read ~= $socket.read(1024);
>>> >
>>> >Dies with error:
>>> >
>>> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>>> method on it
>>> >
>>> >This also doesn't work:
>>> >
>>> >my Buf $read;
>>> >$read ~= $socket.read(1024);
>>> >
>>> >Dies with the same error as above.
>>> >
>>> >
>>> >But this works?
>>> >
>>> >my Blob $read = Buf.new;
>>> >$read ~= $socket.read(1024);
>>> >
>>> >
>>> >Best regards,
>>> >David Santiago
>>>
>>>
>>> Hi!
>>>
>>> Can someone explain me why this doesn't work:
>>>
>>> my Blob $read;
>>> $read ~= $socket.read(1024);
>>>
>>> Dies with error:
>>>
>>> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>>> method on it
>>>
>>> This also doesn't work:
>>>
>>> my Buf $read;
>>> $read ~= $socket.read(1024);
>>>
>>> Dies with the same error as above.
>>>
>>>
>>> But this works?
>>>
>>> my Blob $read = Buf.new;
>>> $read ~= $socket.read(1024);
>>>
>>>
>>> Best regards,
>>> David Santiago
>>>
>>> --
>>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>>>
>>
>>
>> --
>> JJ
>>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: variable as subroutine?

2020-02-11 Thread Simon Proctor
If you can store a subroutine in a variable then you can pass said
subroutine to another one as an argument.

This leads us into the joys of functional programming.

And you may have used it already and not even realised.

The .map and .grep methods (and .reduce and bunch of others) all expect a
callable code block (that might be a subroutine) as a function.

This :

my @a = (1..10).map( * ** 2 )

and this :

my  = sub ($v) { $v ** 2 };
my @a = (1..10).map(  );

are doing the same thing. Except the second one has the  function
available for other things.

(A Note on Marc's comment * * * is not the same as -> $x { $x * $x } it is
the same  as -> $x, $y { $x * $y } )

You can then start doing things like storing functions as values in hashes
and doing all *kinds* of fun stuff.

Welcome to the tip of the iceberg.

Simon


On Tue, 11 Feb 2020 at 03:21, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Is Larry using his magic powder again?
>
> Can I declare a subroutine as a variable?
>
>  my $abc = my sub (UInt $u, Str $s, Int $I) {
>
> How would I use it?
>
> And why would do such a thing?
>
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Range on Subsets

2020-01-28 Thread Simon Proctor
So some recent conversations covered the Range method on numeric types like
Int

So Int.Range gives the range of valid values -Inf^..^Inf which is neat.

Then I thought I'd try UInt.Range and got 0..^Inf

Ah Ha! Thinks I. I have a plan. What if I try this?

my subset OneToTen of Int where { not .defined or 1 <= $_ <= 10 };
say OneToTen.Range;

And it gives ...

-Inf^..^Inf

And now I'm a bit confused. The Docs say the UInt is just a subset
https://docs.raku.org/type/UInt

So how does it have it's own Range?

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: OT: Git Hub repositories

2020-01-04 Thread Simon Proctor
I go with one repository per module.

On Sat, 4 Jan 2020, 21:16 ToddAndMargo via perl6-users, <
perl6-users@perl.org> wrote:

> Hi All,
>
> Over in Git Hub land, would you create a repository
> for each module you place on Git?  Or like my modules,
> the all support/import each other, would you place them
> all in the same repository?  What would be the best for
> sharing with folks on this list?
>
> Many thanks,
> -T
>
> --
> ~
> When we ask for advice, we are usually looking for an accomplice.
> --  Charles Varlet de La Grange
> ~
>


Re: square root question

2019-12-15 Thread Simon Proctor
https://docs.raku.org/language/optut

This should cover it.

On Sun, 15 Dec 2019, 20:17 ToddAndMargo via perl6-users, <
perl6-users@perl.org> wrote:

> On 2019-12-15 02:56, Tobias Boege wrote:
> > On Sat, 14 Dec 2019, ToddAndMargo wrote:
> >> What am I doing wrong here?
> >>
> >>> multi prefix:<√> (Cool:D $x) { $x.sqrt }
> >> :<√>
> >>
> >>> say √2
> >> ===SORRY!===
> >> Argument to "say" seems to be malformed
> >> --> say⏏ √2
> >> Bogus postfix
> >
> > If this is inside the REPL, it's not your fault. It's a known issue:
> > https://github.com/rakudo/rakudo/issues/2245
> >
> > Regards,
> > Tobias
> >
>
> Hi Tobias,
>
> Well now, its really not me?  That is an odd feeling.
>
> For my keeper on the subject, I searched the documentation
> for "prefix:" and found a gazillion entries.  A lot of
> how use it other things with it, but nothing specifically
> for "prefix:".   Do you know if one exists?
>
> Many thanks,
> -T
>


Re: Cannot invoke this object (REPR: Null; VMNull)

2019-12-14 Thread Simon Proctor
I saw this issue when I was building Trait::Env, the closest I got to
figuring it out was closure's in phasers in modules seem to get lost in the
compilation process.

But I never figured out a solution I'm afraid.

On Sat, 14 Dec 2019, 22:35 Paul Procacci,  wrote:

> Ladies/Gents,
>
> I'm perplexed by the error message as stated in the subject.
> It's quite possible I'm doing it wrong.
> What I'm attempting to do is create an attribute of a class that is a Map
> ... who's value is known at compile time; hence the CHECK phaser.
>
> To produce the error it requires two source files, as merging the class
> and the code that invokes the class doesn't occur in an error:
>
> # File lib/A.pm6
> 
> class A {
>
> has Map $!pre-compiled = CHECK {
> Map.new: dir("data", test => { $_ eq none('.', '..') and
> "data/$_".IO.d })>>.map({
> .basename => .dir>>.map({
> .basename => .dir>>.basename.Set
> })
> })
> };
>
> method test {
> $!pre-compiled.perl.say;
> }
> }
>
>
> # File: test.pl6
> ---
> use lib ;
> use A;
>
> my A $x .= new;
> $x.test;
>
>
> % ./test.pl6
> Cannot invoke this object (REPR: Null; VMNull)
>   in block  at /git-repos/test/lib/Loader.pm6 (Loader) line 31
>   in method test at /git-repos/test/lib/Loader.pm6 (Loader) line 115
>   in method load at /git-repos/lib/Loader.pm6 (Loader) line 132
>   in block  at ./test.pl6 line 7
>
>
> As stated earlier, when I merge the class and the initialization logic
> into the same source file and run from there, no error occurs.
>
> Am I doing this wrong?
>
> Thanks,
> Paul Procacci
>
> --
> __
>
> :(){ :|:& };:
>


Re: Fwd: Raku, docs, help [was: Re: vulgar?]

2019-12-11 Thread Simon Proctor
 I would argue that signatures are great for any command line script
because you can use them with MAIN to get input checking.

On Wed, 11 Dec 2019, 18:07 Veesh Goldman,  wrote:

> I believe there's a disparity here between the needs of a sysadmin and
> people who program hardcore with Raku. That's what I'm seeing in the
> discussion here.
>
> Signatures are very important to those who write programs, because they
> help you arrange your code in a clean and maintainable and predictable way.
>
> Those who only write one-off scripts or one liners don't yet understand
> their value.
>
> My two cents on what's going on here.
>
> On Wed, Dec 11, 2019 at 7:17 PM yary  wrote:
>
>> > The signatures are very important to the developers.
>> > They only confuse the programmer.
>>
>> Speak for yourself, I'm not developing the innards of Raku, I'm just
>> using it for projects- like you. And I NEED the signatures. They tell me so
>> much!!
>>
>> -y
>>
>>
>> On Mon, Dec 9, 2019 at 6:53 PM ToddAndMargo via perl6-users <
>> perl6-users@perl.org> wrote:
>>
>>> On 2019-12-09 09:44, Trey Harris wrote:
>>> > Signatures are important to Raku.
>>>
>>> Trey,
>>>
>>> The signatures are very important to the developers.
>>> They only confuse the programmer.
>>>
>>> -T
>>>
>>


Re: Fwd: Raku, docs, help [was: Re: vulgar?]

2019-12-10 Thread Simon Proctor
On Tue, 10 Dec 2019 at 02:40, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2019-12-09 07:21, Simon Proctor wrote:
> > I think this does highlight something we probably should document more.
> >
> > How to read signatures. Because it's a *very* powerful part of the
> > language that if you don't understand you're only using it at half
> strength.
> >
> > multi method contains(Str:D: Cool:D $needle, Cool:D $pos --> Bool:D)
> >
> > If not some documentation magic, it's a core part of the language. It
> > tell you this method is called on a defined Str (Str:D:) it takes 2
> > positional arguments which have to be defined Cool types ($needle and
> > $pos) and it returns a Boolean.
> >
> > That is the code as it will be written in the Str Role.
> >
> > I *highly* advise learning how signatures work.
>
>
>
Firstly can I say I admire the fact that you are using Raku in production
on a regular basis.



> Hi Simon,
>
> Did you see the How To post I made on ".contains"?  At
> the bottom of the How To, I take apart the signature
> and explain each part.
>
>
I did. It's pretty good except your understanding of the first part Str:D :

This indicates that this method will be used when it's called on a defined
(D) String instance. The wording you use is a bit weird and it speak to my
beliefe that you don't really get Signatures.



> Do you see anywhere in the docs where how to read
> signatures is explained?  (Don't get any ideas.  The
> signatures should not be there to start with.)
>
>
Apart from here? https://docs.raku.org/type/Signature

I read through this (and some bits on Captures) and was able to get enough
information to give a talk at the Perl Conference in Glasgow in 2018.

Here's the video :
https://www.youtube.com/watch?v=V5rWtKIVmJc=PLQTGmZanuBovAKtE0dDs7rdTUvxnOwvEz

Larry was there, it was rather stressful.


> An aside on the signatures: what is and what is
> not a separator can blow your mind.
>

Not really. comma seperates arguments, colon can be used if you want to
specify information about the calling instance or class.


>
> Do you think it help me or anyone else understand
> how to use ".contains" because I explained the
> "Signature"?  Seriously?
>
>
No, I don't think you NEED the signature to understand contains. I think
that understanding and being able to read signatures CAN help you
understand more about how a subroutine or method works.


> To answer the question, look at all the various
> teaching manuals out there for Raku.  Do you see a
> SINGLE ONE, other that the one I posted, that
> uses the signatures as a teaching tool?
>

I have every single book written about Raku (though of course most are
Perl6) and most of them explain Signatures.

Again I'm not saying that they should be used as a teaching tool, but the
documentation has a lot of uses and it's not just teaching.


>
> And notice that I put the signature explanation
> at the bottom AFTER I explained how to use the
> function (method).  This is akin to the good math
> teachers that run circles around bad math teachers
> in both mechanics and theory by FIRST teaching the
> mechanics and them teaching the theory.  When
> teaching, you should never start with the theory.
> The docs do just that.
>

So when I was first reading the docs I mostly just skipped over the
signatures to get to the rest of the code. I didn't try and understand them
too much "Oh this takes a string, makes sense".

Over time I did start to learn them and that helped me getting better at
programming Perl6.


>
> The "Signatures" in the docs only confuse and often
> have mistakes in them.  Trying to get them corrected
> is a fools errand too.
>
>
How do you mean? If there's a mistake in the signature you can fix it in
the docs and put in a pull request to get it updated.


> The signatures are how the developers talk to each other.
> And judging by the results of their work, it works
> marvelously for them.  This kind of information is
> not appropriate for standard Rakoon that just wants to
> write code.
>
>
Here is where I have to respectfully disagree with you.

Writing Raku code without using Signatures and Multi Methods is like owning
a Jaguar and only driving in first gear. I mean *technically* you can get
where you want to go but you are forgoing a lot of the power of the
language.

I generally write a couple of Raku scripts a week (more if I've got the
time) and they *all* use Signatures. Most use multi methods too.



> You don't need to know how much current affects an LED
> diode to read the time on your digital clock.  This
> is what the signatures are doing.
>
> The Signatures only confuse.  They 

Re: Fwd: Raku, docs, help [was: Re: vulgar?]

2019-12-09 Thread Simon Proctor
I think this does highlight something we probably should document more.

How to read signatures. Because it's a *very* powerful part of the language
that if you don't understand you're only using it at half strength.

multi method contains(Str:D: Cool:D $needle, Cool:D $pos --> Bool:D)

If not some documentation magic, it's a core part of the language. It tell
you this method is called on a defined Str (Str:D:) it takes 2 positional
arguments which have to be defined Cool types ($needle and $pos) and it
returns a Boolean.

That is the code as it will be written in the Str Role.

I *highly* advise learning how signatures work.

On Mon, 9 Dec 2019 at 14:54, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2019-12-09 02:00, JJ Merelo wrote:
> > Other than that, it's clear from the context that it returns a Boolean
>
> JJ,
>
> You are a teacher.  In technical writing, you NEVER leave
> anything to "Context", even if it is "intuitively
> obvious to the student and left for him to figure out
> on his own".
>
> If you meant until the commit gets in place just
> go by context, then I apologize for misinterpreting
> you.
>
> The commit looks nice.  I would have liked it if they
> had used the "the needle and the haystack" instead of
> just "needle" (what am I poking?), but I can live
> with what they came up with.
>
> multi method contains(Str:D: Cool:D $needle, Cool:D $pos --> Bool:D)
>
> In the above, it is not real obvious to the Riff-Raff
> (me), who is not have developer level ledge, that the
> "Str:D" in inside the parenthesis, but instead feeding
> the method.  You have to get use to the cryptography.
>
> You still need to change the target audience of the docs
> from the Developers to the Rakoons.
>
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: modules and constants

2019-12-06 Thread Simon Proctor
If you define them in the top level of your module then all your subs have
access :

constant FOO = 2;

sub inc-by-foo( $a ) {
  $a+FOO;
}

On Fri, 6 Dec 2019 at 09:05, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2019-12-06 00:01, Tom Blackwood wrote:
> > Todd,
> >
> > AFAIK Perl’s culture is not to use so many constants in actual
> > programming. :)
> >
> > Tom
> >
>
> Is there a way to make constants universal inside a module, or
> do I have to declare them inside every sub?
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: where is my map typo?

2019-12-04 Thread Simon Proctor
You're using doubles quotes for the string you're passing to Raku.

This means the Shell will do variable interpolation. So it see's "my $map =
Map.new()" and puts the value of it's variable $map in their.

But it doesn't exist. So Raku gets "my = Map.new()" (Note the space where
$map was). And complains. (You can see that in the error).

I'd advise *always* suing single quotes to pass strings into Raku on the
command line. If you need single quotes in your code use q[] instead.

So :

p6 'my $map = Map.new("a", 1, "b", 2); say $map{"a"}; say $map{ "a", "b"
};'

Should work just fine.

%e := Map.new binds %e to the Map if you did %e = Map.new it will treat the
Map as the first element in a list and probably complain.

On the other hand $e = Map.new is assigning to a Scalar so it doesn't
expect to be taking a list of values.

If that makes sense?

On Wed, 4 Dec 2019 at 10:22, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> I am going through the examples on
> https://docs.perl6.org/type/Map.html
>
> $ p6 "my $map = Map.new('a', 1, 'b', 2); say $map{'a'}; say $map{ 'a',
> 'b' };"
> ===SORRY!=== Error while compiling -e
> Malformed my
> at -e:1
> --> my⏏  = Map.new('a', 1, 'b', 2); say {'a'};
>
> What the heck is a 'Malformed my"?  I copied and pasted
> from the second set of examples.
>
> And why is the first example:
>   %e := Map.new
> and the second example
>   $e = Map.new
> ?
>
> Many thanks,
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: restricted value passed to a sub question

2019-12-04 Thread Simon Proctor
So I'd approach this in one of two ways. Firstly there's the multi sub with
constants option :

multi selector( "AbortRetryIgnore" ) { ... }
multi selector( "CancelRetryContinue" ) { ... }
multi selector( "Help" ) { ... }
multi selector( "YesNo" ) { ... }
multi selector( "Maybe" ) { ... }

I'd do this if each option is pretty different in what happens.

If on the other hand the way the options are handled pretty similar I'd go
with and Enum :

enum Option ;
subset OptStr of Str where { Options::{$_}:exists};

multi sub selector( OptStr $opt ) { callwith( Options::{$opt} ) }
multi sub selector( Option $opt ) { ... }

This lets us all the sub with with the Option enum value eg :
selector(YesNo) or the string variant (useful on the command line) eg :
selector("YesNo")

I'd do this if there's a lot of shared functionality in the selector sub.

Hope that helps.

You can combine the two options of course :)

enum Option ;
subset OptStr of Str where { Options::{$_}:exists};
multi sub selector( OptStr $opt ) { callwith( Options::{$opt} ) }

multi selector( AbortRetryIgnore ) { ... }
multi selector( CancelRetryContinue) { ... }
multi selector( Help ) { ... }
multi selector( YesNo ) { ... }
multi selector( Maybe ) { ... }

Simon


On Wed, 4 Dec 2019 at 08:45, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> I am cooking up something where I want top pass a value to a sub, but I
> want to restrict what those values are.
>
> For instance, things like
>
> AbortRetryIgnore
> CancelRetryContinue
> Help
> YesNo
> Maybe
>
> And so on and so forth.
>
> If the wrong value is passed, I want the checker to crash
> the sub.
>
> What is the best way of going about this?
>
> Many thanks,
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Fwd: for by 3?

2019-11-26 Thread Simon Proctor
Forgot to reply all this to the list.

In my defence it's first thing in the morning for me.


-- Forwarded message -
From: Simon Proctor 
Date: Wed, 27 Nov 2019, 06:59
Subject: Re: for by 3?
To: William Michels 


Sorry Bill I was typing that on my phone and didn't fully explain.

Mostly I didn't include the block after the @b.

-> in Raku is used the pass arguments into a block so this :

for @a -> $b { say $b }

Iterates through @a passing each value to the block. The block lexical
scopes the incoming value as $b because of the ->.

The reason you got your error was because you didn't have a block.

Sorry for the confusion.

On Wed, 27 Nov 2019, 00:04 William Michels,  wrote:

>
> Inline:
>
>> -- Forwarded message -----
>> From: Simon Proctor 
>> Date: Sat, Nov 23, 2019 at 3:34 AM
>> Subject: Re: for by 3?
>> To: ToddAndMargo 
>> Cc: perl6-users 
>>
>> If you want to read you lines in groups of 3 then you want batch :
>> for @x.lines.batch(3) -> @b
>> If you just want the third line and throw away the first I'd probably do
>> a tail on that.
>> for @x.lines.batch(3).map( *.tail ) -> $l
>> Note you need to map the tail on each batch of three not slap it on the
>> end.
>
>
>
> Hi Simon, can you explain to me what the "->" arrow is doing in your
> above? All I see in the docs is  "->" used within the signature part of a
> sub. I can get some  "->" arrow-containing code to work (below), but it
> doesn't resemble your code. Specifically, if I drop the block containing
> 'put', Raku/Perl6 throws an error.  Any advice appreciated, Bill.
>
> mbook:~ homedir$ cat testcode5.p6
> first line of code
> second line of code
> third line of code
> fourth line of code
> fifth line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my @b; for lines.batch(3) ->
> @b {put @b};'
> first line of code second line of code third line of code
> fourth line of code fifth line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my @b; for lines.rotor(3) ->
> @b {put @b};'
> first line of code second line of code third line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my $b; for lines.batch(3) ->
> $b {put $b};'
> first line of code second line of code third line of code
> fourth line of code fifth line of code
> mbook:~ homedir$ cat testcode5.p6 | perl6 -e 'my $b; for lines.batch(3) ->
> $b;'
> ===SORRY!=== Error while compiling -e
> Malformed parameter
> at -e:1
> --> my $b; for lines.batch(3) -> $b;⏏
> mbook:~ homedir$
>


Re: for by 3?

2019-11-23 Thread Simon Proctor
If you want to read you lines in groups of 3 then you want batch :

for @x.lines.batch(3) -> @b

If you just want the third line and throw away the first I'd probably do a
tail on that.

for @x.lines.batch(3).map( *.tail ) -> $l

Note you need to map the tail on each batch of three not slap it on the end.


On Sat, 23 Nov 2019, 06:00 ToddAndMargo via perl6-users, <
perl6-users@perl.org> wrote:

> Hi All,
>
> In a "for" loop, what is the syntax for "by 3"?
>
>  for @x.lines by 3
>
> In other words, every third line.
>
> Many thanks,
> -T
>


Re: Variable character class

2019-09-01 Thread Simon Proctor
Using a set would be good but it doesn't give you the matching string from
the original (which is what I thought was required) otherwise Sets would be
my first thought.

On Sun, 1 Sep 2019, 17:57 William Michels,  wrote:

> Hi Yary and Paul and Simon,
>
> I ran into the same difficulties as Yary with repeated characters, so
> I tried the .unique method. Then after a while, I realized that
> problems like this might best be treated as "Set" problems in Perl6.
> Note the Set Intersection operator "(&)" below:
>
> sub matching_chars(Str $a, Str $b) {
>my @c = $a.comb.unique;
>my @d = $b.comb.unique;
>#say @c; say @d;
>return @c (&) @d;
> }
>
> say matching_chars("24680", "19584203"); #RETURNS set(0 2 4 8)
> say matching_chars('+\/\]\[', 'Apple ][+//e'); #RETURNS set(+ / [ ])
>
>
> https://docs.perl6.org/routine/Set
> https://docs.perl6.org/language/operators#infix_(&),_infix_∩
>
> HTH, Bill.
>
>
> On Sat, Aug 31, 2019 at 8:59 PM Paul Procacci  wrote:
> >
> > I'm not entirely sure if this is the correct answer, but if you define
> your own custom character class
> > with a 'regex' object, you can use that in the grouping.
> >
> > sub matching_chars(Str $chars_to_match, Str $_) {
> > my regex x { $chars_to_match ** 1 };
> > m/<[]>/;
> > }
> >
> > The above worked for me in the very small testing I did.
> >
> > ~Paul
> >
> > On Sat, Aug 31, 2019 at 9:54 PM yary  wrote:
> >>
> >> I found something easy in Perl 5 that's puzzling me in Perl 6-
> specifying a character class via a variable.
> >>
> >> Perl 5:
> >> sub matching_chars {
> >>   (my $chars_to_match, local $_) = @_;
> >>   /([$chars_to_match]+)/
> >> }
> >>
> >> say matching_chars('24680', '19584203'); # says 8420
> >> say matching_chars('+\/\]\[', 'Apple ][+//e'); # says ][+//
> >>
> >> Perl 6:
> >> sub matching_chars(Str $chars_to_match, Str $_) {
> >> # warnings, treats as string not variable
> >> m/<[$chars_to_match]>/;
> >> }
> >>
> >> How do I get Perl 6 to interpret a variable in the contents of a
> character class?
> >> From http://docs.perl6.org/language/regexes#Regex_interpolation I'd
> think that  Rakudo would use the literal contents of $chars_to_match,
> instead it's using the literal chars "$ c h a r s _ t o _ m a t c h" and
> warning about repeated c, underscore, etc.
> >>
> >> -y
> >
> >
> >
> > --
> > __
> >
> > :(){ :|:& };:
>


Re: Variable character class

2019-09-01 Thread Simon Proctor
sub contains ( Str $chars, Str $_ ) {
  m:g/<{$chars.comb}>+/
};

This will return all the sets of matching strings but it is doing runtime
evaluation of your character string so it's a bit slow.

On Sun, 1 Sep 2019 at 04:59, Paul Procacci  wrote:

> I'm not entirely sure if this is the correct answer, but if you define
> your own custom character class
> with a 'regex' object, you can use that in the grouping.
>
> sub matching_chars(Str $chars_to_match, Str $_) {
> my regex x { $chars_to_match ** 1 };
> m/<[]>/;
> }
>
> The above worked for me in the very small testing I did.
>
> ~Paul
>
> On Sat, Aug 31, 2019 at 9:54 PM yary  wrote:
>
>> I found something easy in Perl 5 that's puzzling me in Perl 6- specifying
>> a character class via a variable.
>>
>> Perl 5:
>> sub matching_chars {
>>   (my $chars_to_match, local $_) = @_;
>>   /([$chars_to_match]+)/
>> }
>>
>> say matching_chars('24680', '19584203'); # says 8420
>> say matching_chars('+\/\]\[', 'Apple ][+//e'); # says ][+//
>>
>> Perl 6:
>> sub matching_chars(Str $chars_to_match, Str $_) {
>> # warnings, treats as string not variable
>> m/<[$chars_to_match]>/;
>> }
>>
>> How do I get Perl 6 to interpret a variable in the contents of a
>> character class?
>> From http://docs.perl6.org/language/regexes#Regex_interpolation I'd
>> think that  Rakudo would use the literal contents of $chars_to_match,
>> instead it's using the literal chars "$ c h a r s _ t o _ m a t c h" and
>> warning about repeated c, underscore, etc.
>>
>> -y
>>
>
>
> --
> __
>
> :(){ :|:& };:
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Checking If a certain object is present in Array

2019-08-15 Thread Simon Proctor
Oh. That's easy use an any junction.

say any(@objects) ~~ Bool;

On Thu, 15 Aug 2019 at 16:10, Mikkel  wrote:

> Hi Simon
>
> That was certainly a simple way.
> But this checks for the value of True rather than the object type Bool
> right? What if I wanted to know if an Int, (with any given value) were
> among the values?
>
> Best regards
> Mikkel
>
> On Thu, 15 Aug 2019 at 16:38, Simon Proctor 
> wrote:
>
>> The easiest option would be use the set operators. In this case (elem)
>> (or ∈) will coerce your array to a Set and then check to see if the given
>> item is in it.
>>
>> my @objects = [1, True, "string", 5, Str.new];
>> say True (elem) @objects;
>> say True ∈ @objects;
>>
>> Give True. Note Removing the True from the list and we get False so we
>> don't have to worry about the joys of truthiness it's taking your types
>> into account.
>>
>> Hope that helps.
>>
>> Simon
>>
>>
>> On Thu, 15 Aug 2019 at 15:29, Mikkel  wrote:
>>
>>> Hello.
>>>
>>> Suppose I have an array (or should I say a positional?):
>>> my @objects = [1, True, "string", 5, Str.new];
>>> Containing different kind of objects. It could be Ints, Strs and Bools.
>>> Is there a nice way of determining if for example a Bool is present in
>>> the array, returning True or False whether the given object is present or
>>> not?
>>>
>>> Best Regards
>>> Mikkel Birkedam
>>>
>>
>>
>> --
>> Simon Proctor
>> Cognoscite aliquid novum cotidie
>>
>> http://www.khanate.co.uk/
>>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Checking If a certain object is present in Array

2019-08-15 Thread Simon Proctor
The easiest option would be use the set operators. In this case (elem) (or
∈) will coerce your array to a Set and then check to see if the given item
is in it.

my @objects = [1, True, "string", 5, Str.new];
say True (elem) @objects;
say True ∈ @objects;

Give True. Note Removing the True from the list and we get False so we
don't have to worry about the joys of truthiness it's taking your types
into account.

Hope that helps.

Simon


On Thu, 15 Aug 2019 at 15:29, Mikkel  wrote:

> Hello.
>
> Suppose I have an array (or should I say a positional?):
> my @objects = [1, True, "string", 5, Str.new];
> Containing different kind of objects. It could be Ints, Strs and Bools.
> Is there a nice way of determining if for example a Bool is present in the
> array, returning True or False whether the given object is present or not?
>
> Best Regards
> Mikkel Birkedam
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Short term Zef fix

2019-04-30 Thread Simon Proctor
Not tried that

On Tue, 30 Apr 2019 at 12:35, Timo Paulssen  wrote:

> Doesn't updating zef to the latest version fix everything up nicely?
>   - Timo
> On 30/04/2019 12:06, Simon Proctor wrote:
>
> Until the p6c system is fixed here's a short term fix that will at least
> let zef install modules from cpan.
>
> zef --help
> This lists a config file mine is :
>
> CONFIGURATION /home/sproctor/.config/zef/config.json
>
> Open that file and fine the "p6c" section. Set enabled to 0 and zef will
> stop trying to access the ecosystem modules.
>
> It's not perfect as not everything is in CPAN but it should help.
>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/
>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Short term Zef fix

2019-04-30 Thread Simon Proctor
Oooh. How would I do that?

(Like I say it's a short term fix as hopefully we'll get p6c back soonish).

On Tue, 30 Apr 2019 at 12:01, JJ Merelo  wrote:

> The problem with that is that it will go from using the old version of the
> file (and old versions of modules there) to none of them. It's probably
> better to lower the timeout...
>
> El mar., 30 abr. 2019 a las 12:07, Simon Proctor ()
> escribió:
>
>> Until the p6c system is fixed here's a short term fix that will at least
>> let zef install modules from cpan.
>>
>> zef --help
>> This lists a config file mine is :
>>
>> CONFIGURATION /home/sproctor/.config/zef/config.json
>>
>> Open that file and fine the "p6c" section. Set enabled to 0 and zef will
>> stop trying to access the ecosystem modules.
>>
>> It's not perfect as not everything is in CPAN but it should help.
>>
>> --
>> Simon Proctor
>> Cognoscite aliquid novum cotidie
>>
>> http://www.khanate.co.uk/
>>
>
>
> --
> JJ
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Short term Zef fix

2019-04-30 Thread Simon Proctor
Until the p6c system is fixed here's a short term fix that will at least
let zef install modules from cpan.

zef --help
This lists a config file mine is :

CONFIGURATION /home/sproctor/.config/zef/config.json

Open that file and fine the "p6c" section. Set enabled to 0 and zef will
stop trying to access the ecosystem modules.

It's not perfect as not everything is in CPAN but it should help.

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: I need help with "lines"

2019-03-15 Thread Simon Proctor
there is no @x[1]. etc.
> >>  >
> >>  > The result I want is 13908
> >>  >
> >>  > Many thanks,
> >>  > -T
> >>
> >> And why do I have a broken pipe here?
> >>
> >> $ ps ax | grep [f]irefox | perl6 -ne 'say
> >> $_.lines.sort.reverse.words[0];'
> >> 7380
> >> 7581
> >> 7698
> >> 13023
> >> 13767
> >> 22369
> >>
> >> $ ps ax | grep [f]irefox | perl6 -ne 'say
> >> $_.lines.sort.reverse.words[0];' | sort -r
> >>
> >> Failed to write bytes to filehandle: Broken pipe
> >> in block  at -e line 1
> >>
>
>
>
> On 3/14/19 10:53 PM, Simon Proctor wrote:
> > 6am here and I'm not at a computer but I think your problem is trying to
> > use both -n which runs your code on each line of STDIN and lines.
> >
> > Try one or the other see what happens.
> >
> > Once I'm ambulant and at a computer I'll poke at it myself.
>
>
> Thank you anyway.
>
>
> $ ps ax | grep [f]irefox | perl6 -n 'my @x = $_.words[0].lines.reverse;
> print @x[0] ~ "\n";'
> Could not open my @x = $_.words[0].lines.reverse; print @x[0] ~ "\n";.
> Failed to stat file: no such file or directory
>
> $ ps ax | grep [f]irefox | perl6 -e 'my @x = $_.words[0].lines.reverse;
> print @x[0] ~ "\n";'
> No such method 'words' for invocant of type 'Any'
>in block  at -e line 1
>
> >
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: I need help with "lines"

2019-03-14 Thread Simon Proctor
6am here and I'm not at a computer but I think your problem is trying to
use both -n which runs your code on each line of STDIN and lines.

Try one or the other see what happens.

Once I'm ambulant and at a computer I'll poke at it myself.

On Fri, 15 Mar 2019, 05:34 Todd Chester via perl6-users, <
perl6-users@perl.org> wrote:

>
>
> On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
> > Hi All,
> >
> > What am I doing wrong here?
> >
> > ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse;
> > print @x[0] ~ "\n";'
> > 7380
> > 7581
> > 7698
> > 13023
> > 13767
> > 13908
> >
> >
> > Two problems:
> >
> > 1) "lines" is putting everything into @x[0]
> >
> > 2) "reverse" is ignoring me as there is no @x[1]. etc.
> >
> > The result I want is 13908
> >
> > Many thanks,
> > -T
>
> And why do I have a broken pipe here?
>
> $ ps ax | grep [f]irefox | perl6 -ne 'say $_.lines.sort.reverse.words[0];'
> 7380
> 7581
> 7698
> 13023
> 13767
> 22369
>
> $ ps ax | grep [f]irefox | perl6 -ne 'say
> $_.lines.sort.reverse.words[0];' | sort -r
>
> Failed to write bytes to filehandle: Broken pipe
>in block  at -e line 1
>


Re: buf to integer?

2019-02-08 Thread Simon Proctor
Ooo. Nice.

On Fri, 8 Feb 2019, 17:55 Brad Gilbert  If you have a new enough version of Rakudo:
>
> my Buf $x=Buf.new(0xAE,0x5D,0x5C,0x72);
>
> my int32 $i = $x.read-int32(0,LittleEndian);
>
> say $i.base(16);
> # 725C5DAE
>
> On Fri, Feb 8, 2019 at 12:35 AM Todd Chester via perl6-users
>  wrote:
> >
> > Hi All,
> >
> > I am dealing with a Buf what includes 32 bit integers, but
> > they are entered somewhat backwards as view with hexedit:
> >
> > AE 5D 5C 72 represents the number 725C5DAE
> >
> > This is what I have come up with to convert this type of
> > number in a buffer to and integer
> >
> > $ p6 'my Buf $x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 $i=$x[3] +< 0x18
> > +  $x[2] +< 0x10  +  $x[1] +< 0x08  +  $x[0];  say $x; say
> $i.base(0x10);'
> >
> > Buf:0x
> > 725C5DAE
> >
> >
> > Is there a more "elegant" way to do this?
> >
> > Many thanks,
> > -T
>


Re: buf to integer?

2019-02-08 Thread Simon Proctor
There's probably a nicer way but I don't generally play about with this
sort of thing.

:16([~] $x.reverse.map( *.base(16) ))

It does involve lots of String manipulation, as I say. There's probably a
better way.


On Fri, 8 Feb 2019 at 06:35, Todd Chester via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> I am dealing with a Buf what includes 32 bit integers, but
> they are entered somewhat backwards as view with hexedit:
>
> AE 5D 5C 72 represents the number 725C5DAE
>
> This is what I have come up with to convert this type of
> number in a buffer to and integer
>
> $ p6 'my Buf $x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 $i=$x[3] +< 0x18
> +  $x[2] +< 0x10  +  $x[1] +< 0x08  +  $x[0];  say $x; say $i.base(0x10);'
>
> Buf:0x
> 725C5DAE
>
>
> Is there a more "elegant" way to do this?
>
> Many thanks,
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Roles are fundamentally broken?

2019-01-29 Thread Simon Proctor
I think part of the issue is that fundamentally Roles are intended to be a
way of doing non inheritance based classes. So composing Roles from other
Roles is an anti pattern.

On Tue, 29 Jan 2019, 06:32 yary  https://github.com/rakudo/rakudo/issues/2657 - looks like an outright
> bug, to me.
>
> I don't know about "the big picture" but you hit a
> not-explicitly-documented case.
>
> Referring to
> https://docs.perl6.org/language/objects#index-entry-declarator_role-Roles
> -
>
> *When a role is applied to a class, the methods of that role are copied
> into the class. If multiple roles are applied to the same class, conflicts
> (e.g. attributes or non-multi methods of the same name) cause a
> compile-time error, which can be solved by providing a method of the same
> name in the class.*
>
> That page continues on to an example which works- I added a couple lines
> to print output-
>
> use v6.c;
>
> role Bull-Like {
> has Bool $.castrated = False;
> method steer {
> # Turn your bull into a steer
> $!castrated = True;
> return self;
> }
> }
> role Steerable {
> has Real $.direction;
> method steer(Real $d = 0) {
> $!direction += $d;
> }
> }
>
> # Try changing 'class' to 'role' on the next line
> class Taurus does Bull-Like does Steerable {
> method steer($direction?) {
> self.Steerable::steer($direction)
> }
> }
>
> my $t=Taurus.new;
> say $t.steer(3.3); # Says 3.3 when Taurus is a class, dies when a role.
> say $t.steer(1.1); # Says 4.4 (if it gets this far)
>
> That section explicitly discusses what happens when multiple roles with
> the same name are applied to a class, and how the class is to resolve it.
> But it never mentions applying roles with conflicting names to another role.
>
> It appears that the Rakudo implementation has the same blind spot as the
> Perl6 documentation.
>
> I'd like it if roles disambiguated same-name application just as classes
> did. Which means, the role they are applied to must have a role with the
> same name explicitly calling the methods it wants- compile time error
> otherwise. Roles would never participate in MRO, because their "flatness"
> part of their attractiveness - there's no guessing which role is providing
> a method, any potential name clash is averted by requiring calling out the
> role or class providing the desired semantics.
>
> Through that lens, my thoughts on
> https://github.com/rakudo/rakudo/issues/2282 - ought to run without error
> https://github.com/rakudo/rakudo/issues/2496 - my edits/comments
> role  X{ method f { say "f" } }
> role  Y does X { method g { say "g" } }
> class C does Y {}
>
> C.new.Y::g;  # works
> C.new.Y::f;  # works
> C.new.X::f;  # LTA error. But with roles doing "flat" copying don't have
> an expectation that C knows the name "X",
> # I only expect that C can call method f which it got from Y, and that did
> work.
>
> -y
>
>


Re: Bad syntax check

2019-01-02 Thread Simon Proctor
Have you tried defining your return values in the signature?

sub AddThree( Int $a, Int $b, Int $c --> Int) {...}

With this the compiler knows what your function is supposed to return and
can earn you in advance.

On Wed, 2 Jan 2019, 20:04 ToddAndMargo via perl6-users  Dear Perl 6 Developers,
>
> Fedora 29, x64
> Xfce 4.13
>
> $ perl6 -v
>  This is Rakudo version 2018.11 built on MoarVM version
>  2018.11 implementing Perl 6.d.
>
> I am constantly improving (changing things) in my subs,
> etc..  As such, the things I return often change.
>
> Because of this, I have a found something I just do not like
> in the checker (Perl6 -c xxx) and the run time compiler.
>
> Here is a simplified sample code with the error in it:
>
> 
> #!/usr/bin/env perl6
>
> sub AddThree( Int $a, Int $b, Int $c ) {
> my Int $d = $a + $b + $c;
> return $d;
> }
>
> my Int $X = 0;
> my Int $Y = 0;
>
> ( $X, $Y ) = AddThree( 1, 2, 3 );
> say "X = <$X>\tY = <$Y>";
> 
>
>
> The error is that the subroutine is only returning one
> value and two are trying to be read.
>
> And the checker passes it!
>
>  $ perl6 -c RtnBooBoo.pl6
>  Syntax OK
>
> No, it is not okay.  The sub and the caller do not match up!
>
>
> If you run the flawed code, you get:
>
>  $ RtnBooBoo.pl6
>  Use of uninitialized value of type Int in string context.
>  Methods .^name, .perl, .gist, or .say can be used to stringify
>  it to something meaningful.  in block  at ./RtnBooBoo.pl6
>  line 12
>
>  X = <6>Y = <>
>
> Which is a bizarre warning (it does not stop on this error).  And
> it is also not the error.  The error was that the return line's
> returned variables and the caller do not match up.  Not an
> uninitialized value.
>
> If you send too few variables to a sub, you get the finger shaken
> at you.  The return should also have the same checking capability.
>
> Would you guys please consider improving the checker and the compiler?
>
> Many thanks,
> -T
>


Re: Perl 6 Advent calendar open for contributions

2018-11-16 Thread Simon Proctor
Can I just say on this. I did one last year,

I don't think I'd been doing anything with Perl6 the year before.

You don't have to be some kind of super guru or anything you just need to
have something *you* like about the language or it's uses that you think
others might find interesting.

The only thing you have to fear is fear itself and all that. ;)

Go on. Give it a go.



On Fri, 16 Nov 2018 at 06:27, JJ Merelo  wrote:

> Do you have something to say with/about Perl 6? Add your name (and then
> write the article) to the Perl 6 Advent Calendar schedule!
> https://github.com/perl6/mu/blob/master/misc/perl6advent-2018/schedule
>
> ... Please!
>
> Cheers
>
> --
> JJ
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: routine declaration line question

2018-10-12 Thread Simon Proctor
What if something could return an Int or a Rat? Or an single item or an
Array? Having Mu or Any as the listed return type isn't very useful.

Maybe better to define a subset for it. Or just leave it empty and document
it.

On Fri, 12 Oct 2018, 13:35 Curt Tilmes,  wrote:

>
> On Fri, Oct 12, 2018 at 7:46 AM Simon Proctor 
> wrote:
>
>> Only if the routine has an easily defined return Type. Many do not.
>>
>
> Is there not always a common root, even if it is Mu?  Why not explicitly
> mark those
> as Mu for documentation purposes at least?  That would differentiate those
> from
> the ones just not documented that pick up Mu by default.
>
> Curt
>
>


Re: routine declaration line question

2018-10-12 Thread Simon Proctor
Only if the routine has an easily defined return Type. Many do not.

On Fri, 12 Oct 2018 at 12:41, Curt Tilmes  wrote:

>
>
> On Fri, Oct 12, 2018 at 7:31 AM Todd Chester via perl6-users <
> perl6-users@perl.org> wrote:
>
>> I was asking because sometimes the documentation for routines does
>> not give a --> and I find having to dig around to figure out what
>> the return is to be time consuming and confusing.
>>
>> Based on what Larry stated, I do believe that the documentation
>> should always have a --> in the definition line.  This was
>> my question, not whether or not I should write a definition
>> line for my own subs.
>>
>
> I agree.  The documentation should always describe the routine with a -->
>
> Curt
>
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Use of the --output flag

2018-10-09 Thread Simon Proctor
100% thanks a lot. :)

On Tue, 9 Oct 2018 at 16:31, Timo Paulssen  wrote:

> --output is for the compiler's compilation stages
>
> for example:
>
> timo@schmand ~> perl6 --output=/tmp/outputtest --target=mbc -e 'say "hi"'
> timo@schmand ~> moar --dump /tmp/outputtest | head
>
> MoarVM dump of binary compilation unit:
>
>   SC_0 : B1DFAD9164F11E967B354508CC458ABAB8DEDC27
>   SC_1 : D71FD1C8B1B40FC9B294068F2EC29C505914FDC6-0
>   SC_2 : 0808522FF10EC773B02A4C55883CC154BB964DE2
>   Callsite_0 :
> num_pos: 0
> arg_count: 0
>   Callsite_1 :
>
>
> Most of the compilation stages don't work with --output, which could be a
> bug. However, --output isn't supposed to change what $*OUT is set to in the
> script.
>
> Hope that helps
>   - Timo
>
>
> On 09/10/2018 15:18, Simon Proctor wrote:
>
> So... I'm working through some notes for a talk on Thursday and I am
> trying to work out how the --output flag is supposed to work.
>
> I would expect this to create a file called test and print "Hi\n" in it :
>
> perl6 --output=test -e 'say "Hi"'
>
> But instead I got Hi printed to the command line and an error :
>
> Use of Nil in string context
>   in any print at gen/moar/stage2/NQPCORE.setting line 850
>
> Trying use it on a sime file (say "Hi") and it also doesn't do that.
>
> (Note that the test file is created but it's empty).
>
> Any ideas?
>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/
>
>

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Use of the --output flag

2018-10-09 Thread Simon Proctor
It feels like a bug. I more wanted to know if anyone knew anything about it
for the talk.

Thanks

On Tue, 9 Oct 2018, 14:49 Brad Gilbert,  wrote:

> My guess is that this is a bug.
>
> You can work around it by adding
>
> my $*OUT = q[test].IO.open(:w);
>
> in front of the code.
> On Tue, Oct 9, 2018 at 8:18 AM Simon Proctor 
> wrote:
> >
> > So... I'm working through some notes for a talk on Thursday and I am
> trying to work out how the --output flag is supposed to work.
> >
> > I would expect this to create a file called test and print "Hi\n" in it :
> >
> > perl6 --output=test -e 'say "Hi"'
> >
> > But instead I got Hi printed to the command line and an error :
> >
> > Use of Nil in string context
> >   in any print at gen/moar/stage2/NQPCORE.setting line 850
> >
> > Trying use it on a sime file (say "Hi") and it also doesn't do that.
> >
> > (Note that the test file is created but it's empty).
> >
> > Any ideas?
> >
> > --
> > Simon Proctor
> > Cognoscite aliquid novum cotidie
> >
> > http://www.khanate.co.uk/
>


Use of the --output flag

2018-10-09 Thread Simon Proctor
So... I'm working through some notes for a talk on Thursday and I am trying
to work out how the --output flag is supposed to work.

I would expect this to create a file called test and print "Hi\n" in it :

perl6 --output=test -e 'say "Hi"'

But instead I got Hi printed to the command line and an error :

Use of Nil in string context
  in any print at gen/moar/stage2/NQPCORE.setting line 850

Trying use it on a sime file (say "Hi") and it also doesn't do that.

(Note that the test file is created but it's empty).

Any ideas?

-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Could this be any more obscure?

2018-10-02 Thread Simon Proctor
ut understanding the
> > signature (but it is still very useful to have the signature definition
> > in the documentation), or bite the bullet and learn how to read
> signatures.
> >
> > Despite your denegation, I think that what you really need is to read a
> > good tutorial or book on Perl 6. If you had made a real effort to read
> > such introductory material, you would probably not have needed to ask
> > about 90% of the questions you asked lately. Do yourself a favor: read
> > good introductory material (tutorials or books).
> >
> > HTH,
> > Laurent.
> >
> >
>
> Hi Laurent,
>
> You already know what to expect.  You are an advanced user.
> And I would have to tentatively agree with you. The documentation
> does "seem" to be extraordinarily well written for advanced
> developer level users.  Just the sort of reader that does not
> need to use it as they already know what is going on.
>
> When you know how to use a function but can't reverse
> engineer how to do it from the documentation, then you
> are in real trouble.
>
> I am thinking of doing an RFE to place at the front
> of the routines documentation that introduces the reader
> on how to read THAT line in the documentation -- what
> the abbreviations and symbols and the like mean.
>
> If I do, I will post it here first for criticism.
>
> Your thoughts?
>
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: join questions

2018-09-30 Thread Simon Proctor
On Sun, 30 Sep 2018, 12:05 ToddAndMargo,  wrote:

> Hi All,
>
> https://docs.perl6.org/routine/join#(List)_routine_join
>
> method join(List:D: $separator --> Str:D)
>
> $ p6 'say (1, ).join("|");'
> 1|a b c
>
>
> In this instance you have passed in two objects the Int 1 and a list of
> Str's  (<> being similar to qw () in perl5. Join works on Str's to
> the first thing it does is convert each of the two parameters to Str, the
> default Str conversion for a list is space separated hence "a b c" which is
> then joined with "1" to get "1|a b c"
>
>
> It states in the manual that this will happen.
>
> Questions:
>
> 1) why?
>
> 2) where in the method definition does it state
>this will happen?
>
> 3) why does this work?
>   $ p6 'join( "|", <1 2 3>).say;'
>   1|2|3
>
> In this case the join sub will be using the + slurpy so it's flattening
> the given input into it's parameter list and then joining it.
>
> Many thanks,
> -T
>

I think you really want to get a solid understanding of signatures, they
are what gives Perl6 a lot of it's flexibility. Unlike Perl5 where many
functions have special rules handling input in Perl6 a lot of it is done
with Signatures.

Simon

>


Re: .kv ?

2018-09-14 Thread Simon Proctor
Just look at Curt's explanation.

On Fri, 14 Sep 2018, 12:22 Todd Chester,  wrote:

>
>
> On 09/14/2018 04:18 AM, Simon Proctor wrote:
> > Assigned, created or defined.
> >
> > Basically the object has a value.
>
> Not following.  Are there three of them?
>


Re: .kv ?

2018-09-14 Thread Simon Proctor
:D is a type constraint requiring an instantiated (or defined) object of
the given type (or a subtype of it).

:U is a type constraint saying you have a container specified for the given
type that hasn't been instantiated.

So if you have my Int $a; you have said this should hold and Int but it's
currently valueless (undefined). It would match Int:U in a signature.

Assign 5 to it and it's now defined and matches Int:D in a signature.

On Fri, 14 Sep 2018, 11:44 Todd Chester,  wrote:

> >> On Fri, 14 Sep 2018, 11:22 Todd Chester,  >> <mailto:toddandma...@zoho.com>> wrote:
> >>
> >> Hi All,
> >>
> >> I adore the "kv" method:
> >>
> >> $ p6 'for "abc\n23\n4.56".lines.kv -> $i, $j { say "$i  $j" };'
> >> 0  abc
> >> 1  23
> >> 2  4.56
> >>
> >> So, I decided to go and look at:
> >> https://docs.perl6.org/routine/kv
> >>
> >> multi method kv(Any:U:  -->List)
> >> multi method kv(Any:D:  -->List)
> >>
> >>
> >> Okay, here is what I see:
> >>
> >> "method"  is .foo style of a routine
> >>
> >> "Any:U:" and "Any:D:" are what goes in front of .foo
> >> and it can be of type "Any".
> >>
> >> https://docs.perl6.org/type/Any
> >>
> >>":D" mean constrained, meaning it much have something
> >>
> >>What is ":U"?
> >>
> >>Whatever ":U", how can it be both?
> >>
> >> The second ":" is the delimiter for what goes in front of the .foo,
> >> meaning it has finished its declaration of what that in front is.
> >> Kind of like a comma.
> >>
> >> "-->List" mean something is returned of type "List"
> >> https://docs.perl6.org/type/List
> >>
> >>0  abc
> >>1  23
> >>2  4.56
> >>
> >>
> >> How have I done so far?
> >>
> >>
> >> And is there a list somewhere of the meanings of ":U" and ":D"
> >> and such so the next time I see one that I do not recognize,
> >> I can look it up?
> >>
> >> Many thanks,
> >> -T
> >>
>
>
> On 09/14/2018 03:28 AM, Simon Proctor wrote:
> > :D means a defined value. So it's when you have an instance. :U is
> > undefined so it's when you call kv as a classethod.
> >
> > Pair.kv would be :U.
> > (A => "b").kv would be :D
> >
> >
>
> Hi Simion,
>
> I am not following.  What do you mean by "undefined"?
>
> I can't make head or tails out of "Pair"
> https://docs.perl6.org/type/Pair
>
> I thought ":D" meant "constrained"?
>
> Yours in confusion ,
> -T
>


Re: .new?

2018-09-14 Thread Simon Proctor
I think the docs of objects (sorry on my phone no link) describe object
creation and the default new quite well.

Do a search for objects.

On Fri, 14 Sep 2018, 11:30 Todd Chester,  wrote:

> Hi All,
>
> What exactly is going on with .new?
>
>https://docs.perl6.org/routine/new
>method new(Telemetry::Sampler: @instruments --> Telemetry::Sampler:D)
>
> The whole thing went over my head.  It looks like
> specifications for the developers, but I really can't
> tell.  And it looks like it might be really handy.
>
> What can I use it for?
>
>
> Also, does "Telemetry::Sampler" mean what it does in Perl 5,
> which is a routine called "Sampler" found in the module
> called "Telemetry"?
>
> Many thanks,
> -T
>


Re: .kv ?

2018-09-14 Thread Simon Proctor
:D means a defined value. So it's when you have an instance. :U is
undefined so it's when you call kv as a classethod.

Pair.kv would be :U.
(A => "b").kv would be :D


On Fri, 14 Sep 2018, 11:22 Todd Chester,  wrote:

> Hi All,
>
> I adore the "kv" method:
>
> $ p6 'for "abc\n23\n4.56".lines.kv -> $i, $j { say "$i  $j" };'
> 0  abc
> 1  23
> 2  4.56
>
> So, I decided to go and look at:
> https://docs.perl6.org/routine/kv
>
> multi method kv(Any:U:  -->List)
> multi method kv(Any:D:  -->List)
>
>
> Okay, here is what I see:
>
> "method"  is .foo style of a routine
>
> "Any:U:" and "Any:D:" are what goes in front of .foo
> and it can be of type "Any".
>
>   https://docs.perl6.org/type/Any
>
>   ":D" mean constrained, meaning it much have something
>
>   What is ":U"?
>
>   Whatever ":U", how can it be both?
>
> The second ":" is the delimiter for what goes in front of the .foo,
> meaning it has finished its declaration of what that in front is.
> Kind of like a comma.
>
> "-->List" mean something is returned of type "List"
>   https://docs.perl6.org/type/List
>
>   0  abc
>   1  23
>   2  4.56
>
>
> How have I done so far?
>
>
> And is there a list somewhere of the meanings of ":U" and ":D"
> and such so the next time I see one that I do not recognize,
> I can look it up?
>
> Many thanks,
> -T
>


Re: Nil ?

2018-09-12 Thread Simon Proctor
O learn something new everyday :)

On Wed, 12 Sep 2018 at 08:46 Elizabeth Mattijsen  wrote:

> Also:
>
> my $a is default(Nil);
>
> > On 12 Sep 2018, at 09:25, Simon Proctor  wrote:
> >
> > If you don't define the type of a Scalar and don't assign to it you'll
> have an undefined Any (the Parent class of all the other types). If you
> assign Nil to it then you have the same effect.
> >
> > You can make $x to be Nil by iether casting it : my Nil $x; or binding
> it to Nil; my $x; $x := Nil;
> >
> > Basically Nil is special, slippery and a bit hard to catch.
> >
> >
> >
> > On Wed, 12 Sep 2018 at 06:56 ToddAndMargo  wrote:
> > What am, I missing?
> >
> > $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> > Not Nil
> >
> > $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> > Not Nil
> > --
> > Simon Proctor
> > Cognoscite aliquid novum cotidie
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Nil ?

2018-09-12 Thread Simon Proctor
If you don't define the type of a Scalar and don't assign to it you'll have
an undefined Any (the Parent class of all the other types). If you assign
Nil to it then you have the same effect.

You can make $x to be Nil by iether casting it : my Nil $x; or binding it
to Nil; my $x; $x := Nil;

Basically Nil is special, slippery and a bit hard to catch.



On Wed, 12 Sep 2018 at 06:56 ToddAndMargo  wrote:

> What am, I missing?
>
> $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> Not Nil
>
> $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> Not Nil
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Please explain this to me

2018-09-12 Thread Simon Proctor
In answer to "why the : between Str:D and Cool:D and why Int(Cool:D) ?" can
I just point out the video I linked (or the slides) which answer both of
these questions.



On Wed, 12 Sep 2018 at 06:29 ToddAndMargo  wrote:

> On 09/11/2018 03:09 AM, ToddAndMargo wrote:
> > multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos)
> >
> > Okay, I know that
> > Str is a string
> > Cool is an object that can be treated as both a string and a number
> > $needle is the second optional parameter
> >
> > What is "D"?
> >
> > $needle is optional, why is it not stated as "$needle?"
> >
> > How is both Str:D: and Cool:D the first parameter?
> >
> > Why does "Str:D:" have a colon on the end and "Cool:D" does not?
> >
> > What is Int(Cool:D) ?
> >
> > What is $pos ?
> >
> > Where is it stated that it has a return a value?
> >
> > Where is it state that the return value is a boolean?
> >
> > Yours in confusion,
> > -T
>
> First off, I band the heck out of "contains" all over my code.
> I know how it works.  What I don't know is how the documentation
> got there.
>
> Okay I am making progress.
>
> "multi method contains" means that it is a "method" (.foo).
> Perl 6 has "methods" `.foo` and subroutines `sub foo(...){...}`
>
> "Str:D" means it reads a string Str.contains(...) and
> that the string is mandatory (constrained).
>
> Okay, foul!
> Str:D: Cool:D $needle
> why is there not a comma between "Str:D:" and "Cool:D"?
> And what is with the extra ":".  By chance is the extra ":"
> a confusing way of using a comma for a separator?
>
> "Cool:D $needle" means that sub string or number you are
> looking for.  And it is constrained.  You must enter a value.
>
> Foul again!
> Int(Cool:D) $pos
> Why "Int(Cool:D)"?  Why is type Int being redefined
> as type "Cool" (number or any type or a string).
>
> $pos is the starting position to check for a match,
> start at zero.
>
> Foul!
> $pos is optional.  But there is a "D" in its definition
> making it constrained and not optional.
>
> And another foul!
> There is no stating what the return value is.  It
> should be of single value of type Bool.
>
> I am getting there.  Thank you all for the help.
>
> -T
>
>
>
>
>
>
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: A comparison between P5 docs and p6 docs

2018-09-11 Thread Simon Proctor
It's a very good read. :)

On Tue, 11 Sep 2018 at 16:19 Laurent Rosenfeld via perl6-users <
perl6-users@perl.org> wrote:

> Hi Todd,
>
> I fully agree with Tom B.'s message that you should really set out to read
> a Perl 6 book. Many of the things you asked are covered in most of the
> available books. And the available books are easier than the official
> documentation for a beginner to start understand the basic underlying
> concepts.
>
> I should add that you don't even have to *buy* one book, since my own *Think
> Perl 6* book is freely available on the Internet (Creative Commons
> license): https://greenteapress.com/wp/think-perl-6/. Well, if you are
> interested in reading it, I'd suggest you look for the PDF on my Github
> repository (https://github.com/LaurentRosenfeld/thinkperl6/tree/master/PDF),
> because it is more up-to-date (number of small corrections made following
> comments from readers).
>
> So it would take you just a few minutes (at no cost) to download it and
> start enjoying it.
>
> Cheers,
> Laurent.
>
> Le mar. 11 sept. 2018 à 13:26, ToddAndMargo  a
> écrit :
>
>> Hi All,
>>
>> Not to beat a dead horse, but Perl 6's docs are
>> miserably hard to understand.
>>
>> Here is a comparison of Perl 5's perldocs and Perl 6's
>> docs:
>>
>> Perl 5:
>>
>> $ perldoc -f index
>>  index STR,SUBSTR,POSITION
>>  index STR,SUBSTR
>> The index function searches for one string within another,
>> but without the wildcard-like behavior of a full regular-
>> expression pattern match. It returns the position of
>> the first occurrence of SUBSTR in STR at or after POSITION.
>> If POSITION is omitted, starts searching from the beginning
>> of the string. POSITION before the beginning of the string
>> or after its end is treated as if it were the beginning
>> or the end, respectively. POSITION and the return value
>> are based at zero. If the substring is not found, "index"
>> returns -1.
>>
>> Perl 6:
>>
>>  https://docs.perl6.org/routine/index
>>
>>  Documentation for sub index assembled from the following types:
>>  class Cool
>>
>>  From Cool
>>  (Cool) routine index
>>
>>  Defined as:
>>
>>  multi subindex(Str(Cool) $s, Str:D $needle, Int(Cool) $startpos
>> = 0 --> Int)
>>  multi method index(Str(Cool) $needle, Int(Cool) $startpos = 0 -->
>> Int)
>>
>>  Coerces the first two arguments (in method form, also counting
>>  the invocant) to Str, and searches for $needle in the string
>>  starting from $startpos. It returns the offset into the string
>>  where $needle was found, and an undefined value if it was not
>>  found.
>>
>>  See the documentation in type Str for examples.
>>
>>
>> "Cources"??? Seriously:
>>
>>  https://www.merriam-webster.com/dictionary/coerce
>>  Definition of coerce coerced; coercing
>> transitive verb
>> 1 : to compel to an act or choice
>> was coerced into agreeing
>> abusers who coerce their victims into silence
>>
>> 2 : to achieve by force or threat
>> coerce compliance
>> coerce obedience
>>
>> 3 : to restrain or dominate by force
>>
>> And what the heck is a "multi sub" and a "multi method" anyway?
>> AND WHY DO I EVEN CARE?  I just what to know how to use the
>> stinking thing!  Geepers Creapers !!!  (I am trying to avoid
>> swearing.)
>>
>> Perl 5's perldoc just tells you what you need to know to use the
>> stinker.  It is concise and to the point.  Perl 6 is a nightmare
>> to understand.
>>
>> Thank for putting up with my frustration.
>>
>> -T
>>
> --
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Functions and subroutines?

2018-09-11 Thread Simon Proctor
There are also Blocks like : my $a = do { 5 }; say $a; (Gives 5);

Blocks turn up all over the place big different between blocks and Routines
(Sub or Method) is you can't return from them. They will return the last
thing evaluated within them though. But a return statement inside one
raises and Expection. (Might be a Failure)...

On Tue, 11 Sep 2018 at 16:24 yary  wrote:

> And looking at questions in other threads- there are subroutines declared
> with "sub", those get called without an invocant.
>
> sub i-am-a-sub() { say "Hi from subroutine land!" }
>
> i-am-a-sub; # says "Hi from subroutine land!"
>
> and methods are declared inside a class, and are called with an invocant
> of that class type.
>
> class sample-class {
>   method speak-to-me {say "We are classy"}
> }
> my sample-class $object;
> $object. speak-to-me; # Guess what it says
>
> ... subroutines and methods, in the perl6 class hierarchy, are both
> subclasses "Routine"
> maybe that's the word your looking for!
>
> -y
>
> On Tue, Sep 11, 2018 at 8:12 AM, yary  wrote:
>
>> I would call them subroutines, since that's the long form of "sub"
>>
>> -y
>>
>> On Tue, Sep 11, 2018 at 3:47 AM, ToddAndMargo 
>> wrote:
>>
>>> Hi All,
>>>
>>> I use subs like ducks use water.  It is about time
>>> I learned what to properly call them.
>>>
>>> I come from Modula2 and Pascal (as well as bash), "functions"
>>> return a value outside the declared parameters and "(sub)routines"
>>> only can modify values through the declarations parameters.
>>>
>>> Sort of like
>>> function:   sub add($a, $b){return $a+$b}
>>> routine:sub add($a, $b, rw $c){$c = $a+$b}
>>>
>>> In Perl, what is the proper terminology?
>>>
>>> Many thanks,
>>> -T
>>>
>>> I no longer use "rw $c".  I always use "return".
>>> The guys told me this was the best way on the
>>> chat line, so I adopted it.
>>>
>>
>>
> --
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Please explain this to me

2018-09-11 Thread Simon Proctor
Also Todd I gave a talk on signatures types and multi methods at The Perl
Conference this year.

https://www.youtube.com/watch?v=Sy-qb5nXKyc=8606s

That should be just before the start.

https://www.slideshare.net/SimonProctor8/perl6-signatures-types-and-multicall

Slides are here.

Hope this helps.

Simon

On Tue, 11 Sep 2018 at 13:05 Simon Proctor  wrote:

> 1) why is it a "method" and not a "function"?
>
> methods are all on instance of a Class (or Role) they can locally access
> the instances data via self or $ or ... see below.
>
> 1-1/2) why is there a color after a$?  What happens to $a?
>
> You can as an extra option give your instance object a different name, you
> seperate that from the rest of the args with a :
>
> 2) What is an "invocant"?  Does it mean I can access it
> by placing it after something with a dot?  Sort of
> like
>  contains("abc", "b")
>  "abc".contians("b")
>
> The incovant is the object you invoke the method on. It's the thing that
> gets assigned to self, $ (and whatever else you want to call it)
>
> 3) What makes the "invocant" special over the other second
> and third parameters?
>
> See about
>
>  > class Foo {
>
> 4) I see no class called "Foo" over on
> https://docs.perl6.org/type.html
>
> That's a class being defined for this example
>
> 5) Are they creating a new class?  If so, why?
>
> To make an example
>
>  >method whoami($me:) {
>
> 6) where is @b and %c?
>
> In this case thet aren't being passed.
>
>
>  >"Well I'm class $me.^name(), of course!"
>
> 7) why is there a caret in front of "name"?
>
> There are certain Meta Object methods that are access with a ^ infront of
> the name. I'd need to check the exact definition though.
>
> Please note the Perl5 docs have had decades of people working on them the
> Perl6 ones less so. There's bound to be some difference in scope.
>
> On Tue, 11 Sep 2018 at 12:11 ToddAndMargo  wrote:
>
>> On 09/11/2018 03:30 AM, JJ Merelo wrote:
>> > Also, "is no help whatsoever" is no help whatsoever. Saying what part
>> of
>> > it is not clear enough, or could be explained better, is.
>> >
>>
>> Well now,
>>
>>  >  method ($a: @b, %c) {};   # first argument is the invocant
>>
>> 1) why is it a "method" and not a "function"?
>>
>> 1-1/2) why is there a color after a$?  What happens to $a?
>>
>> 2) What is an "invocant"?  Does it mean I can access it
>> by placing it after something with a dot?  Sort of
>> like
>>  contains("abc", "b")
>>  "abc".contians("b")
>>
>> 3) What makes the "invocant" special over the other second
>> and third parameters?
>>
>>  > class Foo {
>>
>> 4) I see no class called "Foo" over on
>> https://docs.perl6.org/type.html
>>
>> 5) Are they creating a new class?  If so, why?
>>
>>  >method whoami($me:) {
>>
>> 6) where is @b and %c?
>>
>>  >"Well I'm class $me.^name(), of course!"
>>
>> 7) why is there a caret in front of "name"?
>>
>>  >}
>>  >  }
>>  >
>>  >
>>  >  say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»
>>
>> 8) no clue how they got there
>>
>>
>> JJ, have you ever used Perl 5's perldocs?  They are a bazillion
>> times easier to understand than Perl 6's.
>>
>> Thank you for the help with this?
>>
>> -T
>>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Please explain this to me

2018-09-11 Thread Simon Proctor
 1) why is it a "method" and not a "function"?

methods are all on instance of a Class (or Role) they can locally access
the instances data via self or $ or ... see below.

1-1/2) why is there a color after a$?  What happens to $a?

You can as an extra option give your instance object a different name, you
seperate that from the rest of the args with a :

2) What is an "invocant"?  Does it mean I can access it
by placing it after something with a dot?  Sort of
like
 contains("abc", "b")
 "abc".contians("b")

The incovant is the object you invoke the method on. It's the thing that
gets assigned to self, $ (and whatever else you want to call it)

3) What makes the "invocant" special over the other second
and third parameters?

See about

 > class Foo {

4) I see no class called "Foo" over on
https://docs.perl6.org/type.html

That's a class being defined for this example

5) Are they creating a new class?  If so, why?

To make an example

 >method whoami($me:) {

6) where is @b and %c?

In this case thet aren't being passed.


 >"Well I'm class $me.^name(), of course!"

7) why is there a caret in front of "name"?

There are certain Meta Object methods that are access with a ^ infront of
the name. I'd need to check the exact definition though.

Please note the Perl5 docs have had decades of people working on them the
Perl6 ones less so. There's bound to be some difference in scope.

On Tue, 11 Sep 2018 at 12:11 ToddAndMargo  wrote:

> On 09/11/2018 03:30 AM, JJ Merelo wrote:
> > Also, "is no help whatsoever" is no help whatsoever. Saying what part of
> > it is not clear enough, or could be explained better, is.
> >
>
> Well now,
>
>  >  method ($a: @b, %c) {};   # first argument is the invocant
>
> 1) why is it a "method" and not a "function"?
>
> 1-1/2) why is there a color after a$?  What happens to $a?
>
> 2) What is an "invocant"?  Does it mean I can access it
> by placing it after something with a dot?  Sort of
> like
>  contains("abc", "b")
>  "abc".contians("b")
>
> 3) What makes the "invocant" special over the other second
> and third parameters?
>
>  > class Foo {
>
> 4) I see no class called "Foo" over on
> https://docs.perl6.org/type.html
>
> 5) Are they creating a new class?  If so, why?
>
>  >method whoami($me:) {
>
> 6) where is @b and %c?
>
>  >"Well I'm class $me.^name(), of course!"
>
> 7) why is there a caret in front of "name"?
>
>  >}
>  >  }
>  >
>  >
>  >  say Foo.whoami; # OUTPUT: «Well I'm class Foo, of course!␤»
>
> 8) no clue how they got there
>
>
> JJ, have you ever used Perl 5's perldocs?  They are a bazillion
> times easier to understand than Perl 6's.
>
> Thank you for the help with this?
>
> -T
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: how do I do this index in p6?

2018-09-11 Thread Simon Proctor
Why not use contains though?

perl6 -e 'say "abc".contains("z")'
False

Use index if the index is important. Use contains if you just want to know
if it's there.


On Tue, 11 Sep 2018 at 10:57 JJ Merelo  wrote:

> perl6 -e 'say "abc".index("z") =:= Nil  ?? "False" !! "True"'
>
> -e runs the script from the CL
> https://github.com/rakudo/rakudo/wiki/Running-rakudo-from-the-command-line
> "abc" is on front (but it could be in the same way)
> index return Nil if it does not found (more logical than -1)
> https://docs.perl6.org/routine/index; it's a constant, so you have to use
> =:= to check for equality. https://docs.perl6.org/routine/=:=
> ??!! is the ternary operator in Perl 6
> https://docs.perl6.org/language/operators#index-entry-operator_ternary-ternary_operator
>
>
> JJ
> PS: ObStackOverflow plug.
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: use Moo:from;

2018-09-06 Thread Simon Proctor
Well I got a bit further but I am also thinking about how I'd do it.

On Thu, 6 Sep 2018, 14:47 Vadim Belman,  wrote:

>
>
> 1. There is currently a bug (or bugs) about wrapped methods –
> https://github.com/rakudo/rakudo/issues/2178
> get_value() is unlikely to be wrapped. But potential issues are possible
> as it seems that the bug is not only related to method inheritance.
>
>
> Oops, correction: "get_value() is unlikely to be inherited". Sorry.
>
> Best regards,
> Vadim Belman
>
> --
Simon Proctor
Cognoscite aliquid novum cotidie


Re: use Moo:from;

2018-09-06 Thread Simon Proctor
Done a bit of noodling about this morning and I got this. And it works
sort of.

.perl calls the get_value method but the accessor and private value reads
don't. (I'm guessing this is what you came up against Vadim?)

Still the self deleting wrapper is a fun trick. Best I do some work now
though.

use v6.c;

role LazyAttr {
has $.get-wrapper is rw;
}

multi sub trait_mod: ( Attribute $a, :@lazy [  ] ) {
$a does LazyAttr;

$a.set_build(
-> |c {
$a.get-wrapper = $a.^find_method('get_value').wrap(
-> $self, $instance {
my $val = ( $instance );
$a.set_value( $instance, $val );
$a.get-wrapper.restore;
$val;
}
);
Any;
}
);
}

class Test {

sub build-a( $self ) { note "Build A Called"; sleep 1; 5 }
sub build-b( $self ) { note "Build B Called"; sleep 2; 10 }

has $.a is lazy[];
has $.b is lazy[];
}

my $t = Test.new();

say $t.perl;

On Wed, 5 Sep 2018 at 23:45 Vadim Belman  wrote:

> Looking forward to see what you come up with. I do mix in a role into both
> Attribute and ClassHOW. But delving into the core didn't help to find a
> better approach than the one I finally took. Two subtle aspects are to be
> kept in mind: support for roles; and knowing the object attribute is
> belonging to.
>
> > So I have a thought for how to do lazy attributes without Proxy objects.
> It is late so I'll try and poke about at it tomorrow but I think we can
> Mixin a role to the Attribute using a trait.
> >
> > The role will track if the attribute was set to a value at build and if
> not call a block it's given when first read from. This gets round the issue
> of if we want to set it to Any.
> >
> > I *think* this will work. The stuff I've been doing with Trait::Env
> would point that way.
> >
>
> Best regards,
> Vadim Belman
>
> --
Simon Proctor
Cognoscite aliquid novum cotidie


Re: curious effects in debugging

2018-08-16 Thread Simon Proctor
How did you copy the project over? I am wondering if the copy added some
bogus characters.

On Thu, 16 Aug 2018, 09:40 Theo van den Heuvel, 
wrote:

> Hi Perl6 people,
>
> Yesterday I moved my Perl6 project to another machine on which I had
> first installed:
>
> $
> This is Rakudo Star version 2018.06 built on MoarVM version 2018.06
>
>
> Both machines have Ubuntu 16.04.
>
> Two things (related?):
>
> 1. I cannot use arrow keys (and hence line editing) while debugging. I
> have Linenoise installed. I tried setting RAKUDO_LINE_EDITOR to that,
> but to no avail. Why? I am aware that this could be a Linux thing. I am
> a novice on that field. Anyway I get this when I use arrow up:
>
> > ^[[A
>
>
> 2. The debugger reports lots of bugs like the one below, having to do
> with the use of comments in grammars, although the per6 engine is fine
> with it.  Why?
>
> $
> Strange text after block (missing semicolon or comma?)
> at /home/theo/projects//create_nested_fun_count.pl6:78
> -->   token ConstNum { <[0 .. 9 . ]> + }⏏ # negative values via
> AddExpr
>  expecting any of:
>  infix
>  infix stopper
>  postfix
>  statement end
>      statement modifier
>  statement modifier loop
>
>
> thanks,
>
>
> --
> Theo van den Heuvel
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: is there a limit to a s/ ?

2018-08-11 Thread Simon Proctor
One thing your example you'll lose the second <\div>.

ff is great for working though lines of data. Going back to your previous
example say we have a file like.

A
B
C
D
E
F
G

And we want to print the lines from C to F we can write.

for "file".IO.lines {
   print if /C/ ff /F/;
}

Each line in the file is assigned to $_. If ff has not seen the LHS (so C)
yet it will compare the line to that if it matches (and it doesn't match
the RHS) it returns True. It continues to return True until the line
matches the RHS. At which point I *think* it resets to Looking for the LHS
and returning False.

The more I think about ff and fff the more I'm mind blown, operators that
remember state? Whacky.

But anyway I hope that helped a bit. The gather example might be closer to
what you're looking for, putting lines into an array for further looking at.

Or Take a look at DOM::Tiny which might also help you out.

Hope that helped, I should get up and start the drive to Scotland soon.

On Sat, 11 Aug 2018, 06:41 ToddAndMargo,  wrote:

> On 08/10/2018 08:59 PM, ToddAndMargo wrote:
> >
> >> On Fri, Aug 10, 2018 at 8:16 PM, ToddAndMargo 
> >> wrote:
> >>> Hi All,
> >>>
> >>> I was thinking of doing a
> >>>
> >>> $ p6 'my $x="a\nb\nc\nd\n"; say "$x\n"; $x ~~ s/ .*?c /c/; say "$x";'
> >>> a
> >>> b
> >>> c
> >>> d
> >>>
> >>>
> >>> c
> >>> d
> >>>
> >>>
> >>> Except the real deal will be across 1460 lines.  Am I pushing the
> >>> limits?
> >>>
> >>> There are other ways of doing what I want.
> >>>
> >>>
> >>> Many thanks,
> >>> -T
> >
> >
> > On 08/10/2018 08:29 PM, yary wrote:
> >  > 1460 lines, at an average of say, oh, 70 characters per line, that's
> >  > oh 100k or so? Sounds like a piece of cake... try it and see
> >  > -y
> >  >
> >  >
> >
> > Hi Yary,
> >
> > I will.
> >
> > This is what I am after:
> >
> >  
> >  Version:*
> >
> >  
> >  
> >   >  >9.2.0.92978.3.6.35572
> >  
> >      
> >  
> >
> >
> > $WebPage ~~ s/ . * ''//;
> > $WebPage ~~ s/ '' .* //;
> >
> >
> > Then
> >
> > ( $NewRev  = $Webpage ) ~~ s/ .*? ' >
> > I may have to fuss with the escapes.
> >
> > I do so adore Perl!
> >
> > :-)
> >
> > -T
>
>
> I have done this with two web pages already.  Perl 6
> eat its lunch!
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: is there a limit to a s/ ?

2018-08-10 Thread Simon Proctor
It's 5am and I should be asleep but I think this is a perfect case for ff
then.

Check out the docs for it.

On Sat, 11 Aug 2018, 05:01 ToddAndMargo,  wrote:

> On 08/10/2018 08:56 PM, Simon Proctor wrote:
> > If all you are wanting to do is print the lines after a certain point in
> > the file the ff operator might be what you're looking for.
>
> See my response to Yary to see what I am after.
>
> Thank you!
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Why use dd to convert a string to an integer?

2018-08-07 Thread Simon Proctor
Moarvm is the Perl6 Virtual Machine that is one of the targets Rakudo
compiles to (the JVM is another).

Basically at the moment when people talk about Perl6 that mostly mean Perl6
compiled with Rakudo running on MoarVM.

(As I understand it).

the dd bit was not in the example as part of string -> int conversion but
to demonstrate the result.

On Tue, 7 Aug 2018 at 08:32 ToddAndMargo  wrote:

> >> On Tue, 7 Aug 2018, 08:16 ToddAndMargo,  >> <mailto:toddandma...@zoho.com>> wrote:
> >>
> >> Hi All,
> >>
> >> I am confused.
> >>
> >> This line will convert a string into an integer, but
> >> will print out and extra line with "(Int)" on it:
> >>
> >>  $ p6 'my Str $x = "5"; my Int $y = dd +$x; say $y'
> >>  5
> >>  (Int)
> >>
> >>
> >> This will convert as well, but no extra line:
> >>
> >>  $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say $x'
> >>  5
> >>
> >>
> >> Also, I can quote $x, and it still works:
> >>
> >>  $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say "$x"'
> >>  5
> >>
> >>
> >> But this tells me I have an uninitialized value, when all
> >> I did was add quotes around $y, as in the above line.
> >>
> >>  $ p6 'my Str $x = "5"; my Int $y = dd +$x; say "$y";'
> >>  5
> >>  Use of uninitialized value $y of type Int in string context.
> >>  Methods .^name, .perl, .gist, or .say can be used to stringify
> >>  it to something meaningful.
> >>
> >>
> >> Why would I want to use "dd"?
> >>
> >> Many thanks,
> >> -T
> >>
>
> On 08/07/2018 12:19 AM, Simon Proctor wrote:
> > dd is the moarvm specific data dump command. You don't need it.
> >
> > --
> > Simon Proctor
> > Cognoscite aliquid novum cotidie
>
> Thank you!
>
> What is "moarvm"
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Why use dd to convert a string to an integer?

2018-08-07 Thread Simon Proctor
dd is the moarvm specific data dump command. You don't need it.

On Tue, 7 Aug 2018, 08:16 ToddAndMargo,  wrote:

> Hi All,
>
> I am confused.
>
> This line will convert a string into an integer, but
> will print out and extra line with "(Int)" on it:
>
> $ p6 'my Str $x = "5"; my Int $y = dd +$x; say $y'
> 5
> (Int)
>
>
> This will convert as well, but no extra line:
>
> $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say $x'
> 5
>
>
> Also, I can quote $x, and it still works:
>
> $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say "$x"'
> 5
>
>
> But this tells me I have an uninitialized value, when all
> I did was add quotes around $y, as in the above line.
>
> $ p6 'my Str $x = "5"; my Int $y = dd +$x; say "$y";'
> 5
> Use of uninitialized value $y of type Int in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify
> it to something meaningful.
>
>
> Why would I want to use "dd"?
>
> Many thanks,
> -T
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: start up delay?

2018-08-06 Thread Simon Proctor
So Perl6 is a lot like Python in that modules get compiled to byte code
making them a lot faster to parse the second time around.

If you're running a 6000 line script then a lot of time is going to be
spent parsing your script every time you run it. If you instead take all
your script code and pop it into a module and have a script along the lines
of :

use lib "./";
use System;

System::start();

(Where your module code is called System.pm6 and start is the entry point
subroutine).

I think you'd find this improves the speed of the script significantly.

On Mon, 6 Aug 2018 at 10:38 ToddAndMargo  wrote:

> On 08/06/2018 02:07 AM, ToddAndMargo wrote:
> > On 08/06/2018 01:02 AM, Simon Proctor wrote:
> >> Sorry I wrote my earlier email on my phone without a computer to hand.
> >> Here's a quick rundown on what I'm talking about.
> >>
> >> --stagestats gives you the breakdown on how much time is spent doing
> >> various steps (note that using time instead of date; date gives you a
> >> better timing of how long something took.
> >>
> >> time perl6 --stagestats -e ""
> >> Stage start  :   0.000
> >> Stage parse  :   0.089
> >> Stage syntaxcheck:   0.000
> >> Stage ast:   0.000
> >> Stage optimize   :   0.001
> >> Stage mast   :   0.004
> >> Stage mbc:   0.000
> >> Stage moar   :   0.000
> >>
> >> real0m0.144s
> >> user0m0.155s
> >> sys0m0.032s
> >>
> >> And generally that's going to be the case for most short programs, in
> >> these cases especially moving to having the core of your code in
> >> modules with give you a speed boost.
> >>
> >> Sorry if my comments earlier were unhelpful.
> >>
> >> Simon
> >>
> >> On Mon, 6 Aug 2018 at 08:56 ToddAndMargo  >> <mailto:toddandma...@zoho.com>> wrote:
> >>
> >>  >> On Sun, 5 Aug 2018, 23:45 Elizabeth Mattijsen,  >> <mailto:l...@wenzperl.nl>
> >>  >> <mailto:l...@wenzperl.nl <mailto:l...@wenzperl.nl>>> wrote:
> >>  >>
> >>  >>  > On 1 Aug 2018, at 20:14, ToddAndMargo
> >> mailto:toddandma...@zoho.com>
> >>  >> <mailto:toddandma...@zoho.com
> >> <mailto:toddandma...@zoho.com>>> wrote:
> >>  >>  > Is it just me or does Perl 6 take about three times as
> >> long to
> >>  >>  > start up as Perl 5?  I do have a very fast machine and it
> >> takes
> >>  >>  > about seven see for some of my Perl 6 stuff to get past
> >> the
> >>  >>  > ruminating phase and start running.
> >>  >>
> >>  >> Seven seconds?  Seven?  That seems *very* long indeed.
> >>  >>
> >>      >>     How long does it take to do:
> >>  >>
> >>  >>     perl6 -e ‘’
> >>  >>
> >>  >> ?  That should be in the order of 130 msecs.  If that’s the
> >> case,
> >>  >> then you’re probably doing a lot of grammar changes to Perl
> >> 6.  But
> >>  >> without the actual code, this remains guessing.
> >>  >>
> >>  >>
> >>  >>  > Any workaround for this, or is this just growing pains
> >> for Perl 6?
> >>  >>
> >>  >> Not sure  :-)
> >>  >>
> >>  >>
> >>  >>
> >>  >> Liz
> >>  >>
> >>  >> --
> >>  >> Simon Proctor
> >>  >> Cognoscite aliquid novum cotidie
> >>
> >> On 08/05/2018 10:57 PM, Simon Proctor wrote:
> >>  > Have you tried running with --stagestats which gives you a break
> >> down of
> >>  > where the time is being spent?
> >>  >
> >>  > On thing is if you are running large script files it came take a
> >> while.
> >>  > Moving your code into modules, which get precompiled can give a
> >>  > significant speed boost.
> >>
> >> Does this tell you anything?
> >>
> >> $ curl --fail --head https://google.com; echo $?
> >> HTTP/2 301
> >> location: https://www.google.com/
> >> content-type: text/html; charset=UTF-8
> >> date: Mon, 06 Aug 2018 05:19:51 GMT
> >> expires: Wed, 05 Sep 2018 05:19:51 GMT
> >> cache-control: public, max-age=2592000
> >> server: gws
> >> content-length: 220
> >> x-xss-protection: 1; mode=block
> >> x-frame-options: SAMEORIGIN
> >> alt-svc: quic=":443"; ma=2592000; v="44,43,39,35"
> >>
> >> 0
> >>
> >> --
> >> Simon Proctor
> >> Cognoscite aliquid novum cotidie
> >
> > real0m14.580s
> > user0m13.723s
> > sys0m0.418s
>
>
> The program is 6160 line long plus a bunch of imported
> modules.
>
> The Perl 5 version of this program that starts three
> times faster is 6354 lines long plus a bunch if imported
> modules.
>
> The slow start is not a reason to go back to p5 for
> any reason.  It would just be nice if it started faster.
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: start up delay?

2018-08-06 Thread Simon Proctor
Sorry I wrote my earlier email on my phone without a computer to hand.
Here's a quick rundown on what I'm talking about.

--stagestats gives you the breakdown on how much time is spent doing
various steps (note that using time instead of date; date gives you a
better timing of how long something took.

time perl6 --stagestats -e ""
Stage start  :   0.000
Stage parse  :   0.089
Stage syntaxcheck:   0.000
Stage ast:   0.000
Stage optimize   :   0.001
Stage mast   :   0.004
Stage mbc:   0.000
Stage moar   :   0.000

real0m0.144s
user0m0.155s
sys0m0.032s

And generally that's going to be the case for most short programs, in these
cases especially moving to having the core of your code in modules with
give you a speed boost.

Sorry if my comments earlier were unhelpful.

Simon

On Mon, 6 Aug 2018 at 08:56 ToddAndMargo  wrote:

> >> On Sun, 5 Aug 2018, 23:45 Elizabeth Mattijsen,  >> <mailto:l...@wenzperl.nl>> wrote:
> >>
> >>  > On 1 Aug 2018, at 20:14, ToddAndMargo  >> <mailto:toddandma...@zoho.com>> wrote:
> >>  > Is it just me or does Perl 6 take about three times as long to
> >>  > start up as Perl 5?  I do have a very fast machine and it takes
> >>  > about seven see for some of my Perl 6 stuff to get past the
> >>  > ruminating phase and start running.
> >>
> >> Seven seconds?  Seven?  That seems *very* long indeed.
> >>
> >> How long does it take to do:
> >>
> >> perl6 -e ‘’
> >>
> >> ?  That should be in the order of 130 msecs.  If that’s the case,
> >> then you’re probably doing a lot of grammar changes to Perl 6.  But
> >> without the actual code, this remains guessing.
> >>
> >>
> >>  > Any workaround for this, or is this just growing pains for Perl
> 6?
> >>
> >> Not sure  :-)
> >>
> >>
> >>
> >> Liz
> >>
> >> --
> >> Simon Proctor
> >> Cognoscite aliquid novum cotidie
>
> On 08/05/2018 10:57 PM, Simon Proctor wrote:
> > Have you tried running with --stagestats which gives you a break down of
> > where the time is being spent?
> >
> > On thing is if you are running large script files it came take a while.
> > Moving your code into modules, which get precompiled can give a
> > significant speed boost.
>
> Does this tell you anything?
>
> $ curl --fail --head https://google.com; echo $?
> HTTP/2 301
> location: https://www.google.com/
> content-type: text/html; charset=UTF-8
> date: Mon, 06 Aug 2018 05:19:51 GMT
> expires: Wed, 05 Sep 2018 05:19:51 GMT
> cache-control: public, max-age=2592000
> server: gws
> content-length: 220
> x-xss-protection: 1; mode=block
> x-frame-options: SAMEORIGIN
> alt-svc: quic=":443"; ma=2592000; v="44,43,39,35"
>
> 0
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: start up delay?

2018-08-05 Thread Simon Proctor
Have you tried running with --stagestats which gives you a break down of
where the time is being spent?

On thing is if you are running large script files it came take a while.
Moving your code into modules, which get precompiled can give a significant
speed boost.

On Sun, 5 Aug 2018, 23:45 Elizabeth Mattijsen,  wrote:

> > On 1 Aug 2018, at 20:14, ToddAndMargo  wrote:
> > Is it just me or does Perl 6 take about three times as long to
> > start up as Perl 5?  I do have a very fast machine and it takes
> > about seven see for some of my Perl 6 stuff to get past the
> > ruminating phase and start running.
>
> Seven seconds?  Seven?  That seems *very* long indeed.
>
> How long does it take to do:
>
>perl6 -e ‘’
>
> ?  That should be in the order of 130 msecs.  If that’s the case, then
> you’re probably doing a lot of grammar changes to Perl 6.  But without the
> actual code, this remains guessing.
>
>
> > Any workaround for this, or is this just growing pains for Perl 6?
>
> Not sure  :-)
>
>
>
> Liz

-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Catching exceptions in expressions

2018-08-03 Thread Simon Proctor
Hi Sean. I hope my second answer in stackoverflow gets closer to what you
want.

I am still trying to think of a more idiomatic way of handling to situation.



On Fri, 3 Aug 2018, 19:29 Sean McAfee,  wrote:

> I posted about this subject on Stack Overflow yesterday[1], but I chose a
> poor example of something that raises an exception (dividing by zero, which
> apparently doesn't necessarily do so) on which the answers have mostly
> focused.
>
> I was looking for a way to evaluate an expression, and if the expression
> threw an exception, for a default value to be provided instead.  For
> example, in Ruby:
>
> quotient = begin; a / b; rescue; -1; end
>
> Or in Lisp:
>
> (setq quotient (condition-case nil (/ a b) (error -1)))
>
> Not having written much exception-related code in Perl 6, I hoped that
> this might work:
>
> sub divide($a, $b) { die "Zero denominator" if $b == 0; $a / $b }
> my $quotient = do { divide($a, $b); CATCH { default { -1 } } };
>
> It doesn't, though.  As far as I can tell, the value to which a CATCH
> block evaluates is ignored; the only useful things one can do in such a
> block are things with side effects.  Long story short, I eventually came up
> with this:
>
> my $quotient = do { my $q; { $q = divide($a, $b); CATCH { default { $q
> = -1 } } }; $q };
>
> That's far more verbose than I've come to expect from Perl 6.  Is there
> some more concise way of expressing this logic?
>
> The doc page on exceptions mentions try, eg:
>
> my $quotient = try { divide($a, $b) } // -1;
>
> That works in this specific case, but it seems insufficient in general.
> The function might validly return an undefined value, and this construction
> can't distinguish between that and an exception.  Also, it wouldn't let me
> distinguish among various exception cases.  I'd have to do something like:
>
> class EA is Exception { }
> class EB is Exception { }
> sub divide($a, $b) { (EA, EB).pick.new.throw if $b == 0; $a / $b }
>
> my $quotient = do { my $q; { $q = divide($a, $b); CATCH { when EA { $q
> = -1 }; when EB { $q = -2 } } }; $q };
>
>
> [1]
> https://stackoverflow.com/questions/51644197/returning-values-from-exception-handlers-in-perl-6/51670573
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: -c bug to report

2018-07-25 Thread Simon Proctor
Problem is that's not a syntax error as such. Running with stage stats you
can see where -c stop and where the error is thrown.

(I'm sure someone with deeper VM understanding can explain is better).

perl6 --stagestats -e 'sub foo($a, $b) { say "Hmm" };foo(1,2,"3")'
Stage start  :   0.000
Stage parse  :   0.116
Stage syntaxcheck:   0.000
Stage ast:   0.000
Stage optimize   : ===SORRY!=== Error while compiling -e
Calling foo(Int, Int, Str) will never work with declared signature ($a, $b)
at -e:1
--> sub foo($a, $b) { say "Hmm" };⏏foo(1,2,"3")
perl6 --stagestats -ce 'sub foo($a, $b) { say "Hmm" };foo(1,2,"3")'
Stage start  :   0.000
Stage parse  :   0.110
Stage syntaxcheck: Syntax OK



On Wed, 25 Jul 2018 at 09:26 ToddAndMargo  wrote:

> Dear Developers,
>
> $ perl6 -v
> This is Rakudo version 2018.05 built on MoarVM version 2018.05
> implementing Perl 6.c.
>
> `Perl6 -c xxx.pl6` passes
>
>   if IsCurrentRevNewer ( $OldRev, $NewRev, $SubName, "no", "quiet" )
>
> when the sub it calls only has three variables in it header, not five:
>
>   sub IsCurrentRevNewer(
>  $Caller,  # who called this function
>  $LatestRev,   # Latest Revision
>  $OldRev ) {   # Old Revision
>
>
> -T
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: need s/ help

2018-05-01 Thread Simon Proctor
So what you what to match is a followed by zero or more not a's and then
the end of the string.

<[a]> is the perl6 regex for a range comprising of a alone you can negate
that like so <-[a]>

Giving us

perl6 -e 'my $x="abcabcabc"; $x ~~ s/a <-[a]>* $/xyz/; say $x;'

(There's probably a better way, this was just my first attempt)

On Tue, 1 May 2018 at 14:37 ToddAndMargo  wrote:

> Hi All,
>
> I am trying to change the last three letters of a string
>
> $ perl6 -e 'my $x="abcabcabc"; $x ~~ s/"a.*"$/xyz/; say $x;'
> abcabcabc
>
> I want abcabcxyz
>
> And, in real life, only the "a" will be a know letter.
> Everything else will vary.  And the "a" will repeat a lot.
> I am only interested in changing the last "a" and everything
> that comes after it.
>
> Many thanks,
> -T
>


Re: Module wishlist priorities

2017-12-29 Thread Simon Proctor
Where is the wishlist?

On Fri, 29 Dec 2017 at 20:12 Michael Stemle  wrote:

> I just finished a module from the wishlist. I’d like to pick up another.
> Is this a good place to discuss priorities for the existing wishlist, or in
> general?
>
> I didn’t see an obvious list for this topic.
>
> Many thanks.
>
> ~ Michael D. Stemle, Jr.


Re: Forcing a Positional role

2017-10-28 Thread Simon Proctor
Maybe a given block then? I generally go for brute force first.

On Sat, 28 Oct 2017, 9:21 pm Fernando Santagata, <nando.santag...@gmail.com>
wrote:

> Yes, the size of the object would change. In any case, I can't use a Perl6
> Array in a NativeCall class, so the point is moot.
>
> The problem is that that C library exposes an API, whose main structure
> contains an array of five pointers to another kind of struct.
> It is not a pointer to an array of pointers, but just an array of
> pointers. So the struct contains an array of five pointers. (Does it sound
> weird? :-) I really don't know why they designed that data container that
> way)
>
> On Sat, Oct 28, 2017 at 9:47 PM, Simon Proctor <simon.proc...@gmail.com>
> wrote:
>
>> Ahhh.. H. Even with the array as a private variable?
>>
>> On Sat, 28 Oct 2017, 8:41 pm Fernando Santagata, <
>> nando.santag...@gmail.com> wrote:
>>
>>> Hello Simon,
>>> Thank you for your reply.
>>>
>>> I would use an array if I hadn't the constraint that in a NativeCall
>>> class I can't use a Perl6 Array, just a CArray.
>>> Anyway I couldn't add a CArray to the class, because it would change its
>>> size and I need to pass the reference to that class to a C function.
>>>
>>> On Sat, Oct 28, 2017 at 1:58 PM, Simon Proctor <simon.proc...@gmail.com>
>>> wrote:
>>>
>>>> Here's my very naive way of doing it.
>>>>
>>>> class A does Positional {
>>>>   has $.a0 is rw;
>>>>   has $.a1 is rw;
>>>>   has $.a2 is rw;
>>>>   has $.a3 is rw;
>>>>   has $.a4 is rw;
>>>>   has $.a5 is rw;
>>>>   has @!arr;
>>>>
>>>>   method TWEAK {
>>>> @!arr[0] := $.a0;
>>>> @!arr[1] := $.a1;
>>>> @!arr[2] := $.a2
>>>> <https://maps.google.com/?q=2%5D+:%3D+$.a2=gmail=g>;
>>>> @!arr[3] := $.a3
>>>> <https://maps.google.com/?q=3%5D+:%3D+$.a3=gmail=g>;
>>>> @!arr[4] := $.a4;
>>>> @!arr[5] := $.a5
>>>> <https://maps.google.com/?q=5%5D+:%3D+$.a5=gmail=g>;
>>>>   }
>>>>   multi method elems() { 6 }
>>>>   multi method AT-POS( $index ) {
>>>>   return @!arr[$index];
>>>>   }
>>>>   multi method ASSIGN-POS( $index, $new ) {
>>>>   @!arr[$index] = $new;
>>>>   }
>>>> }
>>>>
>>>> On Sat, 28 Oct 2017 at 09:45 Fernando Santagata <
>>>> nando.santag...@gmail.com> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I was trying to write a NativeCall interface to a C library, but I
>>>>> stumbled upon a problem (
>>>>> https://stackoverflow.com/questions/44266457/array-of-structs-as-an-attribute-of-a-perl-6-nativecall-struct
>>>>> ).
>>>>> The best way to solve that problem would be to add a new keyword to
>>>>> the NativeCall module, which I think is quite hard, so I'm trying a less
>>>>> fancy alternative.
>>>>>
>>>>> The problem itself looks like this: I have a class with a bunch of
>>>>> elements which I would like to access as an array (I can't use a Perl6
>>>>> Array in a NativeCall class).
>>>>>
>>>>> Reducing the problem to the bare bones, my class looks like
>>>>>
>>>>> Class A {
>>>>>   has $.a0 is rw;
>>>>>   has $.a1 is rw;
>>>>>   has $.a2 is rw;
>>>>>   has $.a3 is rw;
>>>>>   has $.a4 is rw;
>>>>> }
>>>>>
>>>>> My first attempt was to use meta methods to access the attributes:
>>>>>
>>>>> class A does Positional {
>>>>>   has $.a0 is rw;
>>>>>   has $.a1 is rw;
>>>>>   has $.a2 is rw;
>>>>>   has $.a3 is rw;
>>>>>   has $.a4 is rw;
>>>>>   method AT-POS($index) is rw {
>>>>> my $a = A.^attributes(:local)[$index];
>>>>> $a.get_value(self);
>>>>>   }
>>>>> }
>>>>>
>>>>> This works if I just need to read the values, but if I needed to write
>>>>> them I should use the set_value metamethod:
>>>>>
>>>>> $a.set_value(self, $value);
>>&

Re: Forcing a Positional role

2017-10-28 Thread Simon Proctor
Ahhh.. H. Even with the array as a private variable?

On Sat, 28 Oct 2017, 8:41 pm Fernando Santagata, <nando.santag...@gmail.com>
wrote:

> Hello Simon,
> Thank you for your reply.
>
> I would use an array if I hadn't the constraint that in a NativeCall class
> I can't use a Perl6 Array, just a CArray.
> Anyway I couldn't add a CArray to the class, because it would change its
> size and I need to pass the reference to that class to a C function.
>
> On Sat, Oct 28, 2017 at 1:58 PM, Simon Proctor <simon.proc...@gmail.com>
> wrote:
>
>> Here's my very naive way of doing it.
>>
>> class A does Positional {
>>   has $.a0 is rw;
>>   has $.a1 is rw;
>>   has $.a2 is rw;
>>   has $.a3 is rw;
>>   has $.a4 is rw;
>>   has $.a5 is rw;
>>   has @!arr;
>>
>>   method TWEAK {
>> @!arr[0] := $.a0;
>> @!arr[1] := $.a1;
>> @!arr[2] := $.a2
>> <https://maps.google.com/?q=2%5D+:%3D+$.a2=gmail=g>;
>> @!arr[3] := $.a3
>> <https://maps.google.com/?q=3%5D+:%3D+$.a3=gmail=g>;
>> @!arr[4] := $.a4;
>> @!arr[5] := $.a5
>> <https://maps.google.com/?q=5%5D+:%3D+$.a5=gmail=g>;
>>   }
>>   multi method elems() { 6 }
>>   multi method AT-POS( $index ) {
>>   return @!arr[$index];
>>   }
>>   multi method ASSIGN-POS( $index, $new ) {
>>   @!arr[$index] = $new;
>>   }
>> }
>>
>> On Sat, 28 Oct 2017 at 09:45 Fernando Santagata <
>> nando.santag...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I was trying to write a NativeCall interface to a C library, but I
>>> stumbled upon a problem (
>>> https://stackoverflow.com/questions/44266457/array-of-structs-as-an-attribute-of-a-perl-6-nativecall-struct
>>> ).
>>> The best way to solve that problem would be to add a new keyword to the
>>> NativeCall module, which I think is quite hard, so I'm trying a less fancy
>>> alternative.
>>>
>>> The problem itself looks like this: I have a class with a bunch of
>>> elements which I would like to access as an array (I can't use a Perl6
>>> Array in a NativeCall class).
>>>
>>> Reducing the problem to the bare bones, my class looks like
>>>
>>> Class A {
>>>   has $.a0 is rw;
>>>   has $.a1 is rw;
>>>   has $.a2 is rw;
>>>   has $.a3 is rw;
>>>   has $.a4 is rw;
>>> }
>>>
>>> My first attempt was to use meta methods to access the attributes:
>>>
>>> class A does Positional {
>>>   has $.a0 is rw;
>>>   has $.a1 is rw;
>>>   has $.a2 is rw;
>>>   has $.a3 is rw;
>>>   has $.a4 is rw;
>>>   method AT-POS($index) is rw {
>>> my $a = A.^attributes(:local)[$index];
>>> $a.get_value(self);
>>>   }
>>> }
>>>
>>> This works if I just need to read the values, but if I needed to write
>>> them I should use the set_value metamethod:
>>>
>>> $a.set_value(self, $value);
>>>
>>> The detail I miss is: how do I know whether the AT-POS method has been
>>> called to produce an rvalue or an lvalue?
>>>
>>> The second attempt was to use a Proxy object:
>>>
>>> class A does Positional {
>>>   has $.a0 is rw;
>>>   has $.a1 is rw;
>>>   has $.a2 is rw;
>>>   has $.a3 is rw;
>>>   has $.a4 is rw;
>>>   method AT-POS(::?CLASS:D: $index) is rw {
>>> my $a = A.^attributes(:local)[$index];
>>> Proxy.new(
>>>   FETCH => method () { $a.get_value(self) },
>>>   STORE => method ($value) { $a.set_value(self, $value) }
>>> );
>>>   }
>>> }
>>>
>>> sub MAIN
>>> {
>>>   my A $a .= new;
>>>   $a.a0 = 0;
>>>   $a.a1 = 1;
>>>   say $a[0];
>>>   say $a[1];
>>>   say $a[2];
>>>   $a[0] = 42;
>>>   say $a[0];
>>> }
>>>
>>> But this program just hangs.
>>> When run in the debugger I get this:
>>>
>>> >>> LOADING Proxy.p6
>>> + Exception Thrown
>>> | Died
>>> + Proxy.p6 (25 - 29)
>>> | }
>>> |
>>> | sub MAIN
>>> | {
>>> |   my A $a .= new;
>>>
>>> I'm clueless here.
>>> What am I doing wrong?
>>> Can anyone help?
>>>
>>> Thank you!
>>>
>>> --
>>> Fernando Santagata
>>>
>>
>
>
> --
> Fernando Santagata
>


Re: -f ???

2017-09-29 Thread Simon Proctor
So

$f = so "eraseme.txt".IO.f;

Would do the trick?

On Fri, 29 Sep 2017, 6:56 am Norman Gaywood,  wrote:

> On 29 September 2017 at 15:10, Brandon Allbery 
> wrote:
>
>>
>> (And, Norman? It produces a Failure, not a hard exception. You can
>> introspect Failures to keep them from getting thrown.)
>>
>
>  Yep, that's what I thought I'd said :-) Obviously not clearly.
>
> Another way of looking at it:
>
> $ perl6 -e 'my $f = "eraseme.txt".IO.f;say $f.WHAT'
> (Failure)
>
> and you can coerce that to a bool without throwing as other examples in
> the thread have shown.
>
> perl6 -e 'my $f = "eraseme.txt".IO.f; say $f.WHAT; say ?$f'
> (Failure)
> False
>
> Or plain old verbose:
>
> if "eraseme.txt".IO.f {
> say "exists";
> } else {
> say "does not exist";
> }
>
> It seems to me it only looks buggy when you are trying to do one liners
> and you don't naturally get a boolean context.
>
> --
> Norman Gaywood, Computer Systems Officer
> School of Science and Technology
> University of New England
> Armidale NSW 2351, Australia
>
> ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
> Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062
>
> Please avoid sending me Word or Power Point attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>


User defined infix operators and whitespace

2017-08-10 Thread Simon Proctor
So I had a crazy little idea. I've played the odd bit of roleplaying in my
time and wanted to created a 'd' operator.

Quite simple really.

sub infix: ( Int $num, Int $size ) { [+] (1..$size).roll($num) };

sub prefix: ( Int $size ) { 1 d $size }

Gives us 3 d 6 to roll 3 six sided dice or a prefix d 10 for a single 10
sided dice.

Except... I'd really like to write 3d6 or d10 but the parser barfs.

Am I going to just have to live with that? Or did I miss something obvious?

Obviously it's possible to have operators that ignore whitespace (1+1 works
just fine) but is it possibly for user defined ones?

Possibly more serious ones.

Simon


Re: how do you pipe to perl6?

2017-08-04 Thread Simon Proctor
>From the perl6 -h response you have the standard Perl command line
switches

-e program   one line of program, strict is enabled by default

With this case $*IN has the content from the pipe going into it. Personally
I combine -e with one of the next two

  -n   run program once for each line of input

In this case your command line is repeated with $_ set to the next line of
text from $*IN

  -p   same as -n, but also print $_ at the end of lines

And as it says, does the same as -n with an extra print. (Though from a
quick test it looks to be a say?)

Generally one of -e, -ne or -pe will cover what you want. -e if you need to
work with more than one line at a time. -ne if you don't want to print all
the things and -pe if you do (after modifications).

Simon


On Fri, 4 Aug 2017 at 08:47 Todd Chester  wrote:

> Hi All,
>
> In Linux, how do I things to a perl6 one liner?
>
> I want to send
> ip -o -f inet addr show | perl6 ***dig out the netmask on eno1***
>
> I know how to dig out the net mask, I just don't how to pipe
> to the command.
>
> Many thanks,
> -T
>


Re: Version of a Module

2017-06-28 Thread Simon Proctor
See I'm using mi6 to generate my META6.json file from the report and it
picks the version up from the module file. Other options like that seem
sensible to me.

Simon

On Wed, 28 Jun 2017, 13:01 Martin Barth,  wrote:

> Hello,
>
> but your approach means you have to state the version in the META6.json
> AND in the Module.pm6 file again. This would be the similar to having
> $VERSION in perl5. Shouldnt there be a simpler way?
>
>
> Am 28.06.2017 um 08:45 schrieb Fernando Santagata:
>
> Hi Martin,
>
> This works for me:
>
> File mytest.pm6
>
> use v6;
> unit module mytest:ver<0.0.1>;
>
> sub myver is export
> {
>   mytest.^ver;
> }
>
> File mytest.p6
>
> #!/usr/bin/env perl6
> use lib '.';
> use mytest;
>
> say myver;
>
> Console output:
>
> $./mytest.p6
> v0.0.1
>
> I this what you meant?
>
> On Tue, Jun 27, 2017 at 10:37 PM, Martin Barth  wrote:
>
>> Hello everyone,
>>
>> I wanted to repeat the question that I asked today on #perl6.
>> I am looking for a way to retrieve the version of a Perl6-Module from
>> within the module itself.
>>
>>  there is often a our $VERSION in perl5 modules. is this still
>> idiomatic/a good way to go in perl6
>>  i think the version is meant to be part of the meta info and
>> such?
>>  but that means the module itself does not know about its
>> version, just e.g. zef does?
>>  i'm convinced there ought to be a way to get the full meta
>> info from whatever installation your script was grabbed from
>>  but i don't know what or how
>>
>
>
>
> --
> Fernando Santagata
>
>
>


Re: Possible zef addition

2017-05-25 Thread Simon Proctor
Sort of, except you really want it to be done at the end of the current
request. (auto-cleanup doesn't seem to do that, setting it to 0 turns it
off).

When you're building a docker image you really want to make sure the end of
every command only the things the NEED are in the filesystem as a snapshot
is taken at the point. If you're wanting to reduce container size this is
important.

I might take a look at zef today if I have time and see if I can work out a
simple version.

Simon

On Thu, 25 May 2017 at 08:06 Ahmad Zawawi <ahmad.zaw...@gmail.com> wrote:

> Something like cpanm's work directory auto-cleanup mechanism?
>
>
> https://metacpan.org/pod/distribution/App-cpanminus/lib/App/cpanminus/fatscript.pm#-auto-cleanup
>
> On Thu, May 25, 2017 at 7:20 AM, Simon Proctor <simon.proc...@gmail.com>
> wrote:
>
>> So I'm playing around with Docker files (Perl 5 ATM) and one thing I'm
>> getting quite into is trying to keep them small. An important part of this
>> is deleting any extraneous caching info built up during the build,
>> preferably as part of the RUN step to get intermediate layers small.
>>
>> (So with Perl5 and cpanm `rm -rf ~/.cpanm` is your friend).
>>
>> Anyhoo, my thought was could we add something to zef to do this? Either a
>> flag or a new command to auto clean up the ~./zef folder.
>>
>> Yes I know rm -rf ~/.zef is simple to type but if it was built into the
>> command it would show forward thinking. Or something.
>>
>> It's 5am and I couldn't sleep. This is the kind of idea I get.
>>
>> Simon
>>
>


Possible zef addition

2017-05-24 Thread Simon Proctor
So I'm playing around with Docker files (Perl 5 ATM) and one thing I'm
getting quite into is trying to keep them small. An important part of this
is deleting any extraneous caching info built up during the build,
preferably as part of the RUN step to get intermediate layers small.

(So with Perl5 and cpanm `rm -rf ~/.cpanm` is your friend).

Anyhoo, my thought was could we add something to zef to do this? Either a
flag or a new command to auto clean up the ~./zef folder.

Yes I know rm -rf ~/.zef is simple to type but if it was built into the
command it would show forward thinking. Or something.

It's 5am and I couldn't sleep. This is the kind of idea I get.

Simon


Re: How to I create a file?

2017-03-21 Thread Simon Proctor
It's a logical test but I'd probably use || instead.

See : https://docs.perl6.org/language/traps#Loose_boolean_operators


On Tue, 21 Mar 2017 at 10:56 ToddAndMargo  wrote:

> On 03/21/2017 03:07 AM, Brent Laabs wrote:
> > $PathAndName.IO.f or $PathAndName.IO.open(:w).close;
>
> Is that a coding "or" or an English "or"?
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: How to I create a file?

2017-03-21 Thread Simon Proctor
.e checks a path exists.
.f checks it exists AND is a file.
.d checks it exists AND is a directory.

(Perl 5 was the -e, -f and -d tests)

On Tue, 21 Mar 2017 at 10:19 ToddAndMargo  wrote:

> On 03/21/2017 03:07 AM, Brent Laabs wrote:
> > You can create a file by opening a filehandle for writing.
> >
> > $PathAndName.IO.f or $PathAndName.IO.open(:w).close;
>
>
>
> What does the .f do?
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: Is this file check backwards?

2017-03-21 Thread Simon Proctor
Just because the file is called "nonexistent_file" doesn't mean is doesn't
exist.

It's a poorly written example really.

if "possibly_existing_file".IO.e {
 say "file exists";
}
else {
 say "file doesn't exist";
}

Is more intuitive I would say.

On Tue, 21 Mar 2017 at 09:53 ToddAndMargo  wrote:

> https://docs.perl6.org/language/io.html
>
>  From the above manual, the example to check if a file exists:
>
>
> if "nonexistent_file".IO.e {
>  say "file exists";
> }
> else {
>  say "file doesn't exist";
> }
>
>
> Sound backwards to me.  What am I missing?
>
>
> Many thanks,
> -T
>
>
> --
> ~
> I am Windows
> I am the Blue Screen of Death
> No one hears your screams
> ~
>