Re: More efficient of two coding styles?

2018-11-15 Thread Brent Laabs
I don't know the answer to your specific question -- maybe try benchmarking
it?  Subroutine dispatch is normally pretty fast, as are given statements.
Both when and ~~ call the ACCEPTS method, just at different times in your
examples.  I'm not really sure if the JIT will kick in better in one case
or another.

But this also seems to be in the sphere of premature optimization.  You
should write your program in a way that is most likely to give correct
results, and allows you to be flexible where you need to be.  There's More
Than One Way To Do It.

On Thu, Nov 15, 2018 at 8:26 PM Richard Hainsworth 
wrote:

> Brent,
>
> Thanks for the rapid response, but it does not really answer the intent of
> the question.
>
> Essentially, you said that one style provides for a silent default, the
> other does not. The intent of the question is about performance - as in the
> subject line.
>
> Perhaps the word 'style' is mal-chosen, perhaps 'coding idiom' ?
>
> Style 1 can be adjusted to have an explicit default, eg.
>
> multi sub handle ( $node ) { 'I dont care' }
>
> Style 2
>
> given  { ... default { 'I dont care' } }
>
>
> So, since these 'styles' / 'coding idioms' use different mechanisms to
> achieve the same intended result (if necessary, I can re-work the examples
> to get the same result), there must be different performance effects.
>
> Which coding idiom is better in performance terms?
>
> May be my question is "incorrect", in which case what is the implicit
> assumption I am making that should be explicit?
>
>
> On 16/11/2018 12:13, Brent Laabs wrote:
>
> They do two different things.  Style 1 will throw a dispatch error if $
> node.name has a value of 'three', where Style 2 will do nothing in that
> case.
>
> On Thu, Nov 15, 2018 at 7:55 PM Richard Hainsworth 
> wrote:
>
>> Suppose I have a sub called C that runs different code depending
>> on the content of an argument.
>>
>> There are two styles in Perl 6 to code this and my question is whether
>> one is more efficient (speed/memory) than the other.
>>
>> In this example, one relies on multiple dispatch, while the other an
>> explicit control statement.
>>
>> Putting aside clarity considerations, is there any performance reason to
>> prefer one style over another?
>>
>> Style 1
>>
>> multi sub handle( $node WHERE *.name ~~ 'one' ) {
>>
>>  'this is a wonderful sub'
>>
>> }
>>
>> multi sub handle( $node WHERE *.name ~~ 'two' ) {
>>
>> 'twas brillig and the slivy toves did gyre'
>>
>> }
>>
>>
>> Style 2
>>
>> sub handle ( $node ) {
>>
>>  given $node.name {
>>
>>  when 'one' { 'this is a wonderful sub' }
>>
>>  when 'two' { 'twas brillig and the slivy toves did gyre' }
>>
>>  }
>>
>> }
>>
>


Re: More efficient of two coding styles?

2018-11-15 Thread Brent Laabs
They do two different things.  Style 1 will throw a dispatch error if $
node.name has a value of 'three', where Style 2 will do nothing in that
case.

On Thu, Nov 15, 2018 at 7:55 PM Richard Hainsworth 
wrote:

> Suppose I have a sub called C that runs different code depending
> on the content of an argument.
>
> There are two styles in Perl 6 to code this and my question is whether
> one is more efficient (speed/memory) than the other.
>
> In this example, one relies on multiple dispatch, while the other an
> explicit control statement.
>
> Putting aside clarity considerations, is there any performance reason to
> prefer one style over another?
>
> Style 1
>
> multi sub handle( $node WHERE *.name ~~ 'one' ) {
>
>  'this is a wonderful sub'
>
> }
>
> multi sub handle( $node WHERE *.name ~~ 'two' ) {
>
> 'twas brillig and the slivy toves did gyre'
>
> }
>
>
> Style 2
>
> sub handle ( $node ) {
>
>  given $node.name {
>
>  when 'one' { 'this is a wonderful sub' }
>
>  when 'two' { 'twas brillig and the slivy toves did gyre' }
>
>  }
>
> }
>


Re: need p5/p6 :: help

2018-09-15 Thread Brent Laabs
Now that Larry has spoken on the issue of vocabulary, it's lexicanonical.

On Fri, Sep 14, 2018 at 12:49 PM Larry Wall  wrote:

> On Fri, Sep 14, 2018 at 04:15:02AM -0700, Todd Chester wrote:
> : Also, did you answer my question about "::" and did it
> : just go over my head?
>
> The implication was that "::" didn't change, but the default package
> scoping of p5 that you're relying on is no longer the default in p6.
>
> : The p5 guys use to tell me "its lexiconical", meaning it was figured
> : out on the fly.  (Took me forever to catch on.)  Is that any
> : relation to your use of the word "lexical"?
>
> I would like to see a citation of this use of the word "lexiconical".
> In the first place, the word "lexiconical" has not been used in
> perl5-porters in living memory, and if had been used there, it is
> unlikely to have meant "figured out on the fly".
>
> : https://www.dictionary.com/browse/lexical?s=t
> :
> :adjective
> :
> :of or relating to the words or vocabulary of a language,
> :especially as distinguished from its grammatical and
> :syntactical aspects.
> :
> :of, relating to, or of the nature of a lexicon.
>
> The relationship of lexicons to lexical scoping here is a bit tenuous,
> but it goes something like this: Every scope in your program can define
> things local to that scope.  When a scope does define something, it's
> creating a new lexicon of terms, like a private lingo or patois for a
> given workplace that no other workplace will understand.  It is that
> set of private definitions (overlaid on all the definitions pulled in
> from larger scopes) that functions as a "dictionary" here.
>
> So when people say "lexically scoped", they mean there are multiple
> lexicons,
> and each symbol is looked in the nearest one that actually has a definition
> for the term.  The whole point of "scoping" is to decide what is near, and
> what is far.
>
> So, for instance, you may have worked in a workplace or participated
> in a forum where the local lexicon of the "p5 guys" contained the
> word "lexiconical" with some kind of idiosyncratic meaning involving
> dynamic lookup.  That term is not used in the larger p5 culture that
> way, so people outside that workplace or forum will not understand that
> idiosyncratic definition of "lexiconical", which seems to have nothing
> whatsoever to do with lexicons.
>
> Lexical scoping is not figured out on the fly; it's figured out while the
> code is compiling.  You can have delayed compilation when you eval a
> string,
> of course, but then the fact that the lexical lookups are delayed is not
> a special feature of the lexicon; everything related to the compiler is
> delayed when you eval.  "Figured out on the fly" is a feature of eval, not
> of lexicons.
>
> Now, all that being said, in p5 subroutines are looked up in packages,
> and packages are modifiable, so we do have to discover what to call "on
> the fly" in that case.  But in p5 culture we never refer to packages as
> lexicons because that would confuse people.
>
> In Perl 6 culture we never mix them up either, but we also never put subs
> into packages by default.  The reason Foo::bar notation doesn't work is
> because bar isn't in Foo anymore unless you explicitly put it there.
>
> Larry
>


