Re: Problem defining factorial operator in .rakumod file

2022-10-19 Thread Brian Duggan
On Friday, October 14, Bruce Gray wrote: 
> because the `~` tilde character is not special to Raku.
> Instead of:
> use lib '~/Documents/myRaku/gitHub/SequenceHelper/lib';
> , you need either of these:
> use lib "%*ENV/Documents/myRaku/gitHub/SequenceHelper/lib";
> use lib  %*ENV ~ '/Documents/myRaku/gitHub/SequenceHelper/lib';

There is also $*HOME, so this could be written as:

   use lib $*HOME.child('Documents/myRaku/gitHub/SequenceHelper/lib')

Brian


Re: Regex surprises

2022-09-13 Thread Brian Duggan
> > > ...
> > > "y" ~~ /(x)|(y)/

I would probably take advantage of the composability of Raku
regexes, and do something like

  my regex x { x }
  my regex y { y }

and then use

  /  |  /

and check for $ or $

> > S:g[(x)|(y)] = $0 ?? x-replacement !! y-replacement

e.g. this becomes

S:g[|] = $ ?? x-replacement !! y-replacement

Brian


Re: something between run and qx() ?

2022-08-04 Thread Brian Duggan
On Thursday, August  4, Marc Chantreux wrote: 
> I read the Proc documentation and tried to see if there was another
> command or an adverb to the qx construction (something like :r for run).
 
There is the 'x' adverb for Q -- I think qx is equivalent to Q:x

https://docs.raku.org/syntax/Q

Brian



Re: how to handle too many threads?

2022-03-08 Thread Brian Duggan
On Tuesday, March  8, Richard Hainsworth wrote: 
> I would like some help on a strategy to find what/where the problem is, and
> how to prevent the error.

Not sure if it will help since it looks like the issue is more
low-level, but feel free to try out some very new functionality for
debugging threading issues using Dawa --

  https://git.sr.ht/~bduggan/raku-dawa#multiple-threads

  https://raku.land/cpan:BDUGGAN/Dawa

Perhaps stopping the threads and then stepping through statements
in each one can help to hone in on the race.

Brian



Re: Grammar Help

2021-12-29 Thread Brian Duggan
On Sunday, December 26, Paul Procacci wrote: 
> 
> use Grammar::Tracer;
> 
> and
> 
> use Grammar::Tracer::Compact;
> 
> Both I've found helpful, though obviously not fool proof.  It'd be nice if
> it show'd why it failed (i.e. what it encountered vs what it expected )
> rather than just a 'failed'.

For what it's worth, you may also like Grammar::PrettyErrors --

Adding this to the definition :

grammar myTest does Grammar::PrettyErrors {

and then trying to parse the input, yields

--errors--
2 │ {
3 │ a = "bi";
4 │▶b = "hi";

^
5 │ }

Uh oh, something went wrong around line 4.
Unable to parse object.

in block  at grammar.raku line 40

So -- you get the position, and the rule where
it failed ("object").

Brian



Re: ftp client yet?

2021-10-22 Thread Brian Duggan
On Thursday, October 21, ToddAndMargo via perl6-users wrote: 
> Do we have a working ftp module yet?

There are a few modules that use libcurl, which supports FTP
e.g. https://raku.land/github:CurtTilmes/LibCurl

Brian



Re: (sigils are awesome, they say ...) Re: pairs of separators from a string

2021-08-22 Thread Brian Duggan
On Sunday, August 22, Marc Chantreux wrote: 
> my ($a, $b) = { @^a[0,2...Inf], @a[1,3...Inf] }.(q<(){}[]>.comb); say $a[0]; 
> say $b[0]
> 
> oh. i never see this direct call of a lambda before but it really makes
> sense! this is the answer i like the most.

I think it's possible to avoid the explicit lambda too and just
put the expression inside the postcircumfix operator --
  
raku -e 'say q.comb[ [0,2 ... *],[1,3 ... *] ]'

((A B C D) (a b c d))

Brian


Re: REPL / Linenoise question (backslashes)

2021-07-21 Thread Brian Duggan
On Wednesday, July 21, William Michels wrote: 
> Sorry for my continuing confusion, but I don't see any use-case for an
> "unspace" at the end of a line in the Raku REPL, or the Jupyter
> kernel.

A use case would be for instance, wanting to call a method
on the next line -- so wanting to unspace the whitespace before
the method call:

Welcome to 퐑퐚퐤퐮퐝퐨™ v2021.06.
Implementing the 퐑퐚퐤퐮™ programming language v6.d.
Built on MoarVM version 2021.06.

Jupyter console 6.2.0

Welcome to Raku 曆 (rakudo 2021.06).
In [1]: 12.\
 ...: say
Out[1]: Decimal point must be followed by digit

In [2]: 12.\\
 ...: say
12

Brian


Re: REPL / Linenoise question (backslashes)

2021-07-20 Thread Brian Duggan
On Monday, July 19, William Michels via perl6-users wrote: 
> I don't see how the Raku REPL knows how to cycle from taking input at its
> prompt and moving to the read/evaluate step.

This currently happens when the parser throws one of these exceptions:

  X::Syntax::Missing
  X::Comp::FailGoal

  see https://github.com/rakudo/rakudo/blob/master/src/core.c/REPL.pm6#L281

I think this is less than awesome in some cases, which is why in
the Jupyter command line I explicitly supported using a backslash
to indicate that there is more input --

  https://github.com/bduggan/p6-jupyter-kernel#usage-notes

Brian



Re: Weird! When legal?

2021-02-24 Thread Brian Duggan
On Wednesday, February 24, rir wrote: 
> That is helpful. I don't think it conclusive.  Since I am stating
> the initial term is unknown, I think there is no legal statement
> possible.

This is legal --

  class samesame { hello samesame }

  sub hello($x) {}
  sub sameasame { "hello" }

Brian


Re: list assignment

2021-01-19 Thread Brian Duggan
Thanks everyone for the thoughtful replies.

I think this helped me the most --

On Tuesday, January 19, Vadim Belman wrote: 
> We have a documentation section on this: 
> https://docs.raku.org/language/list#Itemization

  "itemization in Arrays is assumed"

  ...

  "It was decided all those extra dollar signs and parentheses were more
  of an eye sore than a benefit to the user. Basically, when you see a
  square bracket, remember the invisible dollar signs."

With this in mind, using Bruce's suggestion of @( @both[0] ) makes
sense -- (though maybe because it reminds me of @{ ... } from Perl 5)

Brian


list assignment

2021-01-19 Thread Brian Duggan
Hi Folks,

I ran into this situation today, which seems counterintuitive:

 my @one = 1,2,3;
 my @two = 4,5,6;
 my @both = @one,@two;
 my @first = @both[0];
 say @one.raku;
 say @first.raku;

output:

[1, 2, 3]
[[1, 2, 3],]

I was expecting @first and @one to be the same.
I discovered that I could instead write either of these --

  my (@first) = @both[0];
  my @first := @both[0];

or I could change the @both assignment to be

my @both := @one, @two;

..but I wonder if there's an idiomatic approach -- or
way of thinking about this -- that makes this flow more
intuitive.

thanks
Brian


Re: Language Design: 'special casing' of split()? (i.e. .split performs concomitant .join? )

2020-10-14 Thread Brian Duggan
On Wednesday, October 14, Aureliano Guedes wrote: 
> In this point, the unique weirdness I'd like to understand is why in Raku
> `@nums.log == 2.302585092994046e0`. I don't understand where this value
> comes from.

This comes from the length of the array; the array is coerced into a numeric
value:

  > my @nums = 1..10
  [1 2 3 4 5 6 7 8 9 10]
  > @nums.log
  2.302585092994046
  > @nums.Numeric.log
  2.302585092994046
  > 10.log
  2.302585092994046

Brian


Re: Language Design: 'special casing' of split()? (i.e. .split performs concomitant .join? )

2020-10-12 Thread Brian Duggan
On Saturday, October 10, William Michels via perl6-users wrote: 
> I can point to the (functional) R-programming language to show what happens
> there. When manipulating "array-like" (i.e. vector) objects in R, you can
> do nested function calls, or sequential (piped) function calls, and still
> get the same data structure out at the end. So a 10-element input gives a
> 10-element output.

This seems pretty convenient and intuitive.  At least, it is possible
to mimic that behavior in Raku:

List.^find_method('split').wrap: { $^a.map: *.split($^b) }
List.^find_method('sin').wrap: *.map: *.sin;

my @words = ;
my @nums = 0, π/2, 3 * π/2;

say @words.split(',');
say @nums.sin;

gives us

  ((a b) (c d))
  (0 1 -1)

Brian


Re: Any other way to do this

2020-09-01 Thread Brian Duggan
On Monday, August 31, Bruce Gray wrote: 
> I finally settled on using `try` instead of numeric coercion, because
> if I am not golfing, I think `try` makes the grep look more like
> “filter out the non-numbers” instead of “get rid of the zero values”.

Another option is to use 'val' -- which parses it as a literal --

  $ raku -e 'say @*ARGS.map: { val($_) ~~ Numeric }' 1 2 3 a 1e10
   (True True True False True)

Brian


Re: print particular lines question

2020-08-31 Thread Brian Duggan
On Monday, August 31, Andy Bach wrote: 
> >  raku -ne '.say if $++ == 3|2|5' Lines.txt
> 
> OT, maybe, but is
> perl -ne 'print if $. =~ /\b[325]\b/' Lines.txt
> 
> or
> perl -ne 'print if $c++ =~ /\b[436]\b/' Lines.txt
> 
> the best you can do in P5?

I can't think of anything better :-)

Brian


Re: print particular lines question

2020-08-31 Thread Brian Duggan
On Monday, August 24, Curt Tilmes wrote: 
> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'

The -n flag is an option here too:

   raku -ne '.say if $++ == 3|2|5' Lines.txt

Brian


Re: keywords in grammars

2019-12-26 Thread Brian Duggan
On Wednesday, December 25, Alt Mcarter wrote: 
> But I'm wondering, is there a way to write token var in such a way that it
> matches <[a..z]>+ EXCEPT when it is a keyword (print, for, to, next, etc.)?

You could use a negative code assertion --

  #!/usr/bin/env raku

  my @keywords = ;

  grammar G {
rule TOP {
 
}
rule var {
  
   eq @keywords.any }>
}
token id {
  <[a..z]>+
}
  }

  use Test;

  ok G.parse('fine');
  ok G.parse('finetoo');
  nok G.parse('print');
  nok G.parse('for');
  nok G.parse('to');
  nok G.parse('next');
  ok G.parse('forth');