Re: I need hash syntax help

2018-09-15 Thread Brent Laabs
Because << >> is a double-quoted index (same as quote words «»), so it
interpolates the variable.  <> is a single-quoted string, so it doesn't
interpolate.

But what you really want here is %x{$z}, so you don't bother with string
interpolation at all, and pass the String variable directly.

On Fri, Sep 14, 2018 at 11:59 PM ToddAndMargo  wrote:

> Hi All,
>
> Why does `$y =%x<<$z>>` work in the following and
> `$y =%x<$z>` and `$y =%x<"$z"> do not work?
>
> $ p6 'my Str %x=("Jan"=>"01", "Feb"=>"02");
>my Str $z="Jan";
>my $y =%x<<$z>>;
>say "$y";'
> 01
>
> Why did I get it right?
>
>
> Many thanks,
> -T
>


Re: a `pe4rl6 -c` error to fix

2018-06-20 Thread Brent Laabs
-c does compile time warnings, not runtime warnings.  You can't make
runtime warnings appear at compile time without using a BEGIN block.

On Wed, Jun 20, 2018 at 9:59 PM, Todd Chester  wrote:

>
>
> > On Tue, Jun 19, 2018 at 10:50 PM, Todd Chester 
> wrote:
> >> Dear Perl Developers,
> >>
> >> Would you please fix this `perl6 -c` checker error?
> >>
> >> $ perl6 -v
> >> This is Rakudo version 2018.05 built on MoarVM version 2018.05
> >> implementing Perl 6.c.
> >>
> >>
> >> The checkers passes this line with Syntax OK
> >>
> >>   $ReturnStr, $CurlStatus = CurlDownloadFile $FileAddr,
> $BaseFileName,
> >> %MaxTime<'MaxTime4'>;
> >>
> >>
> >> But actually running the line throws
> >>
> >>   Useless use of $ReturnStr in sink context
> >>
> >>
> >> The checker should throw an error if the line is "useless"
> >>
> >> Many thanks,
> >> -T
>
>
> > On 06/20/2018 11:46 AM, Will Coleda wrote:
>
>> It's a warning, not an error.
>>
>
> Indeed it is.  "-c" does warnings too and it should
> show in "-c" too.
>


Re: need sort help

2018-06-08 Thread Brent Laabs
It isn't in any variable, @x.sort got called in sink context.  You'll have
to assign it if you want, maybe use @x.=sort ?

I just wanted to give an example of how to solve the problem, not
necessarily a working solution.  First of all, I did thinko the solution --
element 6 is [5]...  and we don't really need to check the last bits of
time if we're going to do cmp anyway...

@x.=sort: {
my $a = $^x ~~ m:g/\d+/;  # extract digit portions in to match object
for each parameter to sort
my $b = $^y ~~ m:g/\d+/;  # ditto
$a[5].defined cmp $b[5].defined   # this part makes sure we're actually
looking at a timestamp with 6 digit groups
??
  $a[3] cmp $b[3]   # year
|| $a[1] cmp $b[1]  # month
|| $a[2] cmp $b[2]  # day
|| $x cmp $y  # sort whatever's left
!! $x cmp $y  # doesn't have a date stamp, then just string compare
};

The part about placeholders being declarations I didn't know, so hey, I'm
glad I participated.


On Fri, Jun 8, 2018 at 9:37 PM, ToddAndMargo  wrote:

> On 06/08/2018 09:25 PM, Brandon Allbery wrote:
>
>> @x.sort: {
>> my $a = $^x ~~ m:g/\d+/;
>> my $b = $^y ~~ m:g/\d+/;
>> $a[6].defined cmp $b[6].defined
>> ??
>>   $a[3] cmp $b[3]
>> || $a[1] cmp $b[1]
>> || $a[2] cmp $b[2]
>> || $a[4] cmp $b[4]
>> || $a[5] cmp $b[5]
>> || $a[6] cmp $b[6]
>> || $x cmp $y
>> !! $x cmp $y
>> };
>>
>> This is what I sent before, minus the leading "> " that I'd neglected to
>> remove.
>>
>> Please note the second line does NOT say "my $a = $a ~~ m:g/\d+/;", which
>> is what you had and what produced the error you pasted. I don't know where
>> you got that. Likewise the third line with $b and $^y (where again you had
>> $b instead).
>>
>> On Sat, Jun 9, 2018 at 12:19 AM ToddAndMargo > > wrote:
>>
>> On 06/08/2018 09:16 PM, Brandon Allbery wrote:
>>  > You didn't use what I sent. It's $^x and $^y, not $a and $b.
>>
>> I am lost.  Would you mind writing it out for me?
>>
>
> $ ls | perl6 -e 'my @x=slurp(); say @x.sort: {my $a = $^x ~~ m:g/\d+/;my
> $b = $^y ~~ m:g/\d+/; $a[6].defined cmp $b[6].defined ??  $a[3] cmp $b[3]
> || $a[1] cmp $b[1]   || $a[2] cmp $b[2]  || $a[4] cmp $b[4]  || $a[5] cmp
> $b[5]  || $a[6] cmp $b[6]  || $x cmp $y !! $x cmp $y};'
> (cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
> cimtrak.log.12-08-2016_06:07:39.zip
> )
>
>
> :'(
>


Re: need sort help

2018-06-08 Thread Brent Laabs
let me revise that

@x.sort: {
  my $a = $^a ~~ m:g/\d+/;
  my $b = $^b ~~ m:g/\d+/;
  $a[6].defined cmp $b[6].defined
  ??
$a[3] cmp $b[3]
  || $a[1] cmp $b[1]
  || $a[2] cmp $b[2]
  || $a[4] cmp $b[4]
  || $a[5] cmp $b[5]
  || $a[6] cmp $b[6]
  || $^a cmp $^b
  !! $^a cmp $^b
};


On Fri, Jun 8, 2018 at 6:59 PM, Brent Laabs  wrote:

> If possible, you should change the way the files come, or rename them when
> you get them, or open an issue to use a proper output log format.
>
> I mean, you can sort like:
> @x.sort: {
>   my $a = $^a ~~ m:g/\d+/;
>   my $b = $^b ~~ m:g/\d+/;
>   $a[6].defined cmp $b[6].defined
>   ??
>   || $a[3] cmp $b[3]
>   || $a[1] cmp $b[1]
>   || $a[2] cmp $b[2]
>   || $a[4] cmp $b[4]
>   || $a[5] cmp $b[5]
>   || $a[6] cmp $b[6]
>   || $a cmp $b
>   !! $a cmp $b
> };
>
> You could make this more efficient with a Schwartzian transform so you
> don't regex at every step.
>
> But seriously, the problem is in the program that produces log files that
> are hard to sort.  Why would someone do that?
>
>
>
> On Fri, Jun 8, 2018 at 6:50 PM, ToddAndMargo 
> wrote:
>
>> On Fri, Jun 8, 2018 at 5:15 PM, ToddAndMargo >>> <mailto:toddandma...@zoho.com>> wrote:
>>>>
>>>> Hi All,
>>>>
>>>> https://docs.perl6.org/routine/sort
>>>> <https://docs.perl6.org/routine/sort>
>>>>
>>>> How do I fix this?
>>>>
>>>> $ ls | perl6 -e 'my @x=slurp(); say @x.sort'
>>>> (log.06-08-2018_16:07:39.zip
>>>> log.06-08-2018_17:07:39.zip
>>>> log.07-08-2018_06:07:39.zip
>>>> log.07-08-2018_16:07:39.zip
>>>> log.12-08-2016_06:07:39.zip
>>>> )
>>>>
>>>>
>>>> 2016 should be at the top.
>>>>
>>>>
>>>> Many thanks,
>>>> -T
>>>>
>>>
>> On 06/08/2018 06:23 PM, Brent Laabs wrote:
>>
>>> Rename all of the input files using ISO 8601 dates.  I can't tell, from
>>> looking at those numbers, if the first field is the month or the day, so
>>> it's impossible to sort data like that with certainty.
>>>
>>>
>> That is the way the files come.
>>
>> The convention being used is
>> month, day, year, hour, minute, second
>>
>
>


Re: need sort help

2018-06-08 Thread Brent Laabs
If possible, you should change the way the files come, or rename them when
you get them, or open an issue to use a proper output log format.

I mean, you can sort like:
@x.sort: {
  my $a = $^a ~~ m:g/\d+/;
  my $b = $^b ~~ m:g/\d+/;
  $a[6].defined cmp $b[6].defined
  ??
  || $a[3] cmp $b[3]
  || $a[1] cmp $b[1]
  || $a[2] cmp $b[2]
  || $a[4] cmp $b[4]
  || $a[5] cmp $b[5]
  || $a[6] cmp $b[6]
  || $a cmp $b
  !! $a cmp $b
};

You could make this more efficient with a Schwartzian transform so you
don't regex at every step.

But seriously, the problem is in the program that produces log files that
are hard to sort.  Why would someone do that?



On Fri, Jun 8, 2018 at 6:50 PM, ToddAndMargo  wrote:

> On Fri, Jun 8, 2018 at 5:15 PM, ToddAndMargo >> <mailto:toddandma...@zoho.com>> wrote:
>>>
>>> Hi All,
>>>
>>> https://docs.perl6.org/routine/sort
>>> <https://docs.perl6.org/routine/sort>
>>>
>>> How do I fix this?
>>>
>>> $ ls | perl6 -e 'my @x=slurp(); say @x.sort'
>>> (log.06-08-2018_16:07:39.zip
>>> log.06-08-2018_17:07:39.zip
>>> log.07-08-2018_06:07:39.zip
>>> log.07-08-2018_16:07:39.zip
>>> log.12-08-2016_06:07:39.zip
>>> )
>>>
>>>
>>> 2016 should be at the top.
>>>
>>>
>>> Many thanks,
>>> -T
>>>
>>
> On 06/08/2018 06:23 PM, Brent Laabs wrote:
>
>> Rename all of the input files using ISO 8601 dates.  I can't tell, from
>> looking at those numbers, if the first field is the month or the day, so
>> it's impossible to sort data like that with certainty.
>>
>>
> That is the way the files come.
>
> The convention being used is
> month, day, year, hour, minute, second
>


Re: need sort help

2018-06-08 Thread Brent Laabs
Rename all of the input files using ISO 8601 dates.  I can't tell, from
looking at those numbers, if the first field is the month or the day, so
it's impossible to sort data like that with certainty.

On Fri, Jun 8, 2018 at 5:15 PM, ToddAndMargo  wrote:

> Hi All,
>
> https://docs.perl6.org/routine/sort
>
> How do I fix this?
>
> $ ls | perl6 -e 'my @x=slurp(); say @x.sort'
> (log.06-08-2018_16:07:39.zip
> log.06-08-2018_17:07:39.zip
> log.07-08-2018_06:07:39.zip
> log.07-08-2018_16:07:39.zip
> log.12-08-2016_06:07:39.zip
> )
>
>
> 2016 should be at the top.
>
>
> Many thanks,
> -T
>


Re: How to print colorized text to the terminal

2018-06-03 Thread Brent Laabs
You might want to consider using Terminal::ANSIColor.

On Sun, Jun 3, 2018 at 5:53 PM, Xin Cheng  wrote:

> I just tried to use "put" in place of "say", and got the same result.
>
> Thanks.
>
> Ziping
>
>
> On Jun 3, 2018, at 8:44 PM, Brandon Allbery  wrote:
>
> "say" uses the .gist method, which quotes the output for readability. You
> probably want "put" instead.
>
> On Sun, Jun 3, 2018 at 8:42 PM Xin Cheng  wrote:
>
>> Hi,
>>
>> I am trying to make a program to do grep with perl6 regular expression,
>> and I would like to colorize the matched part to the terminal. So the
>> following is what I wrote
>>
>> sub MAIN(Str $pattern,Str $filename){
>> for $filename.IO.lines -> $line  {
>> my Str $temp = $line;
>> if $temp ~~ s/ (<$pattern>) /\\x1b\[31m$0\\x1b\[0m/ {say $temp};
>> # if no <> surrounding $pattern it becomes literal.
>> }
>> }
>>
>> And I named the program as grep6, and I tried it in zsh as
>>
>> > grep6 'M.*N' =grep6
>>
>> And I got,
>>
>> sub \x1b[31mMAIN\x1b[0m(Str $pattern,Str $filename){
>>
>> How do I turn the string into color?
>>
>> Thanks!
>>
>> Xin
>>
>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
>
>


Re: Real, Num, Rat question

2018-05-27 Thread Brent Laabs
Real is a role, not a type.  Both Num and Rat happen to do Real, so the
type checking is ok.  This would work OK with a type too -- you can safely
store a Num in a `my Cool $foo` as well.

You can't do anything to make the ^name method return Real.  There are a
few ways to check this, though.  The most idiomatic is smartmatch:
> my Real $f = 3;
3
> $f ~~ Real
True
That checked that the value of the variable does Real.  If you want to
check the type of the container:
> $f.VAR.of
(Real)


On Sun, May 27, 2018 at 2:49 PM, ToddAndMargo  wrote:

> Hi All,
>
> What is wrong with this picture?  Is my
> type being changed or are "Num" and "Rat" in
> a subset of "Real"?
>
> Also, what do I alter to get ^name to say real?
>
> $ p6 'my Real $x= 5e65; say $x.^name'
> Num
>
> $ p6 'my Real $x= 5.5; say $x.^name'
> Rat
>
>
> Many thanks,
> -T
>


Re: number of letters question

2018-05-15 Thread Brent Laabs
Just a quick reminder that  matches the underscore, because 
also does.  If you want to exclude underscores, you can match against
/<+alnum-[_]>/.  That adds the alnum character class, but subtracts
underscores from it.   Decimal points are definitely not alphanumeric,
though.

On Tue, May 15, 2018 at 1:22 AM, JJ Merelo  wrote:

>
>
> El mar., 15 may. 2018 a las 10:17, ToddAndMargo ()
> escribió:
>
>> On 05/15/2018 12:57 AM, JJ Merelo wrote:
>> > Well,
>> > say + "abcrd-12.3.4".comb.grep: //
>> > will give you that, but
>> > say + "abcñé-12.3.4".comb.grep: //
>> > will yield the same result.
>> > Roman or other kind of numerals are excluded, though...
>>
>>
>> $ perl6 -e 'say + "abcrd-12.3.4".comb.grep: //;'
>> 9
>>
>> I don't understand.
>>
>> What does `//` do?  Is that a regex?
>>
>
> Correct. It's the alphanumeric character class.
>
>
> --
> JJ
>