(you can also use before/after assertions -- 
see 
)

Brian


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

2019-12-10 Thread Brian Duggan
Hi Folks,

While the tone of this conversation is a little unpleasant
I think there are good points about the readability of the
reference documentation.

For instance, I understand that List inherits from
"Cool", but listing trigonometric functions on this
page

  https://docs.raku.org/type/List

really hurts readability; nobody is going to call "cotan"
on a list.  In my opinion, this section should maybe have
a link to the "Cool" page at most, perhaps in a footnote.

Also this exact same list appears on every page that inherits
from Cool

  https://docs.raku.org/type/Range
  https://docs.raku.org/type/Map
  https://docs.raku.org/type/Seq
  https://docs.raku.org/type/Match
  etc

I get that the list of methods is comprehensive, but I would argue that
seeing things like Match.sqrt, Seq.log10 and Range.lc are distracting and
these pages could benefit a less pedantic presentation

Brian


Re: split to walk into an HoH ?

2019-11-25 Thread Brian Duggan
On Friday, November 22, Marc Chantreux wrote: 
> hello,
> 
> > You could also use the feed operator
> 
> is there a reason to do so? i see none.

I don't think so; just a stylistic choice -- though the
documentation lists some potential benefits at the end of
the section here

  https://docs.raku.org/language/operators#infix_==%3E

(not being restricted to method chaining, and potential
parallel operation in the future)

Brian


Re: split to walk into an HoH ?

2019-11-22 Thread Brian Duggan
On Friday, November 22, Marc Chantreux wrote: 
> so it becames:
> 
> fix () perl6 -e '
> lines.map( *.split(",") )
> .classify( { .[0] }, :as{ .[1] } )
> .map: { say .key; say "\t$_" for .value.unique }
> '

You could also use the feed operator

  perl6 -e '
  lines() ==> map({split(",", $_)})
  ==> classify( {.[0]}, :as{.[1]})
  ==> sort()  # optional
  ==> map({ say .key; say "\t$_" for .value.unique })' in.csv

Brian


Re: (update the doc?) Re: run with $*OUT?

2019-06-06 Thread Brian Duggan
On Thursday, June  6, Marc Chantreux wrote: 
> this isn't obvious to guess that '-' means "you can connect the
> subprocess directly to the perl interpreter". i really think this
> example is worth to be added in the documentation.

Actually -- looks like it is there :-) though on the
Proc page, not the 'run' page --

  https://docs.perl6.org/type/Proc

> +my $p = run 'cat', '-n', :in, :out;
> +for  {
> +$p.in.say($_);
> +say $p.out.lines(1)[0];
> +}
> +$p.in.close;

I'm curious about whether you could rely
on a line being emitted right away -- e.g.
if there is some output-buffering of the
command -- this might be better handled by
a react/whenever construct.

Brian


Re: run with $*OUT?

2019-06-06 Thread Brian Duggan
On Thursday, June  6, Marc Chantreux wrote: 
> my $p = run 'cat', '-n', in => $*OUT, :out;
> $*OUT.say for < i bet on you, raku >;
> $*ERR.say: $p.out.slurp;
> 
> my $p = run 'cat', '-n', in => "/dev/stdout", :out;
> $*OUT.say for < i bet on you, raku >;
> $*ERR.say: $p.out.slurp;
> 
> my $o2 = $*OUT.clone;
> my $p = run 'cat', '-n', in => $o2, :out;
> $o2.say for < i bet on you, raku >;
> $*ERR.say: $p.out.slurp;

Something like this?

my $p = run 'cat', '-n', :in, :out;
$p.in.say($_) for ;
$p.in.close;
say $p.out.slurp;

which produces

 1  i
 2  bet
 3  on
 4  you
 5  raku


Re: list comprehension

2019-02-24 Thread Brian Duggan
Yes, +1 and we have this documented on the py-to-perl6 nutshell page:

https://docs.perl6.org/language/py-nutshell#List_comprehensions