Re: odd and even

2018-05-01 Thread Brent Laabs
Yeah, that lexiconic section sounded a bit hyperbolic.

On Tue, May 1, 2018 at 6:17 PM, Larry Wall  wrote:

> On Tue, May 01, 2018 at 01:43:44AM -0700, ToddAndMargo wrote:
> : The worst thing I had problems with in Perl was folks telling it
> : was "Lexiconical".  What?  I wish they would have also said "which
> : means Perl figures out your variables type on the fly, so you don't
> : have to type cast everything".
>
> Just so that nobody overgeneralizes this into a general Perl meme, let
> me point out that to the best of my recollection (which ain't as good
> as it used to was), I've never heard the term "lexiconical" used that
> way (or any way, really), and I'd be completely weirded out if someone
> used it that way, since dynamic typing (figuring out types on the fly)
> has almost nothing to do with either lexicons or lexical scoping.
>
> So I suspect someone has subjected you to a rather idiosyncratic
> term and definition there...
>
> Larry
>


Re: need s/ help

2018-05-01 Thread Brent Laabs
That last one has a special case available, but it's slightly less
portable.  But afaik it works on all platforms we actually support:

> perl6 -e '"screws/nuts/bolts/washers".path.parent.Str.say'
screws/nuts/bolts

On Tue, May 1, 2018 at 4:37 PM, ToddAndMargo  wrote:

> On 05/01/2018 04:29 PM, ToddAndMargo wrote:
>
>> On Tue, 1 May 2018 at 14:37 ToddAndMargo >> toddandma...@zoho.com>> 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


>> On 05/01/2018 06:52 AM, Simon Proctor wrote:
>>
>>> 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)
>>>
>>>
>> Awesome!  Thank you!
>>
>>
>> perl6 -e 'my $x="abc-def-hij"; $x ~~ s/‘-’<-[-]>+$//; say $x;'
>> abc-def
>>
>>
>> $ perl6 -e 'my $x="abc-def-hij"; $x ~~ s|‘-’<-[-]>+$||; say $x;'
>> abc-def
>>
>>
>> $ perl6 -e 'my $x="abc/def/hij"; $x ~~ s|‘/’<-[/]>+$||; say $x;'
>> abc/def
>>
>>
>> $ perl6 -e 'my $x="screws/nuts/bolts/washers"; $x ~~ s|‘/’<-[/]>+$||;
>> say $x;'
>> screws/nuts/bolts
>>
>
>
> `+` means to repeat one or more times; `*` is the same as `+`, except
> it will take a zero times.
>
> $ perl6 -e 'my $x="screws/nuts/bolts/washers"; $x ~~ s|‘/’<-[/]>*$||; say
> $x;'
> screws/nuts/bolts
>
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: who own my code?