On Friday, February 22, Lucas Buchala wrote: 
> Hello folks. Did I understand correctly that this thread is about list
> comprehension syntax in Perl 6? :-)
> I don't if it was mentioned, but I think this syntax just simply works
> already. See an example:
> 
>   > say ($_~$_ if $_ %% 2 for ^10).Set
>   set(00 22 44 66 88)
> 
>   > say ($_.item if $_[0] eq 'a' or $_[1] == 2 for  X ^3).Set
>   set((a 0) (a 1) (a 2) (b 2) (c 2))
> 
> (Just drop the .Set from the end if it's not needed)


Re: exceptions in threads

2018-11-10 Thread Brian Duggan
Oh, great!  I was running the latest version I saw
listed in 'rakudobrew list-available' which is 2018.10:

~ $ perl6 -v
This is Rakudo version 2018.10 built on MoarVM version 2018.10
implementing Perl 6.c.

thanks!
Brian

On Saturday, November 10, Elizabeth Mattijsen wrote: 
> In v6.d this throws the exception:
> 
> $ 6 'start die("bye"); sleep 1'
> Unhandled exception in code scheduled on thread 4
> bye
>   in code  at -e line 1
> 
> 
> whereas the exception is silently ignored in 6.c:
> 
> $ 6 'use v6.c; start die("bye"); sleep 1'
> 
> Not sure if this answers your question, as it is unclear from your question 
> on which version you are running.
> 
> 
> 
> > On 10 Nov 2018, at 13:59, Brian Duggan  wrote:
> > 
> > Hi Perl 6 Users,
> > 
> > What's the best way to know that an exception
> > occurred in another thread, e.g.
> > 
> >$ perl6 -e 'start say("hi"); sleep 1'
> >hi
> >$
> > 
> > but
> > 
> >$ perl6 -e 'start die("bye"); sleep 1'
> >$
> > 
> > I thought maybe $*SCHEDULER.uncaught_handler
> > would help out here, but it didn't seem to.
> > 
> > thanks
> > Brian


exceptions in threads

2018-11-10 Thread Brian Duggan
Hi Perl 6 Users,

What's the best way to know that an exception
occurred in another thread, e.g.

$ perl6 -e 'start say("hi"); sleep 1'
hi
$

but

$ perl6 -e 'start die("bye"); sleep 1'
$

I thought maybe $*SCHEDULER.uncaught_handler
would help out here, but it didn't seem to.

thanks
Brian


Re: Appropriate last words

2018-10-26 Thread Brian Duggan
Oh, good point!

Yes, but works --

  my @lines;
  $*OUT = $*OUT but role { method print($str) { @lines.push($str) } };
  note "stderr is ok";
  use Test;
  say "hello";
  is @lines[0], "hello\n", 'stdout is wrapped'

stderr is ok
ok 1 - stdout is wrapped


On Thu, Oct 25, 2018 at 9:39 PM Brandon Allbery  wrote:

> I didn't phrase that quite right.
>
> pyanfar Z$ 6 'my @lines; $*OUT.^find_method("print").wrap: -> $self, $str
> { @lines.push($str) }; use Test; note "hello"; is @lines[0], "hello\n",
> "wrapped err too"'
> ok 1 - wrapped err too
>
> This wraps it for every IO::Handle, not just for the IO::Handle in $*OUT.
> You may need "but" for that?
>
> On Thu, Oct 25, 2018 at 9:34 PM Brian Duggan  wrote:
>
>> On Thursday, October 25, Brandon Allbery wrote:
>> > You can't actually wrap print that way, can you? Or rather, if that
>> works
>> > it wouldn't be specific to $*ERR.
>>
>> Um, you definitely can, and yes it's not specific to $*ERR, e.g.
>>
>> my @lines;
>> $*OUT.^find_method('print').wrap: -> $self, $str { @lines.push($str) }
>>
>> use Test;
>> say "hello";
>> is @lines[0], "hello\n", 'said hello';
>>
>> produces
>>
>> ok 1 - said hello
>>
>> Brian
>>
>
>
> --
> brandon s allbery kf8nh
> allber...@gmail.com
>


Re: Appropriate last words

2018-10-25 Thread Brian Duggan
On Thursday, October 25, Brandon Allbery wrote: 
> You can't actually wrap print that way, can you? Or rather, if that works
> it wouldn't be specific to $*ERR.

Um, you definitely can, and yes it's not specific to $*ERR, e.g.

my @lines;
$*OUT.^find_method('print').wrap: -> $self, $str { @lines.push($str) }

use Test;
say "hello";
is @lines[0], "hello\n", 'said hello';

produces

ok 1 - said hello

Brian


Re: Appropriate last words

2018-10-25 Thread Brian Duggan
On Thursday, October 25, Richard Hainsworth wrote: 
> >: -> $status { $exit-args = $status; fail }
>
> Is the call to 'fail' replicating the original action of ?

No -- the call to fail is throwing an exception.  The idea
is that the exception could then be caught in the test.

> >: -> |c { $note-args = c; callsame; }
> Does this mean that the next routine in a chain (in this case `exit note ...
> `), so in fact `exit`, is called?

No -- "callsame" is calling the original "note".

> >$*ERR.^find_method('print').wrap: -> |c { True; }
> This wrap I am not so clear about. Why is `^find_method('print') needed?

Since callsame called note (above) note will still print
to stderr -- if we want to intercept this, i.e. to not print
to stderr, we can wrap the 'print' method of $*ERR.

This is just one of doing it...maybe I did more wrapping than
necessary :-)  And in any case, in a test suite, some of
these wraps might have to be temporary. (so that they
don't interfere with code in the test suite)

Brian


Re: Appropriate last words

2018-10-24 Thread Brian Duggan
On Sunday, October 21, Richard Hainsworth wrote: 
> so .. either I use your suggestion of 'exit note $message' which I find
> elegant, but so far difficult to test.

You could always wrap things, e.g. something like --

my ( $exit-args, $note-args );

: -> $status { $exit-args = $status; fail }
: -> |c { $note-args = c; callsame; }

$*ERR.^find_method('print').wrap: -> |c { True; }

sub run {
  exit note 'bye';
}

use Test;
try run;
is $note-args, 'bye', 'output correct';
is $exit-args.Int, 1, 'exit status is 1';
done-testing;


Re: words[] question

2018-09-26 Thread Brian Duggan
On Tuesday, September 25, Todd Chester wrote: 
> Not to ask too obvious a question, but why does words use a []
> instead of a () ?
> ...
> I am confused as to when to use [] and when to use () with a method.

If a method is called without arguments, the () can be omitted.

   "a man a plan a canal -- panama".words()
   "a man a plan a canal -- panama".words# <-- same thing

[] acts on the return value -- it takes an element of a list

   "a man a plan a canal -- panama".words()[3]
   "a man a plan a canal -- panama".words[3]  # <-- same thing

Brian


Re: An interesting math formula to share

2018-07-10 Thread Brian Duggan
On Tuesday, July 10, ToddAndMargo wrote: 
> $ echo "5" | p6 'my $N=slurp(); say $N*($N+1)/2;'
> 15
> 
> $ echo "6" | p6 'my $N=slurp(); say $N*($N+1)/2;'
> 21
> 
> $ echo "100" | p6 'my $N=slurp(); say $N*($N+1)/2;'
> 5050

Another cool thing is that this formula is used
in Perl 6 under the hood to calculate the sum of
the integers in a range instantly:

~ $ time perl6 -e 'say [+] 1..100'
5050

real0m0.213s
user0m0.250s
sys 0m0.032s

~ $ time perl6 -e 'say [+] 1..1000'
500500

real0m0.198s
user0m0.236s
sys 0m0.034s


Re: my keeper on random numbers

2018-05-27 Thread Brian Duggan
On Sunday, May 27, ToddAndMargo wrote: 
> Hi Brian,
> 
> `^name` is sweet.  Why the caret?  (I realize it won't work without it.)

The caret is shorthand for .HOW.name(object), i.e.

~ $ perl6 -e 'say 12.^name'
Int

same thing:

~ $ perl6 -e 'say 12.HOW.name(12)'
Int

Brian


Re: my keeper on random numbers

2018-05-27 Thread Brian Duggan
On Sunday, May 27, ToddAndMargo wrote: 
> Why do I sometime see a range written `0..1000`
> and `0...1000` (three dots)?

Two dots makes a Range.  Three dots is the
sequence operator -- it makes a Seq.

~ $ perl6 -e 'say (0..1000).^name'
Range
~ $ perl6 -e 'say (0...1000).^name'
Seq

Brian


Re: my keeper on random numbers

2018-05-26 Thread Brian Duggan
> To convert to an positive integer, use truncate:
> $ p6 'say 1000.rand.truncate;'
> 876

or use pick:

perl6 -e 'say (^1000).pick'
209

Brian


Re: Does words have a delimiter?

2018-04-14 Thread Brian Duggan
You can use tail:

$ perl6 -e 'say .words.tail(2)'
(bar bat)

On Saturday, April 14, yary wrote: 
> What's an elegant way of asking for the last two words? I have this:
> 
> 'foo bar bat'.words[*-2..*];# (bar bat)
> 
> I bet it could be better...
> 
> -y
> 
> On Sat, Apr 14, 2018 at 3:23 AM, JJ Merelo  wrote:
> 
> >
> >
> > 2018-04-14 7:27 GMT+02:00 ToddAndMargo :
> >
> >> Hi All,
> >>
> >> I am over on
> >> https://docs.perl6.org/routine/words
> >> and I can't make heads of tails out of it.
> >>
> >
> > Can you please report that as an issue in https://github.com/perl6/doc/
> > issues?
> >
> > Cheers
> >
> > JJ
> >


Re: awk?

2018-04-13 Thread Brian Duggan
One could also use .words --

$ echo "total kB  1804482980 112" |perl6 -n -e 'say .words[3]'
2980

Brian

On Friday, April 13, Fernando Santagata wrote: 
> Hi,
> 
> Since "There's More Than One Way To Do It", one can look for the value,
> instead of the separator:
> 
> $ echo "total kB  1804482980 112" |perl6 -n -e 'say
> .comb(/\d+/)[1]'
> 2980
> 
> 
> On Fri, Apr 13, 2018 at 12:31 PM, Shlomi Fish 
> wrote:
> 
> > Hi Todd,
> >
> > On Fri, 13 Apr 2018 03:00:22 -0700
> > ToddAndMargo  wrote:
> >
> > > echo "total kB  1804482980 112" | awk '{print $4}')
> >
> > shlomif[Perl6]:$trunk$ echo "total kB  1804482980 112" |
> > perl6
> > -n -e 'say .split(/\s+/)[3]'
> >
> > 2980
> >
> > shlomif[Perl6]:$trunk$ echo "total kB  1804482980 112" |
> > awk
> > '{print $4}'
> >
> > 2980
> >
> > See https://docs.perl6.org/language/5to6-nutshell#-a and
> > http://perldoc.perl.org/perlrun.html .
> >
> > --
> > -
> > Shlomi Fish   http://www.shlomifish.org/
> > What does “Zionism” mean? - http://shlom.in/def-zionism
> >
> > Gödel’s Incompleteness Theorem is about to be replaced by the
> > [Clarissa] Darling “Like, Totally!” Completeness Theorem.
> > — http://www.shlomifish.org/humour/bits/facts/Clarissa/
> >
> > Please reply to list if it's a mailing list post - http://shlom.in/reply .
> >
> 
> 
> 
> -- 
> Fernando Santagata


Re: Perl 6 Object Construction - General Advice

2017-09-30 Thread Brian Duggan
On Saturday, September 30, Mark Devine wrote: 
> My most common OC case:  initialize attributes at OC time from external
> input that will be parsed with grammars &/| scrubbed with elaborate
> conditional tests.

I like to use assignment for simple things and TWEAK for
complicated things --

class Foo {
has $.bar = 'something simple';
has $.baz;
submethod TWEAK {
$!baz = call-something-complicated;
}
}

Brian


[perl #132170] fork + react + IO::Socket::Async issue

2017-09-28 Thread Brian Duggan via RT
That makes sense.  Thanks for the thorough explanation.

Brian


Re: Need sub for `LWP::UserAgent`

2017-07-28 Thread Brian Duggan
On Friday, July 28, ToddAndMargo wrote: 
> I have been fighting with this all day and gave up an hour ago
> and just did a system call to curl (this is P5 code):
> 
> $CurlStatus = system (
>  "curl -L -b $AcceptCookie $ClickHere -o $NewFileName" );

There are also perl 6 bindings to libcurl, e.g.

http://modules.perl6.org/dist/LibCurl

>From the examples, it looks like ':followlocation' corresponds
to '-L'.

Brian


[perl #131717] [BUG] incorrect sum for large numbers

2017-07-08 Thread Brian Duggan via RT
On Fri, 07 Jul 2017 19:24:48 -0700, c...@zoffix.com wrote:
> [..] I'm going to reject both tickets as not a bug.
> It's just a natural outcome of treating limited-precision numbers as
> 100% precise and getting the prize of floating point noise in return.

Sounds good to me!

Brian


Re: getting help in the REPL

2017-06-14 Thread Brian Duggan
$ perl6
To exit type 'exit' or '^D'
> #|{ because } class Foo { }
(Foo)
> Foo.WHY
because
>

On Wednesday, June 14, Gabor Szabo wrote: 
> Thanks for all the responses so far.
> 
> On Wed, Jun 14, 2017 at 4:44 PM, Timo Paulssen  wrote:
> > WHY and WHEREFOR are "fully" supported, it's just that we've not put any
> > pod into the core setting and we don't have helper code that loads it
> > "lazily" when WHY is called the first time on a core class or sub …
> 
> $ perl6
> To exit type 'exit' or '^D'
> > my @x = 1, 2, 3;
> [1 2 3]
> > @x.WHY
> (Any)
> > @x.WHEREFOR
> No such method 'WHEREFOR' for invocant of type 'Array'
>   in block  at  line 1
> 
> $ perl6 -v
> This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
> implementing Perl 6.c.
> 
> 
> In additionally, can I list all the built-in variables, functions, and
> objects? While inside the REPL..
> 
> 
> regards
>   Gabor


Re: getting help in the REPL

2017-06-14 Thread Brian Duggan
On Wednesday, June 14, Gabor Szabo wrote: 
> Hi,
> 
> In the python interactive shell one can write dir(object)  and it
> lists the attributes and methods of the object. One can write
> help(object) and get the documentation of the object.
> 
> Is there anything similar in Perl 6?

object.^methods, object.^attributes and object.WHY?

Brian


Re: mocking Proc

2017-02-27 Thread Brian Duggan
On Monday, February 27, Brian Duggan wrote: 
> I tried numerous variants with multis and signatures that match the
> existing signatures, but didn't have any success.

Okay, looks like wrap does what I want:

use module;

( sub (|args) { say 'bye' } );
hello;

Brian


Re: mocking Proc

2017-02-27 Thread Brian Duggan
On Monday, February 27, Lloyd Fournier wrote: 
> You will have to use augment in this case I think:
> https://docs.perl6.org/syntax/augment
> 
> Augment Proc with your own shell method and  should call it.

No luck..

use MONKEY-TYPING;
augment class Proc  {
method shell() {
  ...
}
}

gives

Package 'Proc' already has a method 'shell' (did you mean to declare a
multi-method?)

I tried numerous variants with multis and signatures that match the
existing signatures, but didn't have any success.

Brian


Re: mocking Proc

2017-02-27 Thread Brian Duggan
On Monday, February 27, Lloyd Fournier wrote: 
> Do you mean without modifying module.pm?

Yes, ideally without modifying module.pm.

Brian


Re: mocking Proc

2017-02-27 Thread Brian Duggan
On Monday, February 27, Lloyd Fournier wrote: 
> I'd do the follwiing:
> 
> 1. make a sub named shell to overwrite the existing one that calls .shell
> on Proc.

Once I make a 'shell', is it possible for the test file
to inject my 'shell' into module.pm's namespace?

e.g. I was hoping for something like

$::(CLIENT::<>) = sub (...) { ... }

?

Brian


mocking Proc

2017-02-27 Thread Brian Duggan
Hi perl6-users,

Suppose I have a file like this:

# module.pm
sub hello is export {
shell "echo hello world"
}

and another like this:

# test.t
use module;
hello;

I want to have 'hello' invoke a 'shell' that I write,
rather than the real one, so that I can mock the
behavior of a command.  What would be the best way
to do this?

thanks
Brian


Re: [perl #130355] [RESOLVED] S/// within map doesn't work

2017-02-02 Thread Brian Duggan
Great.  I tested the original example with the change and verified
that it works.

./perl6 -e 'say .map({S/a/x/}).perl'
("x1", "x2", "x3").Seq

thanks!
Brian


Re: mocking $*OUT

2017-01-25 Thread Brian Duggan
Thanks, Timo and Moritz.

> Because say() is a high-level function that uses the lower-level
> $*OUT.print under the hood.

Ah, so an alternative would be to just redefine the sub:

  my $str = '';

  sub say($arg) {
$str ~= $arg 
  }

  say 'hi';

  use Test;
  is $str, 'hi', 'works';

Works great!  

Brian


mocking $*OUT

2017-01-24 Thread Brian Duggan
Hi All,

This code:

  my $str = '';
  class Mock {
method say($arg) { $str ~= $arg }
  }
  $*OUT = Mock.new;
  say 'hi';

produces:

  Too many positionals passed; expected 1 argument but got 2
in block  at out.p6 line 6

Changing the signature of say doesn't seem to help.

If I change 'say' to 'print' in Mock, things work
fine, though I'm having a hard time figuring out why
the code above doesn't work.  Any ideas?

thanks
Brian


Re: grammars and indentation of input

2016-09-13 Thread Brian Duggan
I've also recently been experimenting with parsing an
indent-based language -- specifically, a small subset
of Slim () -- I push to a stack
when I see a tag, and pop based on the depth of the
indendation.

Here's a working example:

  https://git.io/vig93

Brian


Re: Observations from a C++/Python developer that never used Perl5

2016-09-10 Thread Brian Duggan
The pair constructor seems to be in a different category than the other
quoting operators since the expression that it quotes must look like an
identifier:

https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Grammar.nqp#L1776

token fatarrow {