2017-10-21 Thread Brent Laabs
This depends on the contract you signed with the customer, and laws in your
local jurisdiction.  As such, it's probably a question more appropriate to
ask a lawyer than this list.

On Sat, Oct 21, 2017 at 12:57 AM, ToddAndMargo 
wrote:

> On 10/21/2017 12:40 AM, ToddAndMargo wrote:
>
>> If I write a program for a customer who pays my labor to
>> write it, who own the program?  Me or the customer?
>>
>
> I am a private contractor.  What they payed me for fixing a/the
> problem.  They don't care how.  I was wondering if they owned
> any of the code I wrote to fix the problem.  The customer did
> not specifically ask me to write anything.
>


Re: Is Haskell the right language for teaching FP. No!

2017-10-16 Thread Brent Laabs
It'd probably be just as useful to reply here:
https://news.ycombinator.com/item?id=15483195

On Mon, Oct 16, 2017 at 5:03 PM, Norman Gaywood  wrote:

> Someone should mention perl6 :-)
>
> http://profsjt.blogspot.com.au/2017/10/is-haskell-right-
> language-for-teaching.html
>
> --
> 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 <+61%202%206773%202412>  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
>


Re: variable size limit?

2017-10-02 Thread Brent Laabs
I'd recommend using less memory in a variable than your system has in
physical RAM, or your program will get slow from swapping to disk.  I've
never had a computer with less than 8MB of memory, so you should be fine.

On Mon, Oct 2, 2017 at 6:22 PM, ToddAndMargo  wrote:

> Hi All,
>
> I am about to pick up 5 MB of data and cram it into a $ variable.
>
> Is there some size limit to how much data I can or should cram
> into a variable?
>
> Many thanks,
> -T
>


Re: Why can't I "write"?

2017-09-23 Thread Brent Laabs
OK, a method is something you call on an object, using a the dot operator.
A subroutine is an independent object installed into your current lexical
scope.

If write was a sub, it would work exactly as you described:
   48:   my $Handle = open( $DateFile, :rw )
   53:   write( $Handle, $OldDateTime );
And if you wanted to, you could even refer to it by name...
  my $func = 
  $func( $Handle, $DateThing );

But it's not a sub, so it needs to be invoked on the object:
   53:   $Handle.write($OldDateTime );
- or -
   67:   $Handle.write: $DateTime;

So the last section is the statements that will work.  Methods belong to
objects, so they can't be invoked except by calling them on the object.

On Fri, Sep 22, 2017 at 11:43 PM, ToddAndMargo 
wrote:

> On Sat, Sep 23, 2017 at 8:19 AM, ToddAndMargo >> > wrote:
>>>
>>> On 09/22/2017 11:09 PM, ToddAndMargo wrote:
>>>
>>> Hi All,
>>>
>>> https://docs.perl6.org/routine/write
>>> 
>>>
>>> (IO::Handle) method write
>>> Defined as:
>>> method write(IO::Handle:D: Blob:D $buf --> True)
>>>
>>> Writes $buf to the filehandle. This method can be called
>>> even when the handle is not in binary mode.
>>>
>>>
>>>
>>> This:
>>>  48:   my $Handle = open( $DateFile, :rw )
>>>  53:   write( $Handle, $OldDateTime );
>>>  67:   write( $Handle, $DateTime );
>>>
>>> gives me this:
>>>  Undeclared routine: write used at lines 53, 67
>>>
>>> Huh?  Seems to me I am follow the directions.  What am
>>> I doing wrong?
>>>
>>>
>>> Many thanks,
>>> -T
>>>
>>>
>>>
>>> This worked:
>>>  $Handle.print( "$DateTime\n" );
>>>
>>> But I still what to know what was wrong with the
>>> way I interpreted the manual
>>>
>>> -T
>>>
>>
> On 09/22/2017 11:25 PM, Fernando Santagata wrote:
>
>> Hi,
>>
>> "write" is a method; its signature is
>>
>> method write(IO::Handle:D: Blob:D $buf --> True)
>>
>> so it has to be called as a method, not a sub.
>>
>> Also note the way the first argument is declared, as a IO::Handle:D:,
>> without a comma separating it from the second argument. That's the type of
>> the object to which the method write is to be applied.
>>
>> --
>> Fernando Santagata
>>
>
> Thank you!
>
> I  a-l-m-o-s-t  understand it.
>
> How to I turn the above into something that writes to a file?
>


Re: help with map and regexp

2017-09-21 Thread Brent Laabs
You can also use a whatever star with the subst method to avoid the block
entirely, and just chain method calls:

my @fields = $line.split( ',' ).map: *.subst(/\'/, "", :g).subst(/^\"|\"$/,
"", :g);


On Wed, Sep 20, 2017 at 11:37 PM, Luca Ferrari 
wrote:

> On Tue, Sep 19, 2017 at 2:43 PM, Timo Paulssen  wrote:
> > perl6 -e '.perl.say for "hello, how, are, you".split(",").map: -> $_
> > is copy { s:g/a//; s:g/^ \s|\s $/O/; $_ }'
> > "hello"
> > "Ohow"
> > "Ore"
> > "Oyou"
>
> Thanks.
> Out of cursiosity: what is the diffence between using "is copy" and "<->"?
> Seems to me the map example can work with both.
>
> Luca
>


Re: String to array problem

2017-07-17 Thread Brent Laabs
Just to make it clear, do not use EVAL() ever on untrusted user input.  In
the example I wrote, if the string contained a '>', anything after that
point would be executed.  While it works, it's a bad idea to use it.

On Mon, Jul 17, 2017 at 2:17 AM, ToddAndMargo <toddandma...@zoho.com> wrote:

> On Sun, Jul 16, 2017 at 11:34 PM, ToddAndMargo <toddandma...@zoho.com
>>> <mailto:toddandma...@zoho.com>> wrote:
>>>
>>> On 07/16/2017 07:48 PM, Brent Laabs wrote:
>>>
>>> $ perl6
>>>> my $x='ls -al "Program Files" "Moe Curly Larry"';
>>> ls -al "Program Files" "Moe Curly Larry"
>>>> ( "qww<$x>" ).perl
>>> ("ls", "-al", "Program Files", "Moe Curly Larry")
>>>
>>> How about this?  Obligatory: Much EVAL, very danger wow.
>>>
>>>
>>> I don't understand.  Would you put this into a full executable
>>> example?
>>>
>>>
>>>
> On 07/17/2017 02:08 AM, Brent Laabs wrote:
>
>> I would put it in an executable example, and I already did.  But here's
>> another one, if you like.
>>
>> $ perl6 -e 'my $x = q; my @y =
>> ( "qww<$x>"); for @y.kv -> $i, $j { say "  \@y[$i] = \c39$j\c39" }'
>>@y[0] = 'ls'
>>@y[1] = '-al'
>>@y[2] = 'Program Files'
>>@y[3] = 'Moe Curly Larry'
>>
>> The last loop is just so it's printed in the way you demonstrated in the
>> first post.
>>
>> The main point of me writing that example in the first place is because I
>> know that the Perl 6 language itself is very good at parsing quotes.  If
>> you knew what the string was at compile time, you could just write this:
>>   my @y = qww;
>> And it would know exactly how to deal with the quotes.  But I don't know
>> how to access this functionality of the quote language from within the Perl
>> 6 language.  You can't use qqww directly, because the quote protection is
>> handled before interpolation, and we want it to happen after.  So I can
>> eval a qww string instead, and that does work, though it does recognize
>> kinds of quoting that you wouldn't expect, like dumb quotes or halfwidth
>> katakana quotes.
>>
>> All of this is to say that I wish the Str.words method had a way of
>> applying Perl 6 quoting rules as if it were the qww operator.
>>
>>
> Thank you!
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: How do you call the variable types?

2017-06-10 Thread Brent Laabs
I thought:
$ is Scalar
@ is Array
% is Hash
& is a function

> my $x; say $x.VAR.WHAT;
(Scalar)

A dollar variable is a scalar.  The Scalar type is the the container for
the dollar-variables, just like Array is the container for @array and Hash
is the container for %hash.  Of course we also have this...
> my  
(Scalar)

It turns out functions are stored in Scalar containers as well.  In my view
it's a form of syntactic sugar to be able to to use function names without
a sigil in Perl 6.  A declared function is just an object; `sub foo {}` is
saved in the current lexical scope as   These function calls are all
equivalent:
> my  = sub { say "called" };
sub () { #`(Sub|140204743370112) ... }
> x()
called
> ()
called
> my $y =  $y();
called

(Though multi subs would be much more complex to declare this way.)


On Fri, Jun 9, 2017 at 9:51 PM, Gabor Szabo  wrote:

> Brad, thanks for your reply.
> I accept your point on not calling $-variables "generic variables",
> but then how do you call them?
>
> The same with the other 3. You described what they do in the same way
> as the documentation does, but
> when you casually speak about them, you know, with friends in bar :-),
>  what do you call them then? e.g.:
>
> @a = 23, 14, 49;
>
> Do you say:
> "I assign the list on the right hand side to a variable that does the
> Positional role."?
> or
> "I assign the list on the right hand side to an array." ?
> or
> "I assign the list on the right hand side to an at-variable." ?
> or
> Something completely different.
>
> Gabor
>
>
>
> On Sat, Jun 10, 2017 at 7:21 AM, Brad Gilbert  wrote:
> > @ does the Positional role
> > % does Associative
> > & does Callable
> > $ causes its value to be an item (its values do not flatten into an
> > outer list when you use `flat`)
> >
> > my %hash is SetHash;
> >
> > Array does Positional, and all of its values are itemized
> >
> > We are unlikely to call $ variables "generic" because the word
> > "generic" is too generic.
> > For example Java has generics, and they are not variables.
> > Why muddy the waters by using a word that has many different meanings
> > in different programming languages?
> >
> > On Fri, Jun 9, 2017 at 1:21 AM, Richard Hainsworth
> >  wrote:
> >> It also seems to me that 'scalar' gives the wrong impression compared to
> >> arrays. A scalar in a vector is a component of a vector.
> >>
> >> I was thinking of "generic".
> >>
> >> Hence "$variable" is a generic variable because it can hold any type of
> >> content.
> >>
> >>
> >>
> >> On Friday, June 09, 2017 02:10 PM, Gabor Szabo wrote:
> >>>
> >>> Looking at https://docs.perl6.org/language/variables there are 4
> >>> variable types with sigil:  $, @, %, &.
> >>> In Perl 5 I used to call them scalar, array, hash, and function
> >>> respectively, even if the scalar variable had a reference to an array
> >>> in it.
> >>>
> >>> How do you call them in Perl 6?
> >>>
> >>> As I understand @ always holds an array (@.^name is always Array or
> >>> some Array[type]). Similarly % always holds a hash and & is always a
> >>> function or a method.
> >>> So calling them array, hash, and function sounds good.
> >>>
> >>> However I am not sure what to call the variables with a $ sigil?
> >>> Should they be called "scalars"? Wouldn't that case confusion as there
> >>> is also a container-type called Scalar.
> >>>
> >>> The word "scalar" appears twice in the document describing the
> >>> variables: https://docs.perl6.org/language/variables and a total of
> >>> 135 in the whole doc including the 5to6 documents and the document
> >>> describing the Scalar type.
> >>> The document describing the Scalar type:
> >>> https://docs.perl6.org/type/Scalar the term "$-sigiled variable" is
> >>> used which seems to be a bit long for general use.
> >>>
> >>> So I wonder how do *you* call them?
> >>>
> >>> Gabor
>


Re: ding!

2017-06-01 Thread Brent Laabs
The lack of sound is probably from your terminal.  For instance, iTerm2.app
has the "Silence Bell" option in Preferences > Profiles.

On macOS, this makes a ding noise:
perl6 -e 'run '
or
perl6 -e 'run '

On Wed, May 31, 2017 at 9:18 PM, ToddAndMargo  wrote:

> On 05/31/2017 09:11 PM, Peter Scott wrote:
>
>> On 5/31/17 8:44 PM, ToddAndMargo wrote:
>>
>>> On 05/31/2017 08:39 PM, Lloyd Fournier wrote:
>>>
 perl6 -e 'say "\a"'

>>>
>>> No joy under linux.
>>>
>>> 0x07 does not work either.  Just prints a 7
>>>
>>
>> ITYM chr(7).
>>
>
> perl6 -e 'print chr(7)'
>
> No joy.  :'(
>
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: zef, zef-j, zef-m

2017-05-29 Thread Brent Laabs
This works without a module on Rakudo:

use nqp;
my $path = "foo".IO;
my $hardlink-count =  nqp::stat($path.absolute,
nqp::const::STAT_PLATFORM_NLINKS);




On Mon, May 29, 2017 at 1:54 AM, Elizabeth Mattijsen  wrote:

> > On 29 May 2017, at 10:42, Fernando Santagata 
> wrote:
> >
> > The three files are already hard-linked, no need for soft links.
> >
> > BTW, is there a way to detect hard links in Perl6?
> > Perl5 "stat" operator returns an array whose fourth element is the
> number of hard links of a file, but I don't see anything like that in the
> Perl6 docs.
>
> Generally, unixisms are not directly supported in Perl 6 in the core.  It
> should be relatively trivial to create an ecosystem module for this using
> NativeCall directly accessing functionality in libc (which then of course
> won’t work on Windows).
>
>
> Liz


Re: Get Better error message that "is trait on $-sigil variable not yet implemented. Sorry."?

2017-05-26 Thread Brent Laabs
To file a bug in Rakudo, you should email rakudo...@perl.org.

If it's a better error message you want, put "LTA Error" in the email
subject somewhere.  LTA means "less than awesome", because we in Perl 6
land only accept awesome error messages.

If you want to actually have the feature, put "[NYI]" in the subject line,
for "not yet implemented".

You can of course track Perl 6 bugs at in RT, perl6 queue:
https://rt.perl.org/

On Fri, May 26, 2017 at 1:34 AM, Gabor Szabo  wrote:

> I just tried:
>
>
> > my $x is Int = 42;
> ===SORRY!=== Error while compiling:
> is trait on $-sigil variable not yet implemented. Sorry.
> --> my $x is Int⏏ = 42;
> expecting any of:
> constraint
>
> and was a bit disappointed. It took me a while and reading the book of
> Andrew Shitov till I tried
>
> > my Int $x = 42;
> 42
>
>
> I wonder if the error message could hint at this way of declaring a
> type constraint?
>
> Gabor
>


Re: Are sigils required?

2017-05-26 Thread Brent Laabs
You didn't keep reading far enough.

> For information on variables without sigils, see sigilless variables
.
> https://docs.perl6.org/language/variables#Sigilless_variables

On Thu, May 25, 2017 at 11:10 PM, Gabor Szabo  wrote:

> https://docs.perl6.org/language/variables
> says:
> "Variable names can start with or without a special character called a
> sigil,"
>
> But then in the examples all 3 have sigils. How can a variable have no
> sigil?
>
> Gabor
>


Re: How to I create a file?

2017-03-21 Thread Brent Laabs
You can create a file by opening a filehandle for writing.

$PathAndName.IO.f or $PathAndName.IO.open(:w).close;

On Tue, Mar 21, 2017 at 3:01 AM, ToddAndMargo  wrote:

> Hi All,
>
> How to I do this bash code in Perl 6?
>
> if [ ! -f "$PathAndName" ]; then touch "$PathAndName" fi
>
> I am not finding the directions on how to create a "new"
> file at a specific location.
>
>
> Many thanks,
> -T
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: more match humility

2017-03-14 Thread Brent Laabs
I'm not sure what you mean by lexiconical.  I can't find any references to
it in the official perl documentation (which would technically be
lexicanonical, right?).

But if you're talking about lexical scope, then yeah, Perl 6 enforces that
even more than Perl 5 does by default.

On Mon, Mar 13, 2017 at 10:50 PM, ToddAndMargo 
wrote:

> On 03/13/2017 10:20 PM, Brandon Allbery wrote:
>
>> Just to be a little more clear about what is happening here:
>>
>> Perl 5 tended to treat things as strings if you use them as strings, or
>> as numbers if you use them as numbers. Perl 6 is more strict about that,
>> but makes an exception for specifically numbers and strings; if you have
>> noticed the class "Cool", that's a class whose subclasses are string and
>> number classes, and which tries to make one into the other if needed.
>>
>> Subs aren't Cool. [ :) ] They are objects of type Sub, which is *not* a
>> String (nor has a Stringy role, nor is a subclass of Cool). Perl 6 wants
>> you to explicitly make a string in this case; and as there are multiple
>> strings one could want (the name? a summary of the definition like .gist
>> makes? the full definition like .perl is intended to make but IIRC
>> doesn't yet? something else?) you need to specify exactly *what* string
>> to get from a Sub object.
>>
>
> Hi Brandon
> Makes sense.  Thank you for the tutorial!
>
> So Perl 6 is less "Lexiconical" that Perl 5?
>
> :-)
>
> I know, I am going to the bad hell.
>
> When I was learning Perl 5, the  term "Lexiconical" drove
> me nuts.  "JUST SAY WHAT YOU MEAN"   "Lexiconical"
> meant noting to me for the longest time.  And every time
> I looked it up, I understood it for about 20 seconds,
> then lost it again.
>
> Perl 6 is so much better done than Perl 5. I am a Top Down
> guy (you will notice a lot fo subs in my postings) and
> Perl 6's sub's are a match made in heaven.  I adore
> Perl 6's subs.
>
> I came from Modula 2.  "Lexiconical" is a dirty word
> over there.  Everything is literal.
>
> -T
>


Re: How do I use "&?ROUTINE"?

2017-03-08 Thread Brent Laabs
You must be doing something wrong then:

> sub LinuxCheck () { print &?ROUTINE.name ~ " " ~ "$*DISTRO OS\n"; }
sub LinuxCheck () { #`(Sub|140478449412680) ... }
> LinuxCheck();
LinuxCheck macosx OS


On Tue, Mar 7, 2017 at 11:54 PM, ToddAndMargo <toddandma...@zoho.com> wrote:

> On Tue, Mar 7, 2017 at 11:30 PM, ToddAndMargo <toddandma...@zoho.com
>>> <mailto:toddandma...@zoho.com>> wrote:
>>>
>>> Hi All,
>>>
>>> I am trying to print out the name of the sub I am in.
>>>
>>> Reference:
>>>
>>> https://docs.perl6.org/language/variables#index-entry-%26%3FROUTINE
>>> <https://docs.perl6.org/language/variables#index-entry-%26%3FROUTINE
>>> >
>>> &?ROUTINE   Which routine am I in?
>>>
>>>
>>> 
>>> sub LinuxCheck () { print &?ROUTINE ~ " " ~ "$*DISTRO $OS\n"; }
>>> 
>>>
>>>  rhel linux
>>>
>>> &?ROUTINE resolves to "", which is not the name of the sub.
>>> What am I missing?
>>>
>>>
>>> Many thanks,
>>> -T
>>>
>>
> On 03/07/2017 11:42 PM, Brent Laabs wrote:
>
>> Try &?ROUTINE.name -- that should get you the sub's name.
>>
>>
> Hi Brent,
>
> Still prints "".  Rats!
>
> Thank you for the help!
> -T
>


Re: How do I use "&?ROUTINE"?

2017-03-07 Thread Brent Laabs
Try &?ROUTINE.name -- that should get you the sub's name.

On Tue, Mar 7, 2017 at 11:30 PM, ToddAndMargo  wrote:

> Hi All,
>
> I am trying to print out the name of the sub I am in.
>
> Reference:
> https://docs.perl6.org/language/variables#index-entry-%26%3FROUTINE
> &?ROUTINE   Which routine am I in?
>
>
> 
> sub LinuxCheck () { print &?ROUTINE ~ " " ~ "$*DISTRO $OS\n"; }
> 
>
>  rhel linux
>
> &?ROUTINE resolves to "", which is not the name of the sub.  What am
> I missing?
>
>
> Many thanks,
> -T
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: List

2017-02-06 Thread Brent Laabs
Here are the docs on the List type: https://docs.perl6.org/type/List

On Mon, Feb 6, 2017 at 12:40 PM, Bob Goolsby  wrote:

> Help
>
> --
>
> Bob Goolsby
> bob.gool...@gmail.com
>


Re: Can I call myself

2017-02-04 Thread Brent Laabs
I think you're looking for &?ROUTINE.  &?BLOCK is also related.

https://docs.perl6.org/language/variables#index-entry-%26%3FROUTINE

On Sat, Feb 4, 2017 at 12:51 AM, Darren Duncan 
wrote:

> Any decent programming language supports self-recursion, where a
> subroutine may invoke itself.  Perl 6 explicitly also supports this, and
> even has a special keyword for a routine to refer to itself without knowing
> its own name, especially useful for anonymous subs; I don't remember that
> keyword but it may have been something like "SUB" or "SELF". -- Darren
> Duncan
>
>
> On 2017-02-04 12:34 AM, ToddAndMargo wrote:
>
>> Hi All,
>>
>> Just out of curiosity, in Perl 6 can a subroutine call itself?
>>
>> -T
>>
>> I am  fighting with a broken Net:FTP::rmdir in Perl 5 that
>> will not recuse as advertised (it is very intermittent).
>>
>> And I can not use Net::Ftp in Perl 6 as it is hosed and
>> so is the Inline.
>>
>> And it seems that Perl 5 doesn't like me calling myself,
>> which would do wonders for looping on rmdir until I get
>> everything.
>>
>>


Re: Recalling previous commands

2016-01-01 Thread Brent Laabs
Linenoise is included in Task::Star.
https://github.com/tadzik/Task-Star/commit/8ff101ae15

As a bit of history, Linenoise used to be part of the Rakudo repo, but it
was split off in the interest of making the base install smaller, keeping
separate software separate, and making it more pluggable.

On Fri, Jan 1, 2016 at 11:40 PM, Kaare Rasmussen  wrote:

> Hi
>
>> Try Out Linenoise
>> https://github.com/hoelzro/p6-linenoise/
>> panda install Linenoise
>>
>
> Command history is essential to the user experience of a REPL. I wonder
> why Linenoise just isn't included in Task::Star (?)
>
> /kaare
>


Re: String trim method

2015-08-06 Thread Brent Laabs
I think the optimal way would be:

   my $s  = 'yada yada';

That way the program won't have to trim the whitespace off the string every
time it is run.

In the more general case, I might do it something like:

  my $s = something-returning-a-string().trim;

But I don't think that there really is a preferred or best practice way.
This is Perl, there is more than one way to do it.

On Wed, Aug 5, 2015 at 4:16 PM, Tom Browder tom.brow...@gmail.com wrote:

 On Wed, Aug 5, 2015 at 6:00 PM, Brandon Allbery allber...@gmail.com
 wrote:
  I don't know what you mean by optimal there, but you can say something
  like
 
  $s .= trim;

 I really meant the preferred or best practice way.

 Thanks, Brandon!

 -Tom



Re: Sub args: choose one of two?

2015-06-27 Thread Brent Laabs
http://design.perl6.org/S99.html#LTA

On Sat, Jun 27, 2015 at 5:57 PM, Tom Browder tom.brow...@gmail.com wrote:

 On Jun 27, 2015 7:39 PM, yary not@gmail.com wrote:
 
  This sort of works, in that it does the right thing when you give one
  correct arg, and fails when you give neither arg or both args. The error
  message is good when you give both args, but LTA with no args.

 Thanks, Yary, Good use of multi which I passed over in my search!

 Best regards,

 -Tom

 P.S.  I assume LTA means less than adequate?