Re: Running external CLI tool and capturing output

2017-08-10 Thread Gabor Szabo
Oh right. Thanks. I forgot about them. Maybe
https://docs.perl6.org/routine/run should mention them as well.

In any case a simpler way to capture everything might be useful.

Gabor

On Thu, Aug 10, 2017 at 6:09 PM, Brock Wilcox
 wrote:
> How about qx and qxx? I guess those don't separate/capture stderr, and don't
> separate out the params.
>
> --Brock
>
>
> On Thu, Aug 10, 2017 at 10:57 AM, Gabor Szabo  wrote:
>>
>> The documentation has a nice example showing how to run an external
>> program and how to get its output or even its standard error.
>> https://docs.perl6.org/type/Proc
>>
>> However it looks a lot more complex than the plain backtick Perl 5 has
>> and more complex than the capture function of Capture::Tiny.
>> IMHO it is way too much code.
>>
>> I wrote a simple function wrapping it:
>>
>> sub capture(*@args) {
>> my $p = run @args, :out, :err;
>> my $output = $p.out.slurp: :close;
>> my $error  = $p.err.slurp: :close;
>> my $exit   = $p.exitcode;
>>
>> return {
>> out  => $output,
>> err  => $error,
>> exit => $exit;
>> };
>> }
>>
>> It can be used as:
>>
>> my $res = capture($*EXECUTABLE, 'bin/create_db.pl6');
>> say $res;
>>
>> or even
>>
>> say capture($*EXECUTABLE, 'bin/create_db.pl6');
>>
>> I wonder if I have just invented something that already exist in
>> Rakudo or if it is not there, then wouldn't it be a good idea to add
>> such a simple way to run external commands?
>>
>> regards
>>Gabor
>> ps. Backtick actually expected a single string and not a list of
>> parameters and supporting that mode, even if it is less secure, might
>> be also a good idea.


Running external CLI tool and capturing output

2017-08-10 Thread Gabor Szabo
The documentation has a nice example showing how to run an external
program and how to get its output or even its standard error.
https://docs.perl6.org/type/Proc

However it looks a lot more complex than the plain backtick Perl 5 has
and more complex than the capture function of Capture::Tiny.
IMHO it is way too much code.

I wrote a simple function wrapping it:

sub capture(*@args) {
my $p = run @args, :out, :err;
my $output = $p.out.slurp: :close;
my $error  = $p.err.slurp: :close;
my $exit   = $p.exitcode;

return {
out  => $output,
err  => $error,
exit => $exit;
};
}

It can be used as:

my $res = capture($*EXECUTABLE, 'bin/create_db.pl6');
say $res;

or even

say capture($*EXECUTABLE, 'bin/create_db.pl6');

I wonder if I have just invented something that already exist in
Rakudo or if it is not there, then wouldn't it be a good idea to add
such a simple way to run external commands?

regards
   Gabor
ps. Backtick actually expected a single string and not a list of
parameters and supporting that mode, even if it is less secure, might
be also a good idea.


Memory leak or just normal usage in Rakudo?

2017-08-03 Thread Gabor Szabo
Hi,

I think I've mentioned earlier that we see some memory leaks in Bailador.
I've started to investigate it by creating a small function that would
use "ps" to get the memory usage of the current process.

The first step was to do some sanity check and so I wrote a test script:

https://github.com/szabgab/p6-memory/blob/master/t/memory-usage.t

As I am far from being an expert in the field, I wonder if checking
the VSZ as reported by ps is even a good indication of the memory
consumption of a process?

Then I've to note that the results were different in almost every run
which makes me further wonder why?

The numbers are also drastically different between my OSX and running
on Travis-CI, though Rakudo is also different.

Does any of this make sense? Does it indicate any memory leak in
Rakudo already or is this just normal memory usage?

How could I improve my measuring and what else should I measure?

regards
Gabor


Re: Need sub for `LWP::UserAgent`

2017-07-28 Thread Gabor Szabo
On Fri, Jul 28, 2017 at 9:49 AM, ToddAndMargo  wrote:
>>> Hi All,
>>>
>>> I am trying to convert a p5 program to p6.  What do I use in
>>> place of `LWP::UserAgent`?
>>>
>>> I use it for downloading files from the web.  I need to be able
>>> to pass the following to the web page:
>>>
>>> Caller
>>> Host
>>> UserAgent
>>> Referer
>>> Cookies
>>>
>>> This is the p5 code I want to convert:
>>>
>>>http://vpaste.net/gtJgj
>>>
>>> Any words of wisdom?
>>>
>>> Many thanks,
>>> -T
>
> On 07/27/2017 10:30 PM, Gabor Szabo wrote:
>>
>> LWP::Simple now allows you to set the header of your request.
>> See my recent article with examples:
>> http://perl6maven.com/simple-web-client
>> I hope this helps.
>>
>> regards
>> Gabor
>>
>> On Fri, Jul 28, 2017 at 7:42 AM, Todd Chester 
>> wrote:
>
>
>
> I see your article.  I do believe this is what I want.
> 
> {
>   "args": {
> "language": "Perl",
> "math": "19+23=42",
> "name": "Larry Wall"
>   },
>   "headers": {
> "Connection": "close",
> "Host": "httpbin.org",
> "User-Agent": "LWP::Simple/0.090 Perl6/rakudo"
>   },
>   "origin": "17.19.208.37",
>   "url": "http://httpbin.org/get?name=Larry
> Wall&language=Perl&math=19%2B23%3D42"
> }
> 
>
> Questions:
>
> 1) may I leave off the `args` and only include the `headers`?
>
> 2) I need an example with headers.  I have no clue what goes
>before the first "{"
>
> Many thanks,
> -T

I think you quoted the response here and not the request.
What you need I think is the last example on that page.
Something like this:

my $html = LWP::Simple.new.get("http://httpbin.org/headers";, {
"User-Agent" => "Perl 6 Maven articles",
"Zone" => "q" }
);


Gabor


Re: Need sub for `LWP::UserAgent`

2017-07-27 Thread Gabor Szabo
LWP::Simple now allows you to set the header of your request.
See my recent article with examples: http://perl6maven.com/simple-web-client
I hope this helps.

regards
   Gabor

On Fri, Jul 28, 2017 at 7:42 AM, Todd Chester  wrote:
> Hi All,
>
> I am trying to convert a p5 program to p6.  What do I use in
> place of `LWP::UserAgent`?
>
> I use it for downloading files from the web.  I need to be able
> to pass the following to the web page:
>
>Caller
>Host
>UserAgent
>Referer
>Cookies
>
> This is the p5 code I want to convert:
>
>   http://vpaste.net/gtJgj
>
> Any words of wisdom?
>
> Many thanks,
> -T


Re: set (+) set = bag ?

2017-07-21 Thread Gabor Szabo
On Fri, Jul 21, 2017 at 2:07 PM, Timo Paulssen  wrote:
> You want (|) to get the union of two sets as a set.
>
> https://docs.perl6.org/language/setbagmix#Set%2FBag_Operators
>
> hth
>   - Timo

Oh thanks. Now I see there is also a link just under the "Operators"
section of the Set article.
I might not pay enough attention to details, I was looking for the
word  "union" in the article about Sets and haven't even noticed that
link.

I was already adding some more operators to that table when I got your reply.
Now I am not sure if that's needed or how to avoid unnecessary
frustration and questions by others.

Gabor


set (+) set = bag ?

2017-07-21 Thread Gabor Szabo
Looking at Sets https://docs.perl6.org/type/Set

I was happy to see (-) to work as I expected, but I was surprised to see
that (+) created a bag. Is that intentional? How can I get back the
set. Is the only way using the unicode character ∪ ?

(This is Rakudo version 2017.04.3 so I might be behind the times on this.)


$ perl6
To exit type 'exit' or '^D'
> my $a = set('a','b')
set(b, a)
> my $b = set('a', 'c')
set(a, c)

> $a
set(b, a)
> $b
set(a, c)

> $a (-) $b
set(b)
> $b (-) $a
set(c)


> $a (+) $b
bag(b, a(2), c)

> $a ∪ $b
set(b, a, c)

Gabor


Re: Memory usage

2017-07-20 Thread Gabor Szabo
On Thu, Jul 20, 2017 at 12:37 PM, Timo Paulssen  wrote:
> On 19/07/17 21:52, Gabor Szabo wrote:
>> Hi,
>>
>> is it possible to get the size of memory used by the current Perl 6
>> process? (From inside the code)
>> Is it possible to get the size of the individual variables?
>>
>> Gabor
>
> I'm not aware of something cross-platform that rakudo offers for memory
> use of a process, and getting the size of individual variables is an
> extremely hairy topic.
>
> You can use the --profile=heap target to get full snapshots of all
> objects in memory whenever GC kicks in, and go through it with the
> moar-heapanalyzer tool jnthn made.
>
> I had a pull-request open for an op i called "vmhealth" that would
> output a bunch of statistics including what the different allocators are
> doing, but progress halted when I didn't get input or came up with good
> ideas for what else to include. Here's the PR:
> https://github.com/MoarVM/MoarVM/pull/536
>
> The reason why "memory in use" is difficult is because of many things
> not having a single owner. Imagine an array, where you could have bound
> the individual containers to any amount of lexical variables, for example.
>
> Also, if there's exactly one Rat in the whole program, do you count the
> presence of the class itself as being used by the variable that holds
> that Rat?
>
> hope that sheds some light
>   - Timo

Thanks for the explanation. I hope your PR will make progress.

BTW the reason I asked this is as I think there is a memory leak
somewhere in Bailador
and I was hoping to use this to track it down. Any Perl 6 or Rakudo
specific suggestions for that?

Gabor


Memory usage

2017-07-19 Thread Gabor Szabo
Hi,

is it possible to get the size of memory used by the current Perl 6
process? (From inside the code)
Is it possible to get the size of the individual variables?

Gabor


Re: processing misunderstand or bug?

2017-07-15 Thread Gabor Szabo
Thank you!
This helped us solve a major headache we had with processes hanging
around after the tests have finished:

https://github.com/Bailador/Bailador/issues/194

regards
Gabor


Re: processing misunderstand or bug?

2017-07-15 Thread Gabor Szabo
Hi,

Brandon, thanks for the explanation.

If I understand correctly, then this means Ctrl-C sends a SIGINT to
both the main process I ran and the child process I created using
Proc::Async.  When I run kill -2 PID it only sends the SIGINT to the
process I mentioned with PID.
(Which in my case was the process I ran.)

Then here is the problem which is closer to our original problem. I
have another script that uses Proc::Async to launch the previous
process. So now I have a main process, that has a child process which
has a child process.

use v6;
my $proc = Proc::Async.new($*EXECUTABLE, "async.pl6");
$proc.stdout.tap: -> $s { print $s };
my $promise = $proc.start;
sleep 10;
$proc.kill;

The "kill" there kill the immediate child but leaves the grandchild running.

Is there a way to send a signal to all the processes created by that
Proc::Async.new and to their children as well?

What I came up now is that changed the previous script (called
async.pl6) and added a line:

signal(SIGINT).tap( { say "Thank you for your attention"; $proc.kill } );

as below:

use v6;
my $proc = Proc::Async.new($*EXECUTABLE, "-e", "sleep 2; say 'done'");
$proc.stdout.tap: -> $s { print $s };
my $promise = $proc.start;
signal(SIGINT).tap( { say "Thank you for your attention"; $proc.kill } );
await $promise;

Gabor


processing misunderstand or bug?

2017-07-15 Thread Gabor Szabo
Hi,

I don't understand this, and I wonder could shed some light on the situation?

I have the following experimental program:

use v6;
my $proc = Proc::Async.new($*EXECUTABLE, "-e", "sleep 2; say 'done'");
$proc.stdout.tap: -> $s { print $s };
my $promise = $proc.start;
await $promise;

If I run this in one terminal and run "ps axuw" in another terminal I
see 2 processes running.
If I press Ctrl-C in the terminal where I launched the program, both
processes are closed.

OTOH If I run "kill PID" with the process ID of the parent process
then only that process is killed. The child process is still waiting
for the prompt.

It does not make any difference if I use kill PID, or kill -2 PID or
kill -3 PID.

I'd understand that "kill PID" leaves the child process but then why
does Ctrl-C kill both? And then how comes "kill -2 PID", which as I
understand must be the same SIGINT as the Ctrl-C, only kills the
parent?


This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
running on OSX.

regards
Gabor


clone and deep copy of arrays

2017-07-11 Thread Gabor Szabo
Hi,

I wonder what does .clone do and how can I create a deep copy or deep
clone of an array?

Reading https://docs.perl6.org/type/Array#method_clone I don't
understand what does it do as the example there works without clone as
well:

suggest I'd need a

> my @a = (1, 2, 3)
[1 2 3]
> my @b = @a;
[1 2 3]
> @a[1] = 42
42
> @b.append(100)
[1 2 3 100]
> dd @a
Array @a = [1, 42, 3]
Nil
> dd @b
Array @b = [1, 2, 3, 100]
Nil


On the other hand if I have a deeper data structure, then even .clone
does not help.


> my @x = {a => 1}, {b => 2};
[{a => 1} {b => 2}]
> my @y = @x.clone
[{a => 1} {b => 2}]
> @x[0] = 42
42
> dd @x
Array @x = [{:a(42)}, {:b(2)}]
Nil
> dd @y
Array @y = [{:a(42)}, {:b(2)}]
Nil

So I wonder what does .clone do and how could I make a deep copy (deep
clone) of the whole data structure I have in @x.

regards
   Gabor


Proc::Async .kill does not work on Bailador

2017-07-07 Thread Gabor Szabo
Hi,

In a test of Bailador we are launching an instance of Bailador using
Proc::Async and then when we are done we would like to kill the other
process using .kill(9)
Unfortunately this does not seem to have any impact on the process and
it keeps running even after we send that kill signal.

(at leas on OSX and "This is Rakudo version 2017.04.3 built on MoarVM
version 2017.04-53-g66c6dda implementing Perl 6.c." where I tried.)

I can use the "kill" on the command line and that kills the process.

The code is in the subtest on line 120 in this commit:

https://github.com/Bailador/Bailador
/blob/06301f145281f811a4448237e07b8e0be201b195/t/20-cli.t#L102

If you have any thoughts of why this might happen, I'd appreciate your help.

Gabor


Travis for Perl 6

2017-07-07 Thread Gabor Szabo
Hi,

as I understand if I use Travis for a Perl 6 project with

language: perl6
perl6:
  - latest

it will compile Rakudo and it takes bout 15 minutes.

Is there a way to use a pre-compiled version of Rakudo
that will be much faster?

regards
   Gabor


Re: accepting values on the command line

2017-07-01 Thread Gabor Szabo
On Sat, Jul 1, 2017 at 4:30 PM, Elizabeth Mattijsen  wrote:
>
>> On 1 Jul 2017, at 15:15, Gabor Szabo  wrote:
>>
>> I was hoping to wrote a simple script that would accept a bunch of
>> filenames on the command line so I wrote:
>>
>> #!/usr/bin/env perl6
>> use v6;
>>
>> multi sub MAIN(@files) {
>>say @files.perl;
>> }
>
> This signature will only accept an Iterable.  The command line parameters are 
> *not* considered a list, so this will not match.  What you need is a slurpy 
> array:
>
> multi sub MAIN(*@files) {
> say @files.perl;
> }
>
>
> $ 6 'sub MAIN(*@a) { dd @a }' a b c d
> ["a", "b", "c", "d"]
>

thanks
Gabor


accepting values on the command line

2017-07-01 Thread Gabor Szabo
I was hoping to wrote a simple script that would accept a bunch of
filenames on the command line so I wrote:


#!/usr/bin/env perl6
use v6;

multi sub MAIN(@files) {
say @files.perl;
}



$ perl6 code.pl6
Usage:
  code.pl6 

$ perl6 code.pl6 abc
Usage:
  code.pl6 

$ perl6 code.pl6 abc def
Usage:
  code.pl6 

I got desperate, but that did not help either:
$ perl6 code.pl6 --files abc
Usage:
  code.pl6 


I am rather confused by this.


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


Gabor


Re: not enough memory

2017-06-29 Thread Gabor Szabo
On Thu, Jun 29, 2017 at 11:43 AM, Lloyd Fournier  wrote:
> I'm not sure if it's related but I've been getting a few weird memory
> related issues with HEAD and zef. e.g my travis build just segfaulted:
>
> https://travis-ci.org/spitsh/spitsh/builds/248242106#L1355
>
> And a day or so ago I got:
>
> "MoarVM panic: Heap corruption detected: pointer 0x7f0fe9a16410 to past
> fromspace"
> https://travis-ci.org/spitsh/spitsh/builds/247357557#L1355
>
> Are you also using a recent rakudo?

Not really.

This is Rakudo version 2017.06 built on MoarVM version 2017.06
implementing Perl 6.c.


>
> LL
>
>
> On Thu, Jun 29, 2017 at 4:37 PM Gabor Szabo  wrote:
>>
>> hi,
>>
>> I've got this "not enough memory" twice today while trying to upgrade
>> some packages using zef.
>> Once when I ran 'zef upgrade zef' and then again when I ran
>> 'zef --debug upgrade Bailador'.
>>
>> In both cases the error was shown during the running of the tests.
>>
>> After running the first command again it worked.
>>
>> The second command kept the same error message.
>>
>> This machine had 1 Gb memory.
>>
>> After adding another Gb the second command worked as well.
>>
>> Gabor


not enough memory

2017-06-28 Thread Gabor Szabo
hi,

I've got this "not enough memory" twice today while trying to upgrade
some packages using zef.
Once when I ran 'zef upgrade zef' and then again when I ran
'zef --debug upgrade Bailador'.

In both cases the error was shown during the running of the tests.

After running the first command again it worked.

The second command kept the same error message.

This machine had 1 Gb memory.

After adding another Gb the second command worked as well.

Gabor


Re: The speed (improvement) of Rakudo

2017-06-16 Thread Gabor Szabo
The first one is the closest to what I was hoping to see. Very
impressive. Thanks.

Gabor


On Sat, Jun 17, 2017 at 9:10 AM, H.Merijn Brand  wrote:
> On Sat, 17 Jun 2017 07:46:46 +0300, Gabor Szabo 
> wrote:
>
>> Hi,
>>
>> Is there some measurements regarding the speed of Rakudo?
>
> Mine are probably the longest record of speed measurements, but it is
> just measuring one task (that uses a lot of operations). It is not
> measuring all aspects of perl6
>
> http://tux.nl/Talks/CSV6/speed4.html
>
> And a comparison of that task to other languages
>
> http://tux.nl/Talks/CSV6/speed5.html
>
> And the explanation of what it shows
>
> https://github.com/Tux/CSV/blob/master/README.speed
>
> Is that what you were looking for?
>
>> e.g. It would be nice to have a graph of some hand-picked operations
>> measured at different points in time of the development of Rakudo and
>> then graphed in a nice way. Is there anything like that?
>>
>> Gabor
>
> --
> H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
> using perl5.00307 .. 5.27   porting perl5 on HP-UX, AIX, and openSUSE
> http://mirrors.develooper.com/hpux/http://www.test-smoke.org/
> http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/


The speed (improvement) of Rakudo

2017-06-16 Thread Gabor Szabo
Hi,

Is there some measurements regarding the speed of Rakudo?

e.g. It would be nice to have a graph of some hand-picked operations
measured at different points in time of the development of Rakudo and
then graphed in a nice way. Is there anything like that?

Gabor


Re: next

2017-06-16 Thread Gabor Szabo
On Sat, Jun 17, 2017 at 4:19 AM, ToddAndMargo  wrote:
> On 06/16/2017 06:08 PM, Brandon Allbery wrote:
>>
>> On Fri, Jun 16, 2017 at 9:02 PM, ToddAndMargo > > wrote:
>>
>> I am afraid I am not understanding "next" again.
>>
>> When you invoke it, does it pop you back at the start of
>> the loop or just cough up the next value?
>>
>>
>> The former. Or you can think of it as jumping past everything else in the
>> loop body so the next thing it does is get the next value and run the loop
>> body with it.
>
>
> Hi Brandon,
>
> I kept thinking it was going to cough up the next value,
> not restart the loop.

I probably would not say "restart" the loop.
It goes to the *next* iteration of the loop:


If the loop has a condition it jumps to check that condition again and
acts accordingly.
(If the condition is true it does the next iteration, if the condition
is false it ends the loop.)

use v6;

my $i = 0;

while $i < 6 {
$i++;
next if $i %% 2;   # if it can be divided by two go to next iteration
say $i;
}

prints
1
3
5


If the loop has some action and a condition it will jump to  execute
the action again (increment $i) and check the condition and act
accordingly doing the next iteration or quitting the loop.

use v6;

loop (my $i = 0; $i < 10; $i++)  {
next if $i %% 2;# if it can be divided by two go to next iteration
say $i;
}

will print
1
3
5
7
9


Gabor


Re: How do you call the variable types?

2017-06-15 Thread Gabor Szabo
On Sat, Jun 10, 2017 at 9:38 AM, Brent Laabs  wrote:
> I thought:
> $ is Scalar
> @ is Array
> % is Hash
> & is a function
>

Reading this https://docs.perl6.org/language/containers I just found
out that a @-variable can also contain a List,
not just an array:

> my @z = ()
[]
> @z.^name
Array
> my @z := ()
()
> @z.^name
List

Gabor

>> 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 &x; &x.VAR.WHAT
> (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 &foo.  These function calls are all
> equivalent:
>> my &x = sub { say "called" };
> sub () { #`(Sub|140204743370112) ... }
>> x()
> called
>> &x()
> called
>> my $y = &x; $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: getting help in the REPL

2017-06-14 Thread Gabor Szabo
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


getting help in the REPL

2017-06-14 Thread Gabor Szabo
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?

Gabor


Re: Undeclared routine: break used at line ...

2017-06-13 Thread Gabor Szabo
On Tue, Jun 13, 2017 at 9:33 PM, Elizabeth Mattijsen  wrote:
>> On Tue, Jun 13, 2017 at 8:50 PM, Elizabeth Mattijsen  wrote:
>>>> On 13 Jun 2017, at 19:34, Gabor Szabo  wrote:
>>>>
>>>> I just managed to write
>>>>
>>>> while True {
>>>>   ...
>>>>   break if $code eq 'exit';
>>>>   ...
>>>> }
>>>>
>>>>
>>>> I wonder if Rakudo could be more cleaver in this particular case and
>>>> remind me to use 'last' instead of 'break'.
>>> Is the undeclared sub error not helpful enough?
>> I think for someone who comes from a language where 'break' is the
>> keyword, this would be very surprising
>> and an telling that person it is called 'last' in Perl 6 would be a nice 
>> touch.
>
> After https://github.com/rakudo/rakudo/commit/69b1b6c808 you get:
>
> $ 6 'break'
> ===SORRY!=== Error while compiling -e
> Undeclared routine:
> break used at line 1. Did you mean 'last’?
>
> $ 6 'sub brake() {}; break'
> ===SORRY!=== Error while compiling -e
> Undeclared routine:
> break used at line 1. Did you mean 'brake', 'last’?
>
>
> :-)
>
>
> Liz

Thank you :)

Gabor


Re: Undeclared routine: break used at line ...

2017-06-13 Thread Gabor Szabo
On Tue, Jun 13, 2017 at 8:50 PM, Elizabeth Mattijsen  wrote:
>
>> On 13 Jun 2017, at 19:34, Gabor Szabo  wrote:
>>
>> I just managed to write
>>
>> while True {
>>...
>>break if $code eq 'exit';
>>...
>> }
>>
>>
>> I wonder if Rakudo could be more cleaver in this particular case and
>> remind me to use 'last' instead of 'break'.
>
> Is the undeclared sub error not helpful enough?

I think for someone who comes from a language where 'break' is the
keyword, this would be very surprising
and an telling that person it is called 'last' in Perl 6 would be a nice touch.

>
> Alternately, you could do:
>
>   my &break := &last;
>
> and have it just do the right thing  :-)
>
>
> Finally,
>
>   while True {
>
> is better written as:
>
>   loop {
>
> :-)
>
>
>
> Liz

Thanks
   Gabor


Undeclared routine: break used at line ...

2017-06-13 Thread Gabor Szabo
I just managed to write

while True {
...
break if $code eq 'exit';
...
}


I wonder if Rakudo could be more cleaver in this particular case and
remind me to use 'last' instead of 'break'.

Gabor


Re: How do you call the variable types?

2017-06-09 Thread Gabor Szabo
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


How do you call the variable types?

2017-06-08 Thread Gabor Szabo
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


How to install from a specific Git branch?

2017-06-07 Thread Gabor Szabo
Hi There!

In the Bailador project we use a branch called 'dev' for development
and one called 'main' for releases. Or at least we try to.

In the META.list of the ecosystem
https://github.com/perl6/ecosystem/blob/master/META.list we have
listed the 'main' branch:
https://raw.githubusercontent.com/Bailador/Bailador/main/META6.json

However it seems that zef still installs from the 'dev' branch which
is the "Default branch" on GitHub. At least when running on Travis-CI
(of another project that has Bailador as its dependency).  (It could
not install Bailador:
https://travis-ci.org/szabgab/6blog/builds/240466600 because some new
files were not added to the provides key of the META file. After
fixing it on the 'dev' branch:
https://travis-ci.org/szabgab/6blog/builds/240481882 )

Am I misunderstanding something here? Do I need to make some further
changes in the META file of Bailador
https://github.com/Bailador/Bailador or the other code that used
Bailador: https://github.com/szabgab/6blog in order to tell zef to
install from the 'main' branch? Is this a Travis related thing?


regards
Gabor
ps. The Bailador crowdfunding now has 99 supporters. It would be nice
to see you too!
https://www.indiegogo.com/projects/book-web-application-development-in-perl-6-website--2/reft/775728/p6user-0607


Re: Is there a linter for Perl 6? (like Perl::Critic or pylint)

2017-06-03 Thread Gabor Szabo
I think that runs perl6 -c, right?
Then no, I did not mean that.
I mean a tool for static analysis like Perl::Critic in Perl 5 that
would point out potential bugs,
or recommend better practices.

I've added a very naive implementation of checking for "use v6;"
https://github.com/Bailador/Bailador/blob/main/t/00-lint.t

regards
Gabor

On Thu, Jun 1, 2017 at 2:50 PM, Ahmad Zawawi  wrote:
> Hi Gabor,
>
> Like https://atom.io/packages/atom-perl6-editor-tools for instance or
> project-level linting?
>
> Regards,
> Ahmad
>
>
> On Thu, Jun 1, 2017 at 9:02 AM, Gabor Szabo  wrote:
>>
>> e.g. I'd like to check that every pl pm and t file in our project has a
>> "use v6;" at the beginning.
>>
>> regards
>>Gabor
>
>


Re: Creating an array of a single hash

2017-06-01 Thread Gabor Szabo
On Thu, Jun 1, 2017 at 5:44 PM, Timo Paulssen  wrote:
> Yeah, you can use the prefix $ to itemize things, like so:
>
> timo@schmand ~> perl6 -e 'my @y = ${ name => "Foo" }; say @y.gist;
> say @y.^name; say @y[0].^name'
> [{name => Foo}]
> Array
> Hash
>
> HTH
>   - Timo

Thanks.
Gabor


Creating an array of a single hash

2017-06-01 Thread Gabor Szabo
use v6;

my @x = { name => "Foo" }, { name => "Bar"}
say @x.gist; # [{name => Foo} {name => Bar}]
say @x.^name;# Array
say @x[0].^name; # Hash

my @y = { name => "Foo" }
say @y;   # [name => Foo]
say @y.^name; # Array
say @y[0].^name;  # Pair

my @z = { name => "Foo" },;
say @z;   # [{name => Foo}]
say @z.^name; # Array
say @z[0].^name;  #  Hash


In the first example, creating an array of 2 hashes work.
In the second example the listy assignment removes the hashy-ness of
the right hand side.
In the 3rd example adding a comma at the end solves the problem.

Is this how it is recommended to initiate an array with a single hash?
Is there an operator that forces the assignment to item-assignment?

Gabor


Is there a linter for Perl 6? (like Perl::Critic or pylint)

2017-05-31 Thread Gabor Szabo
e.g. I'd like to check that every pl pm and t file in our project has a
"use v6;" at the beginning.

regards
   Gabor


slightly unexpected JSON roundtrip for arrays

2017-05-31 Thread Gabor Szabo
When converting an array to json and then back again, I need to use |
or () in order to get back the original array in a @variable.

This surprised me, especially as for hashes the roundtrip worked
without any extra work.
I was wondering if this is really the expected behaviour?

Gabor

use v6;
use JSON::Fast;
#use JSON::Tiny;

my @elems1;
@elems1.push: {
name => 'Foo',
id   => 1,
};

say @elems1.gist; # [{id => 1, name => Foo}]

my $json_str = to-json @elems1;
#say $json_str;

my (@elems2) = from-json $json_str;
say @elems2.gist;# [{id => 1, name => Foo}]

my @elems3 = | from-json $json_str;
say @elems3.gist; # [{id => 1, name => Foo}]

my @elems4 = from-json $json_str;
say @elems4.gist;# [[{id => 1, name => Foo}]]


how to get the name of the executable of an installed script?

2017-05-29 Thread Gabor Szabo
Original bug report: https://github.com/Bailador/Bailador/issues/119

$ bailador
Usage:

/Applications/Rakudo/share/perl6/site/resources/71985446A5DBC3EB1694DCE3776293A522E54A58
--help (shows this help)

/Applications/Rakudo/share/perl6/site/resources/71985446A5DBC3EB1694DCE3776293A522E54A58
Project-Name   (creates a directory called Project-Name with a
skeleton application)

The code that prints this out uses $*PROGRAM-NAME but apparently the
original program Bailador supplies is installed as
/Applications/Rakudo/share/perl6/site/resources/71985446A5DBC3EB1694DCE3776293A522E54A58
and the program which is installed as "bailador"


$ which bailador
/Applications/Rakudo/share/perl6/site/bin//bailador

is some standardized code snippet created by the installation (zef ?)
that launches the actual script using run().

So $*PROGRAM-NAME is correctly showing that long and horrible name,
but that's rather useless for the end-user.


Gabor


Re: run() not capturing exitcode properly?

2017-05-29 Thread Gabor Szabo
On Tue, May 30, 2017 at 7:21 AM, Gabor Szabo  wrote:
>> my $p = run "ls", "dadsad", :out, :err;
> Proc.new(in => IO::Pipe, out => IO::Pipe.new(:path(""),:chomp), err =>
> IO::Pipe.new(:path(""),:chomp), exitcode => 0, signal => 0, command =>
> ["ls", "dadsad", "adadsa"])
>>
>> $p.exitcode
> 0
>
>
> While for the same command in the shell   $? will hold 1 as the
> directory does not exist.
>
> Is this a bug or am I misunderstanding something?
>
> This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
> implementing Perl 6.c.
>
> Running on OSX.
>
> Gabor

On the other hand if I try to access the captured output or error, an
exception is raised:

> $p.out.slurp: :close;
The spawned command 'ls' exited unsuccessfully (exit code: 1)
  in block  at  line 1\


run() not capturing exitcode properly?

2017-05-29 Thread Gabor Szabo
> my $p = run "ls", "dadsad", :out, :err;
Proc.new(in => IO::Pipe, out => IO::Pipe.new(:path(""),:chomp), err =>
IO::Pipe.new(:path(""),:chomp), exitcode => 0, signal => 0, command =>
["ls", "dadsad", "adadsa"])
>
> $p.exitcode
0


While for the same command in the shell   $? will hold 1 as the
directory does not exist.

Is this a bug or am I misunderstanding something?

This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
implementing Perl 6.c.

Running on OSX.

Gabor


Re: .add missing from IO::Path?

2017-05-28 Thread Gabor Szabo
On Sun, May 28, 2017 at 11:29 PM, Timo Paulssen  wrote:
> what version of rakudo are you on?

This is Rakudo version 2017.01 built on MoarVM version 2017.01

After upgrading to 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
it started to work.

It is magic!

:)

Gabor
/me thanks Timo and goes hiding a bit


.add missing from IO::Path?

2017-05-28 Thread Gabor Szabo
Reading https://docs.perl6.org/type/IO::Path#method_child
I thought I need to use .child or .add but .add does not seem to work:

"foo/bar".IO.add("def")
No such method 'add' for invocant of type 'IO::Path'
  in block  at  line 1


Gabor


zef, zef-j, zef-m

2017-05-28 Thread Gabor Szabo
Hi,

I've just noticed that in /Applications/Rakudo/share/perl6/site/bin/ I
have 3 copies
of every script. One with a -j and one with a -m at the end just as for zef:

zef
zef-j
zef-m

The files seem to be identical.

Why are there 3 and what is their purpose?

Gabor


Re: Absolute path to directory of the current perl program

2017-05-27 Thread Gabor Szabo
Nice.

I think this would be a good addition to the docs :)

You can also write

   $*PROGRAM.parent.parent.parent.parent.absolute;

but if your relative path is too short, you might end up with a bunch
of .. like this:

/Users/gabor/work/perl6maven.com/../..

Gabor

On Sun, May 28, 2017 at 9:10 AM, Lloyd Fournier  wrote:
> After thinking about what Zoffix said, probably what you're meant to do is:
>
> $*PROGRAM.parent.absolute
>
> Which leaves the stringification (.absolute) until last.
>
>
> On Sun, May 28, 2017 at 4:04 PM Lloyd Fournier 
> wrote:
>>
>> FYI:
>>
>> 15:57 < llfourn> Zoffix: is there any plan to make .dirname and .absolute
>> on IO::Path return an IO::Path?
>> 15:58 < llfourn> (rather than a Str)
>> 15:58 < Zoffix> llfourn: no
>> 15:58 < Zoffix> .absolute is one of the two ways to stringify an IO::Path
>> (the second being .relative)
>> 15:58 < Zoffix> And .dirname is part of .parts; all Str objects as well
>>
>>
>> On Sun, May 28, 2017 at 3:54 PM Gabor Szabo  wrote:
>>>
>>> thanks.
>>>
>>> $*PROGRAM.dirname.IO.absolute;
>>>
>>> also works, but yours seem better.
>>>
>>> As a side note, dirname does not return and IO::Path object either.
>>>
>>> Gabor
>>>
>>>
>>> On Sat, May 27, 2017 at 6:48 PM, Lloyd Fournier 
>>> wrote:
>>> > I'd use
>>> >
>>> > $*PROGRAM.absolute.IO.dirname
>>> >
>>> > I'm not sure why .absolute doesn't return an IO::Path object. Maybe
>>> > that's
>>> > being addressed as part of Zoffix++'s IO work.
>>> >
>>> >
>>> > On Sat, May 27, 2017 at 10:07 PM Gabor Szabo  wrote:
>>> >>
>>> >> I came up with this:
>>> >>
>>> >> say $*PROGRAM-NAME.IO.absolute.IO.dirname;
>>> >>
>>> >> but I wonder if there is a simpler way to do it?
>>> >>
>>> >> regards
>>> >> Gabor


Re: Absolute path to directory of the current perl program

2017-05-27 Thread Gabor Szabo
thanks.

$*PROGRAM.dirname.IO.absolute;

also works, but yours seem better.

As a side note, dirname does not return and IO::Path object either.

Gabor


On Sat, May 27, 2017 at 6:48 PM, Lloyd Fournier  wrote:
> I'd use
>
> $*PROGRAM.absolute.IO.dirname
>
> I'm not sure why .absolute doesn't return an IO::Path object. Maybe that's
> being addressed as part of Zoffix++'s IO work.
>
>
> On Sat, May 27, 2017 at 10:07 PM Gabor Szabo  wrote:
>>
>> I came up with this:
>>
>> say $*PROGRAM-NAME.IO.absolute.IO.dirname;
>>
>> but I wonder if there is a simpler way to do it?
>>
>> regards
>> Gabor


Re: Modulino in Perl 6

2017-05-27 Thread Gabor Szabo
A bit late, but thanks to both of you :)
Gabor

On Tue, May 2, 2017 at 6:33 PM, Gianni Ceccarelli
 wrote:
> On Tue, 2 May 2017 17:02:40 +0200
> Gabor Szabo  wrote:
>> Is there some way in Perl 6 to tell if a file was executed directly or
>> loaded into memory as a module?
>
> One way that seems to work: define a ``sub MAIN``; it will be invoked
> when you execute the file as a program, but won't be touched if you
> load it as a module.
>
> Example: in file ``/tmp/x/Foo.pm6``::
>
>   class Foo {
> has $.value;
>   }
>
>   sub MAIN($value) {
> say Foo.new(:$value).value;
>   }
>
> then::
>
>   $ perl6 -I /tmp/x -e 'use Foo;say Foo.new(:value(5)).value'
>   5
>
>   $ perl6 /tmp/x/Foo.pm6
>   Usage:
> /tmp/x/Foo.pm6 
>
>   $ perl6 /tmp/x/Foo.pm6 12
>   12
>
> --
> Dakkar - 
> GPG public key fingerprint = A071 E618 DD2C 5901 9574
>  6FE2 40EA 9883 7519 3F88
> key id = 0x75193F88
>
> Leela: You buy one pound of underwear and you're on their list forever.


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

2017-05-27 Thread Gabor Szabo
Excellent. Thanks.
 Gabor

On Fri, May 26, 2017 at 1:15 PM, Elizabeth Mattijsen  wrote:
> Fixed with https://github.com/rakudo/rakudo/commit/f2fca0c8c2 .
>
>> On 26 May 2017, at 10:47, Brent Laabs  wrote:
>>
>> 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
>>


Absolute path to directory of the current perl program

2017-05-27 Thread Gabor Szabo
I came up with this:

say $*PROGRAM-NAME.IO.absolute.IO.dirname;

but I wonder if there is a simpler way to do it?

regards
Gabor


How to upgrade a module?

2017-05-26 Thread Gabor Szabo
Hi there,

So I have been working on Bailador and pushing out changes lately.
How can I tell zef to upgrade it?

I ran

zef update
zef install --force Bailador

it installed Bailador again, but it was not the most recent code from GitHub.

I tried

zef upgrade Bailador

It told me

===> Searching for: Bailador
The following distributions are already at their latest versions: Bailador

I looked at https://modules.perl6.org/update.log and I don't see an error there.

I also search for Bailador.pm:

-rw-r--r--  1 gabor  staff  2282 Mar 25 11:46
/Users/gabor/.zef/store/Bailador.git
-rw-r--r--  1 gabor  staff  2282 Mar 25 11:46 /Users/gabor/.zef/tmp/Bailador.git
-rw-r--r--  1 gabor  staff  2788 May 26 08:33
/Users/gabor/work/Bailador/lib/Bailador.pm


What do I need to do to get zef see the most recent version in GitHub?

regards
   Gabor


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

2017-05-26 Thread Gabor Szabo
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-25 Thread Gabor Szabo
thanks!


Gabor "impatient" Szabo

On Fri, May 26, 2017 at 9:27 AM, Brent Laabs  wrote:
> 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


Are sigils required?

2017-05-25 Thread Gabor Szabo
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: Compiling Rakudo in parallel

2017-05-25 Thread Gabor Szabo
That just confuses me :(

Do I need to type

make -j 4

and hope for some concurrency?

or

export MAKEFLAGS="-j2 --load-average=2"
make

as I was pointed to off-list?

Would someone update the README that comes with Rakudo Star with this
information, please?

regards
   Gabor


On Fri, May 26, 2017 at 1:19 AM, Timo Paulssen  wrote:
> Sadly, the majority of rakudo's and nqp's compilation is serialized (due
> to the dependencies between the individual pieces).
>
> If you build more than one backend at the same time, i.e. moar + jvm,
> you can build both in parallel.
>
> On the other hand, the biggest chunk of time is spent compiling the core
> setting, which commonly takes a minute on moarvm.
>
> nqp behaves very similarly.
>
> moarvm on the other hand can compile all .c files at the same time and
> use up as many cores as there are .c files, but it compiles so fast that
> it's hardly worth anything.
>
> hope that helps
>   - Timo


Compiling Rakudo in parallel

2017-05-25 Thread Gabor Szabo
Hi,

is it possible to run any of the compilation and installation phases
of Rakudo in parallel?  (eg. so the "make" will use all the cores in
my Linux machine)

Gabor


Re: Task::Star and Panda

2017-05-25 Thread Gabor Szabo
On Thu, May 25, 2017 at 11:59 AM, Richard Hainsworth
 wrote:

> However, for someone new to the Perl6 world, there needs to be some form of
> recommendation about useful "first" modules.

Agree, but would go further:

Someone new to Perl 6 should not need to make any decision regarding
modules and should not need to install anything else for the common
tasks. What are common tasks changes with time. These days accessing
SQLite, handling JSON, YAML, INI files, and even XML falls in that
place. Even simple web application development falls in that category.

IMHO if the distribution of Perl 6 (I guess I mean Rakudo Start) does
not come with such capabilities then it won't be able to compete with
languages such as PHP or Python because of
1) Analysis paralyzes
2) Lack of knowledge how to install
3) Lack of rights (technical or legal)

Gabor
http://perl6maven.com/


Web Development using Perl 6 book - crowdfunding

2017-05-24 Thread Gabor Szabo
Hi,

I hope I am not overstepping the boundaries of the mailing list here.

A few days ago I've started a crowdfunding campaign http://perl6maven.com/book
to finance the writing of a book called "Web Development using Perl 6 book".
BTW a very early version of the book can be found here:
https://leanpub.com/bailador/

My plan is outlined on the campaign page. As I've started writing I've
already bumped into a few problems with Bailador. Issues were open on
GitHub and I am going to work on those problems as well. So in
addition to writing a book, apparently I am going to improve Bailador
as well. If all works out well, the community will end up with both a
book and a much better web framework.

There are already 35 people backing the project, but I'd like to reach
a lot more people. If possible a 1,000 people. For this I'd like to
ask you for your support. Both financially and by telling others about
the book.

So please check out the campaign at http://perl6maven.com/book
If you think having such book would do good for Perl 6 and if you
think I can write that book well, then please support the campaign. Do
it now, as more supporters will make it easier to get others to chip
in.

regards
Gabor
ps. Of course, if you have any questions, feel free to ask!
ps. If you are interested what a roller coaster of feelings is to run
a crowdfunding campaign check out my post:
https://szabgab.com/the-phases-of-a-crowdfunding-campaign-launching.html


Re: Invoking method by name found in variable

2017-05-23 Thread Gabor Szabo
On Tue, May 23, 2017 at 9:09 PM, Elizabeth Mattijsen  wrote:
>
>> On 23 May 2017, at 20:01, Gabor Szabo  wrote:
>> given an object $o and the name of a method in $method = "run"
>> how can I invoke the $o.run() ?
>>
>> Something like $o.call($method)
>
> $o.”$method"()
>
> $ 6 'my $method = "Str"; dd 42."$method"()'
> “42"
>
> Liz


Funny, first I tried $o.$method()  but that did not work.


Thanks to both of you!
Gabor


Invoking method by name found in variable

2017-05-23 Thread Gabor Szabo
Hi,

given an object $o and the name of a method in $method = "run"
how can I invoke the $o.run() ?

Something like $o.call($method)

Gabor


Modulino in Perl 6

2017-05-02 Thread Gabor Szabo
Using the caller() in Perl 5 one can figure out if the file was loaded
as a module or executed as a script.

In Python one could check if __name__ is equal to "__main__".

Is there some way in Perl 6 to tell if a file was executed directly or
loaded into memory as a module?

regards
Gabor


Smoke testing Perl 6 Modules on Rakudo

2017-04-08 Thread Gabor Szabo
I wonder if this site is really out of date as the dates at the top indicate?
http://smoke.perl6.org/report

If so, is there working version of this report?

Gabor


zef not telling what it is going to test for Uzu

2017-04-08 Thread Gabor Szabo
As I understand from installing a number of Perl 6 modules using zef,
every time before zef starts testing the module it tells the user what
it is going to test, including its version number.

eg. this:

Testing: Net::DNS:ver('1.0.1'):auth('github:retupmoca')

When I try to install Uzu, howerver I don't see this line.
I wonder if this is because Uzu us hosted on Gitlab and not on GitHub or
is something missing from the META file of Uzu or something else?

Uzu lives here: https://gitlab.com/samcns/uzu/

The reason I notice this is because of a bug in Uzu that was
(partially?) fixed, but
I still cannot install with zef: https://gitlab.com/samcns/uzu/issues/1
and I am not sure it is even trying to install the latest version or not.

regards
Gabor


Re: How to limit the list of imported functions?

2017-04-07 Thread Gabor Szabo
That's indeed a good idea for documentation purposes and with the strict
function redeclaration
prevention of Perl 6 it might be sufficient as well.

regards
   Gabor

On Sat, Apr 8, 2017 at 2:27 AM, ToddAndMargo  wrote:

> On 04/07/2017 07:21 AM, Gabor Szabo wrote:
>
>> In perl 5 we can limit which functions are imported by listing them
>> after the name of the module:
>>
>> use Module ('foo', 'bar');
>>
>> When I try the same in Rakudo I get
>>
>> "no EXPORT sub, but you provided positional argument in the 'use'
>> statement"
>>
>>
>> At least in this case:
>>
>> use WWW::Google::Time 'google-time-in';
>>
>> ===SORRY!=== Error while compiling /opt/google_time.pl
>> Error while importing from 'WWW::Google::Time':
>> no EXPORT sub, but you provided positional argument in the 'use' statement
>> at /opt/google_time.pl:2
>> --> use WWW::Google::Time 'google-time-in'⏏;
>>
>> Using Rakudo Star 2017.01
>>
>> regards
>>Gabor
>>
>>
>
> Hi Gabor,
>
> They are working on it.
>
> I like this feature too, not to minimize my code,
> but to figure out where things come from for
> maintainability.
>
> Whist we wait, this is what do, so I can figure out
> where things are coming from:
>
> use File::Which;   #  qw[ which whence ];
> use X11Clipboard;  #`{ qw[ WritePrimaryClipboard,
>WriteSecondaryClipboard,
>ReadPrimaryClipboard, ReadSecondaryClipboard ]; }
>
> HTH,
> -T
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


Re: How to limit the list of imported functions?

2017-04-07 Thread Gabor Szabo
thanks!

On Fri, Apr 7, 2017 at 6:04 PM, Elizabeth Mattijsen  wrote:
> https://docs.perl6.org/syntax/need
>
>> On 7 Apr 2017, at 16:59, Gabor Szabo  wrote:
>>
>> Thanks. I was only looking at https://docs.perl6.org/syntax/use
>>
>> Looking at that doc you linked to, I have a related quest I could not see:
>>
>> Is there a way to tell Rakudo to not to import any function from the module?
>>
>> Gabor
>>
>>
>> On Fri, Apr 7, 2017 at 5:37 PM, Will Coleda  wrote:
>>> Please check the docs at
>>> https://docs.perl6.org/language/modules#Exporting_and_Selective_Importing
>>>
>>> On Fri, Apr 7, 2017 at 10:21 AM, Gabor Szabo  wrote:
>>>> In perl 5 we can limit which functions are imported by listing them
>>>> after the name of the module:
>>>>
>>>> use Module ('foo', 'bar');
>>>>
>>>> When I try the same in Rakudo I get
>>>>
>>>> "no EXPORT sub, but you provided positional argument in the 'use' 
>>>> statement"
>>>>
>>>>
>>>> At least in this case:
>>>>
>>>> use WWW::Google::Time 'google-time-in';
>>>>
>>>> ===SORRY!=== Error while compiling /opt/google_time.pl
>>>> Error while importing from 'WWW::Google::Time':
>>>> no EXPORT sub, but you provided positional argument in the 'use' statement
>>>> at /opt/google_time.pl:2
>>>> --> use WWW::Google::Time 'google-time-in'⏏;
>>>>
>>>> Using Rakudo Star 2017.01
>>>>
>>>> regards
>>>>   Gabor
>>>
>>>
>>>
>>> --
>>> Will "Coke" Coleda


Re: How to limit the list of imported functions?

2017-04-07 Thread Gabor Szabo
Thanks. I was only looking at https://docs.perl6.org/syntax/use

Looking at that doc you linked to, I have a related quest I could not see:

Is there a way to tell Rakudo to not to import any function from the module?

Gabor


On Fri, Apr 7, 2017 at 5:37 PM, Will Coleda  wrote:
> Please check the docs at
> https://docs.perl6.org/language/modules#Exporting_and_Selective_Importing
>
> On Fri, Apr 7, 2017 at 10:21 AM, Gabor Szabo  wrote:
>> In perl 5 we can limit which functions are imported by listing them
>> after the name of the module:
>>
>> use Module ('foo', 'bar');
>>
>> When I try the same in Rakudo I get
>>
>> "no EXPORT sub, but you provided positional argument in the 'use' statement"
>>
>>
>> At least in this case:
>>
>> use WWW::Google::Time 'google-time-in';
>>
>> ===SORRY!=== Error while compiling /opt/google_time.pl
>> Error while importing from 'WWW::Google::Time':
>> no EXPORT sub, but you provided positional argument in the 'use' statement
>> at /opt/google_time.pl:2
>> --> use WWW::Google::Time 'google-time-in'⏏;
>>
>> Using Rakudo Star 2017.01
>>
>> regards
>>Gabor
>
>
>
> --
> Will "Coke" Coleda


How to limit the list of imported functions?

2017-04-07 Thread Gabor Szabo
In perl 5 we can limit which functions are imported by listing them
after the name of the module:

use Module ('foo', 'bar');

When I try the same in Rakudo I get

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


At least in this case:

use WWW::Google::Time 'google-time-in';

===SORRY!=== Error while compiling /opt/google_time.pl
Error while importing from 'WWW::Google::Time':
no EXPORT sub, but you provided positional argument in the 'use' statement
at /opt/google_time.pl:2
--> use WWW::Google::Time 'google-time-in'⏏;

Using Rakudo Star 2017.01

regards
   Gabor


write string requires an object with REPR MVMOSHandle

2017-03-29 Thread Gabor Szabo
I was running the following buggy code:

sub save {
my $fh = open('data.txt', :w);
LEAVE: $fh.close;
$fh.print("hello\n");
}

save();

(note the : after the LEAVE)
Which if I am not mistaken is basically the same as:


sub save {
my $fh = open('data.txt', :w);
$fh.close;
$fh.print("hello\n");
}

save();


and I kept getting the error in the subject which greatly confused me.

Shouldn't this be something like a "print of closed filehandle" error?

Gabor


Re: Bug report for Crypt::Bcrypt - cannot install

2017-03-28 Thread Gabor Szabo
Oh I see now.


On Tue, Mar 28, 2017 at 10:17 PM, Will Coleda  wrote:
> Not directly, but: Crypt::Bcrypt's build depends on Crypt::Random -
>
> https://github.com/skinkade/p6-Crypt-Bcrypt/blob/master/META.info#L8
>
> And Crypt::Random depends on if -
>
> https://github.com/skinkade/crypt-random/blob/master/META.info#L13
>
>
>
> On Tue, Mar 28, 2017 at 2:50 PM, Gabor Szabo  wrote:
>> Thanks for the quick reply.
>>
>> That looks like a similar issue, but as I can see Crypt::Bcrypt does
>> not depend on 'if'.
>> It has this bug on its own :)
>>
>> Gabor
>>
>>
>> On Tue, Mar 28, 2017 at 9:45 PM, Will Coleda  wrote:
>>> Looks like you already found the dependency that is failing:
>>> https://github.com/FROGGS/p6-if/issues/2
>>>
>>> The original module doesn't have a bug queue, and I don't think we
>>> have a community solution to authors that don't have bugqueues.
>>> (except to kindly ask them to enable them)
>>>
>>>
>>>
>>> On Tue, Mar 28, 2017 at 2:33 PM, Gabor Szabo  wrote:
>>>> I've just tried to install Crypt::Bcrypt into my Docker based Rakudo
>>>> but it failed.
>>>> I checked the GitHub repo of the project
>>>> https://github.com/skinkade/p6-Crypt-Bcrypt
>>>> that was linked from modules.perl6.org but it could not find the way
>>>> to submit bug reports.
>>>>
>>>> Where should I report it?
>>>>
>>>>
>>>> # perl6 -v
>>>> This is Rakudo version 2017.01 built on MoarVM version 2017.01
>>>> implementing Perl 6.c.
>>>>
>>>>
>>>> # zef install Crypt::Bcrypt
>>>> ===> Searching for: Crypt::Bcrypt
>>>> ===> Searching for missing dependencies: Crypt::Random
>>>> ===> Searching for missing dependencies: if
>>>> ===> Fetching: Crypt::Bcrypt
>>>> ===> Fetching: Crypt::Random
>>>> ===> Fetching: if
>>>> ===> Building: Crypt::Bcrypt:ver('1.3.1')
>>>> ===> Building [OK] for Crypt::Bcrypt:ver('1.3.1')
>>>> ===> Testing: if:ver('0.1.0'):auth('github:FROGGS')
>>>> t/if.t ..1/5===SORRY!===
>>>> Cannot find method 'symtable' on object of type GLOBAL
>>>> # Looks like you planned 5 tests, but ran 1
>>>> t/if.t .. All 5 subtests passed
>>>> All tests successful.
>>>>
>>>> Test Summary Report
>>>> ---
>>>> t/if.t (Wstat: 0 Tests: 1 Failed: 0)
>>>>   Parse errors: Bad plan.  You planned 5 tests but ran 1.
>>>> Files=1, Tests=1,  1 wallclock secs
>>>> Result: FAILED
>>>> ===> Testing [FAIL]: if:ver('0.1.0'):auth('github:FROGGS')
>>>> Aborting due to test failure: if:ver('0.1.0'):auth('github:FROGGS')
>>>> (use --force to override)
>>>>   in code  at 
>>>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>>>> (Zef::Client) line 306
>>>>   in method test at
>>>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>>>> (Zef::Client) line 285
>>>>   in code  at 
>>>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>>>> (Zef::Client) line 457
>>>>   in sub  at 
>>>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>>>> (Zef::Client) line 454
>>>>   in method install at
>>>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>>>> (Zef::Client) line 560
>>>>   in sub MAIN at
>>>> /usr/share/perl6/site/sources/A9948E7371E0EB9AFDF1EEEB07B52A1B75537C31
>>>> (Zef::CLI) line 123
>>>>   in block  at
>>>> /usr/share/perl6/site/resources/3DD33EF601FD300095284AE7C24B770BAADAF32E
>>>> line 1
>>>
>>>
>>>
>>> --
>>> Will "Coke" Coleda
>
>
>
> --
> Will "Coke" Coleda


Re: Bug report for Crypt::Bcrypt - cannot install

2017-03-28 Thread Gabor Szabo
Thanks for the quick reply.

That looks like a similar issue, but as I can see Crypt::Bcrypt does
not depend on 'if'.
It has this bug on its own :)

Gabor


On Tue, Mar 28, 2017 at 9:45 PM, Will Coleda  wrote:
> Looks like you already found the dependency that is failing:
> https://github.com/FROGGS/p6-if/issues/2
>
> The original module doesn't have a bug queue, and I don't think we
> have a community solution to authors that don't have bugqueues.
> (except to kindly ask them to enable them)
>
>
>
> On Tue, Mar 28, 2017 at 2:33 PM, Gabor Szabo  wrote:
>> I've just tried to install Crypt::Bcrypt into my Docker based Rakudo
>> but it failed.
>> I checked the GitHub repo of the project
>> https://github.com/skinkade/p6-Crypt-Bcrypt
>> that was linked from modules.perl6.org but it could not find the way
>> to submit bug reports.
>>
>> Where should I report it?
>>
>>
>> # perl6 -v
>> This is Rakudo version 2017.01 built on MoarVM version 2017.01
>> implementing Perl 6.c.
>>
>>
>> # zef install Crypt::Bcrypt
>> ===> Searching for: Crypt::Bcrypt
>> ===> Searching for missing dependencies: Crypt::Random
>> ===> Searching for missing dependencies: if
>> ===> Fetching: Crypt::Bcrypt
>> ===> Fetching: Crypt::Random
>> ===> Fetching: if
>> ===> Building: Crypt::Bcrypt:ver('1.3.1')
>> ===> Building [OK] for Crypt::Bcrypt:ver('1.3.1')
>> ===> Testing: if:ver('0.1.0'):auth('github:FROGGS')
>> t/if.t ..1/5===SORRY!===
>> Cannot find method 'symtable' on object of type GLOBAL
>> # Looks like you planned 5 tests, but ran 1
>> t/if.t .. All 5 subtests passed
>> All tests successful.
>>
>> Test Summary Report
>> ---
>> t/if.t (Wstat: 0 Tests: 1 Failed: 0)
>>   Parse errors: Bad plan.  You planned 5 tests but ran 1.
>> Files=1, Tests=1,  1 wallclock secs
>> Result: FAILED
>> ===> Testing [FAIL]: if:ver('0.1.0'):auth('github:FROGGS')
>> Aborting due to test failure: if:ver('0.1.0'):auth('github:FROGGS')
>> (use --force to override)
>>   in code  at 
>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>> (Zef::Client) line 306
>>   in method test at
>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>> (Zef::Client) line 285
>>   in code  at 
>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>> (Zef::Client) line 457
>>   in sub  at 
>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>> (Zef::Client) line 454
>>   in method install at
>> /usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
>> (Zef::Client) line 560
>>   in sub MAIN at
>> /usr/share/perl6/site/sources/A9948E7371E0EB9AFDF1EEEB07B52A1B75537C31
>> (Zef::CLI) line 123
>>   in block  at
>> /usr/share/perl6/site/resources/3DD33EF601FD300095284AE7C24B770BAADAF32E
>> line 1
>
>
>
> --
> Will "Coke" Coleda


Bug report for Crypt::Bcrypt - cannot install

2017-03-28 Thread Gabor Szabo
I've just tried to install Crypt::Bcrypt into my Docker based Rakudo
but it failed.
I checked the GitHub repo of the project
https://github.com/skinkade/p6-Crypt-Bcrypt
that was linked from modules.perl6.org but it could not find the way
to submit bug reports.

Where should I report it?


# perl6 -v
This is Rakudo version 2017.01 built on MoarVM version 2017.01
implementing Perl 6.c.


# zef install Crypt::Bcrypt
===> Searching for: Crypt::Bcrypt
===> Searching for missing dependencies: Crypt::Random
===> Searching for missing dependencies: if
===> Fetching: Crypt::Bcrypt
===> Fetching: Crypt::Random
===> Fetching: if
===> Building: Crypt::Bcrypt:ver('1.3.1')
===> Building [OK] for Crypt::Bcrypt:ver('1.3.1')
===> Testing: if:ver('0.1.0'):auth('github:FROGGS')
t/if.t ..1/5===SORRY!===
Cannot find method 'symtable' on object of type GLOBAL
# Looks like you planned 5 tests, but ran 1
t/if.t .. All 5 subtests passed
All tests successful.

Test Summary Report
---
t/if.t (Wstat: 0 Tests: 1 Failed: 0)
  Parse errors: Bad plan.  You planned 5 tests but ran 1.
Files=1, Tests=1,  1 wallclock secs
Result: FAILED
===> Testing [FAIL]: if:ver('0.1.0'):auth('github:FROGGS')
Aborting due to test failure: if:ver('0.1.0'):auth('github:FROGGS')
(use --force to override)
  in code  at 
/usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
(Zef::Client) line 306
  in method test at
/usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
(Zef::Client) line 285
  in code  at 
/usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
(Zef::Client) line 457
  in sub  at 
/usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
(Zef::Client) line 454
  in method install at
/usr/share/perl6/site/sources/1DC0BAA246D0774E7EB4F5119C6168E0D8266EFA
(Zef::Client) line 560
  in sub MAIN at
/usr/share/perl6/site/sources/A9948E7371E0EB9AFDF1EEEB07B52A1B75537C31
(Zef::CLI) line 123
  in block  at
/usr/share/perl6/site/resources/3DD33EF601FD300095284AE7C24B770BAADAF32E
line 1


Re: exit code: 141 causes Perl 6 to exit.

2017-03-27 Thread Gabor Szabo
Putting

CATCH { default { put .^name, ': ', .Str } };

in the While loop helped with the restarting, but I am still not sure if this
is the expected behavior or not.


run.pl:

while True {
 say "Starting";
 shell("perl6 a.pl");
   CATCH { default { put .^name, ': ', .Str } };
}


a.pl:

print "in a.pl\n";
exit(141);


exit code: 141 causes Perl 6 to exit.

2017-03-27 Thread Gabor Szabo
The lack of open filehandles seem to be fixed. The server now stays up
for quite long time, but I've just seen the following on the command
line:


The spawned command './RUN' exited unsuccessfully (exit code: 141)
  in block  at wrap.pl6 line 5


I'd like to understand what this exit code: 141 might be, but also I
am surprised
this stopped the server.

After all I use this code to launch it:

https://github.com/szabgab/Perl6-Maven/blob/main/wrap.pl6

and run "perl6 wrap.pl6"

This should relaunch the server when it crashes, but it did not do it.
The wrapper itself excited.

Any idea what could be the source of exit code 141?
How to run the external script so even if it exits my main code does not exit.

(BTW using "run" instead of "shell" did not help either.)


Gabor
ps. The following two scripts can reproduce the issue with "shell":

run.pl:

while True {
say "Starting";
shell("perl6 a.pl");
say "Ending";
}


a.pl:

print "in a.pl\n";
exit(141);


$ perl6 run.pl
Starting
The spawned command 'perl6 a.pl' exited unsuccessfully (exit code: -1)
  in block  at run.pl line 3

$


Travis-CI and Rakudo seem to be a bit unstable

2017-03-25 Thread Gabor Szabo
Hi,

In addition to me breaking my own code, it seems that Travis-CI and
Rakudo are rather fragile together.

Occasionally my tests fail due to failures in the prerequisites.

This failed due to LWP::Simple failing
https://travis-ci.org/szabgab/Perl6-Maven/jobs/215147392
even though 20 min earlier it worked:
https://travis-ci.org/szabgab/Perl6-Maven/builds/215143736

Yesterday Bailador failed:
https://travis-ci.org/szabgab/Perl6-Maven/jobs/214981400
even though it worked a few minutes earlier and a few minutes later.

As far as I can tell neither LWP::Simple nor Bailador changed during that time.

Have you encountered similar issues?  Am I misreading something?


regards
   Gabor


Re: Failed to open file .. too many open files

2017-03-25 Thread Gabor Szabo
I still get the same error.
I just found another case of slurp-rest which might have been the
cause but it might be good time to
look at the few other cases of "open" in my code. (And later maybe
also the code of Bailador itself.)
I tried to read more about how I am supposed to close file handles in
Perl 6, but the explanation I found didn't help me.
I opened this ticket https://github.com/perl6/doc/issues/1258 asking
for further clarification.

Anyway here is another code snippet from my code:

for open("$.source_dir/authors.txt").lines -> $line {
 ...
}

Do I need to close this myself? Can I rely on Perl closing it?

If I open a file for reading like this:

sub f {
my $fh = open $file, :r;
LEAVE $fh.close;

for $fh.lines -> $line {
}
}

Is that the correct way to put the LEAVE in? Should it be immediately
after the open statement?

And for writing?

sub write {
my $fh = open $file, :w;
LEAVE $fh.close;
$fh.print("text");
}

regards
Gabor


Re: Failed to open file .. too many open files

2017-03-25 Thread Gabor Szabo
On Sat, Mar 25, 2017 at 8:42 PM, Elizabeth Mattijsen  wrote:
> $file.IO.slurp and slurp($file) are basically the same.
>
> $handle.slurp-rest does *not* close the handle, as another process might 
> still be writing to it, so you could do another .slurp-rest.
>
>
> To get back to your original code:
>
>get '/atom' => sub {
>my $path = $.meta ~ request.path;
>return open($path).slurp-rest;
>}
>
> I would write that as:
>
>get '/atom' => sub { slurp $.meta ~ request.path }
>
> Should you wind up with an opened handle, could could use a LEAVE phaser to 
> make sure the handle gets closed:
>
>get '/atom' => sub {
>LEAVE $.meta.handle.close;
>return $.meta.handle.slurp-rest;
>}
>

Thanks.

I've converted all those slurp-rest calls so slurp calls.
I am not sure why did I have the slurp-rest in there.
That code seems to be at least 2 years old.

Anyway, thanks for the explanation.

Gabor


Re: Failed to open file .. too many open files

2017-03-25 Thread Gabor Szabo
Oh so you say that's indeed a bug in my code. That's a relief. Thanks!


As I can see I had some $file.IO.slurp and some of the slurp-rest ones.

What is the difference between $file.IO.slurp and slurp($file) ?
Is the latter just an alias for the former?

Gabor


On Sat, Mar 25, 2017 at 4:54 PM, Timo Paulssen  wrote:
> i highly suggest you slurp instead of open + slurp-rest, because that
> will automatically close the file for you, too.
>
> other than that, you can pass :close to the slurp-rest method and it'll
> also close the file.
>
> if you're not closing the files you're opening, you'll be relying on the
> garbage collector to do file handle closing for you, which is
> nondeterministic and a bad idea in general.
>
> HTH
>   - Timo


Re: Perl 6 docs

2017-03-25 Thread Gabor Szabo
https://github.com/perl6/doc/issues/1257


Failed to open file .. too many open files

2017-03-25 Thread Gabor Szabo
The Perl 6 Maven site runs on Bailador. I've just updated the Rakudo
underneath to 2017.01 and
it seemed to be working fine, but after a while it started crashing
with this error message:



Failed to open file /home/gabor/work/perl6maven-live.com/main.json:
too many open files
  in sub  at /home/gabor/work/Perl6-Maven/lib/Perl6/Maven.pm6
(Perl6::Maven) line 26
  in block  at 
/home/gabor/rakudo-star-2017.01/install/share/perl6/site/sources/A80D3EE41ED647143B6A367AAE142A5967A850D7
(Bailador::Route) line 57
  in method recurse-on-routes at
/home/gabor/rakudo-star-2017.01/install/share/perl6/site/sources/A80D3EE41ED647143B6A367AAE142A5967A850D7
(Bailador::Route) line 56
  in method dispatch at
/home/gabor/rakudo-star-2017.01/install/share/perl6/site/sources/06F75D046213CAD92B84F66E5F161C084878D0C3
(Bailador::App) line 84
  in block  at 
/home/gabor/rakudo-star-2017.01/install/share/perl6/site/sources/06F75D046213CAD92B84F66E5F161C084878D0C3
(Bailador::App) line 77

I've tried to reproduce the problem by running curl against the local
version of the application,
but so far, after a few hundred requests, I have not encountered the problem.


line 26 in the Maven.pm6 file looks like this:

get '/atom' => sub {
my $path = $.meta ~ request.path;
return open($path).slurp-rest;
}

I wonder if you have any idea what could be the source of this problem?

The full source of the application is here:
https://github.com/szabgab/Perl6-Maven/

regards
Gabor


Perl 6 docs

2017-03-25 Thread Gabor Szabo
When I search for %INC at https://docs.perl6.org/ it offers   "%INC (Perl 5)"
but when I search for the more common @INC

Luckily the former leads to
https://docs.perl6.org/language/5to6-perlvar which also has
information on the latter, but it would be nice if that was also
recognized in the search box.

Gabor


Using Rakudo Start on OSX using the .dmg

2017-03-25 Thread Gabor Szabo
Hi,

I just tried to use the .dmg version of Rakudo Star.
I might not be the typical Mac user as I spent quite some time trying to figure
out what do I need to do in order to start using it after the installation.

In the end I found that it was installed to  /Applications/Rakudo

Then I added these to my .bash_profile:

export RAKUDO=/Applications/Rakudo
export PATH=$RAKUDO/bin:$RAKUDO/share/perl6/site/bin/:$PATH
export PERL6LIB=$RAKUDO/share/perl6/site/lib/

reloaded it and then I could use it.

Maybe some notes like this could be added to
http://rakudo.org/how-to-get-rakudo/

regards
   Gabor


Forking or running external process in background

2015-10-24 Thread Gabor Szabo
I am trying to test the Perl6::Maven web application by launching the full
application (which is uses Bailador) and then accessing the pages using
LWP::Simple.


Unfortunately so far I could not figure out how to launch an external
program in the background
or how to fork an exec ?

I tried QX{"command &") but it waited till the command finished.
I tried run(), but that insisted I pass each argument as a separate value

my $p = run("/usr/bin/perl", "-V", :out);

worked but

my $p = run("/usr/bin/perl -V", :out);

did not seem to work and I cannot pass & to the former.

Gabor


How to profile Perl 6 applications?

2015-10-24 Thread Gabor Szabo
Hi,

The Devel::NYTProf helped me a lot locating the source of slowness on the
Perl Maven site.
Is there something similar for Perl 6 so I can try to improve the speed of
the Perl 6 Maven site too?

Gabor


Re: require on string stopped working in rakudo 2015.09

2015-09-26 Thread Gabor Szabo
On Sat, Sep 26, 2015 at 3:39 PM, Moritz Lenz  wrote:

>
> >> I've fixed my script by switching to EVAL "use $module";
> >> but I wonder if this is a regression or a planned deprecation?
> >
> > I’m not sure yet.
> >
> > Could you please rakudobug it so that it doesn’t fall through the
> cracks?  This change did not fire any spectest alarm either, so maybe we
> need a test for it as well  :-)
>
> I've opened https://rt.perl.org/Ticket/Display.html?id=126096 and later
> rejcted it when learning about the desired behavior.
>
>

Thanks for all the replies. I stick with EVAL for now.

BTW  http://doc.perl6.org/ does not know about 'require' at all.   (nor
seems to know about 'use'). nor EVAL.

Gabor


Re: Method 'send' not found for invocant of class 'IO::Socket::INET'

2015-09-26 Thread Gabor Szabo
Tobias thanks!

I ran panda install HTTP::Easy
and it installed the new version in
/Users/gabor/rakudo-star-2015.09/install/share/perl6/site/lib/HTTP/Easy.pm6

but Rakudo is still loading the old one from

/Users/gabor/rakudo-star-2015.09/install/share/perl6/lib/HTTP/Easy.pm6

and crashing.

I can run

perl6 -I /Users/gabor/rakudo-star-2015.09/install/share/perl6/site/lib/
examples/app.pl

and then it works, but is there something else I should have done to make
rakudo look
for the site module before the one in the old place or to let panda install
over the top of
the old version? Oh and there is also a  .moarvm version of the file.

regards
  Gabor


On Sat, Sep 26, 2015 at 3:37 PM, Tobias Leich  wrote:

> You need to upgrade HTTP::Easy, it already contains a fix.
>
>
> Am 26.09.2015 um 12:26 schrieb Gabor Szabo:
>
> And just to clarify launching this simple script (and then accessing it
> via a browser) would show the same problem:
>
> use lib 'lib';
>
> use Bailador;
>
> get '/' => sub {
> "hello world"
> }
>
> baile;
>
>
> On Sat, Sep 26, 2015 at 1:16 PM, Gabor Szabo  wrote:
>
>> In the cloned repository of Bailador I ran
>>
>> perl6 examples/app.pl
>>
>> It launched the web server printing
>>
>> Entering the development dance floor: <http://0.0.0.0:3000>
>> http://0.0.0.0:3000
>> [2015-09-26T10:04:46Z] Started HTTP server.
>>
>> but when I tried to access it with a browser it crashed with:
>>
>> [2015-09-26T10:04:49Z] GET / HTTP/1.1
>> Method 'send' not found for invocant of class 'IO::Socket::INET'
>>   in method run at
>> /Users/gabor/rakudo-star-2015.09/install/share/perl6/lib/HTTP/Easy.pm6:193
>>   in sub baile at /Users/gabor/work/Bailador/lib/Bailador.pm:153
>>   in block  at examples/app.pl:38
>>
>>
>> Any idea what's this and how to fix it?
>>
>> Oh and I found the INET module here:
>> /Users/gabor/rakudo-star-2015.09//rakudo/src/core/IO/Socket/INET.pm
>> it does not even seem to be "installed".
>>
>>
>> regards
>> Gabor
>>
>>
>
>


Re: Method 'send' not found for invocant of class 'IO::Socket::INET'

2015-09-26 Thread Gabor Szabo
And just to clarify launching this simple script (and then accessing it via
a browser) would show the same problem:

use lib 'lib';

use Bailador;

get '/' => sub {
"hello world"
}

baile;


On Sat, Sep 26, 2015 at 1:16 PM, Gabor Szabo  wrote:

> In the cloned repository of Bailador I ran
>
> perl6 examples/app.pl
>
> It launched the web server printing
>
> Entering the development dance floor: http://0.0.0.0:3000
> [2015-09-26T10:04:46Z] Started HTTP server.
>
> but when I tried to access it with a browser it crashed with:
>
> [2015-09-26T10:04:49Z] GET / HTTP/1.1
> Method 'send' not found for invocant of class 'IO::Socket::INET'
>   in method run at
> /Users/gabor/rakudo-star-2015.09/install/share/perl6/lib/HTTP/Easy.pm6:193
>   in sub baile at /Users/gabor/work/Bailador/lib/Bailador.pm:153
>   in block  at examples/app.pl:38
>
>
> Any idea what's this and how to fix it?
>
> Oh and I found the INET module here:
> /Users/gabor/rakudo-star-2015.09//rakudo/src/core/IO/Socket/INET.pm
> it does not even seem to be "installed".
>
>
> regards
> Gabor
>
>


Method 'send' not found for invocant of class 'IO::Socket::INET'

2015-09-26 Thread Gabor Szabo
In the cloned repository of Bailador I ran

perl6 examples/app.pl

It launched the web server printing

Entering the development dance floor: http://0.0.0.0:3000
[2015-09-26T10:04:46Z] Started HTTP server.

but when I tried to access it with a browser it crashed with:

[2015-09-26T10:04:49Z] GET / HTTP/1.1
Method 'send' not found for invocant of class 'IO::Socket::INET'
  in method run at
/Users/gabor/rakudo-star-2015.09/install/share/perl6/lib/HTTP/Easy.pm6:193
  in sub baile at /Users/gabor/work/Bailador/lib/Bailador.pm:153
  in block  at examples/app.pl:38


Any idea what's this and how to fix it?

Oh and I found the INET module here:
/Users/gabor/rakudo-star-2015.09//rakudo/src/core/IO/Socket/INET.pm
it does not even seem to be "installed".


regards
Gabor


Re: How to push a hash on an array without flattening it to Pairs?

2015-09-26 Thread Gabor Szabo
On Sat, Sep 26, 2015 at 10:37 AM, Moritz Lenz  wrote:

> Hi,
>
> This works:
> my @b; @b.push: $%h;
> say @b.perl;# [{:a(1), :b(2)},]
>
> Cheers,
> Moritz
>


Thanks. it worked.

I kept throwing various sigils, bracket, and commas around in hope of
getting this work without
any success and without actually understanding what I am doing.

:-(

Gabor


How to push a hash on an array without flattening it to Pairs?

2015-09-25 Thread Gabor Szabo
In the first two cases the hash was converted to Pairs before assigning to
the array.
Only the third case gave what I hoped for. How can I push a hash onto an
array as a single entity?


use v6;

my %h = x => 6, y => 7;
say %h.perl; #  {:x(6), :y(7)}

my @a = %h;
say @a.elems;   #
say @a[0]; # x => 6



my @c;
@c.push(%h);
say @c.elems; # 2
say @c[0];   # x => 6


my @b;
@b[@b.elems] = %h;
say @b.elems;  # 1
say @b[0];# x => 6, y => 7


Should the use of eval recommend EVAL?

2015-09-25 Thread Gabor Szabo
Hi,

I just tried to use

eval "say 19+23";


but I got:


===SORRY!=== Error while compiling a.pl
Undeclared routine:
eval used at line 3. Did you mean 'val'?


Would it be possible to recommend 'EVAL' as well ?


Gabor


require on string stopped working in rakudo 2015.09

2015-09-25 Thread Gabor Szabo
Hi,

I am really glad Rakudo finally came out.
I've installed in and tried to run the tests of Perl6::Maven.

They quickly failed as I have been using 'require' on string
to check if all the module compile properly.

The following code now fails:

use v6;
my $name = 'Bailador';
require $name;


even though

require Bailador;

works.

In 2015.07 both worked.


I've fixed my script by switching to EVAL "use $module";
but I wonder if this is a regression or a planned deprecation?

Gabor


Re: Is < > creating and Array or Parcel ?

2015-08-03 Thread Gabor Szabo
On Mon, Aug 3, 2015 at 3:49 AM, Larry Wall  wrote:

> On Sun, Aug 02, 2015 at 03:09:07PM +0200, Moritz Lenz wrote:
> : If you want to extract it from the scalar, use the @ again, this
> : time as a prefix:
> :
> : for @$s { } # two iterations again.
>
> Note that this distinction will go away after the Great List Refactor,
> so Gabor gets his wish.  Part of the GLR is to remove most of the
> itemization/listification uses of Scalar, since we're also getting rid
> of most of the auto-flattening contexts that itemization was designed
> to protect against.  This is last major semantic simplification we're
> doing before releasing Perl 6 later this year.
>
> Larry
>


So I guess I'll better wait till after GLR to try to understand it.

Thanks
Gabor


Re: Is < > creating and Array or Parcel ?

2015-08-02 Thread Gabor Szabo
This whole thing sounds quite complex. What is the value behind this
complexity?

Gabor


Re: Is < > creating and Array or Parcel ?

2015-08-01 Thread Gabor Szabo
On Fri, Jul 31, 2015 at 4:16 PM, Moritz Lenz  wrote:

>
>
> On 07/31/2015 03:02 PM, Gabor Szabo wrote:
>
>> The following code (with comments) is confusing me.
>> Can someone give some explanation please?
>> Specifically the difference between
>>
>> my @x = ;
>>
>
> It's the assignment to the Array variable that makes the Array here; < >
> by itself just creates a Parcel:
>
> $ ./perl6-m -e 'say .^name'
> Parcel
> $ ./perl6-m -e 'say (my @ =  ).^name'
> Array
>
> # we can assign that array to a scalar variable and it is still and array
>> my $y = @x;
>>
>
> that's because assignment to $ isn't coercive in the same way as
> assignment to @ or %.
>
> It just wraps things into a Scalar, which is normally invisible.
>
> But, you can observe the difference still>
>
> my @a = ;
> my $s = @a'
>
> for @a { } # two iterations
> for $s { } # one iteration
>
>
Thanks though this just shows I still don't get the whole sigil and Array
thing in Perl 6.
I thought you can put an array in a $ -ish variable and that will still be
a real array, but
now I see it is not an array.


use v6;

my $z = ['a', 'b', 'c'];
say $z.^name; # Array
for $z {
say $^a;  # a b c  (single iteration)
}
say $z.elems; # 3

# assigning it to a @-thing does not convert it to a real array either:
my @a = $z;
say @a.^name;  # Array
for @a {
say $^a; # a b c (single iteration)
}
say @a.elems; # 1

# and even
say @a[0].^name; # Array
for @a[0] {
say $^a; # a b c (single iteration)
}
say @a[0].elems; # 3

# explicitly converting a fake(?) Array to an Array works...
my @x = $z.Array;
say @x.^name;   # Array
for @x {
say $^a;  # (3 itterations)
}
say @x.elems; # 3


Probably it has another name and you don't call it "fake" array, do you?

Gabor


Is < > creating and Array or Parcel ?

2015-07-31 Thread Gabor Szabo
The following code (with comments) is confusing me.
Can someone give some explanation please?
Specifically the difference between

my @x = ;
my $z = @x;

and

my $z = ;

Gabor


use v6;

# < > creates an array here:
my @x = ;
say @x.WHICH;  # Array|140713422866208
say @x;# a b
say @x[0]; # a
@x.push('c');
say @x;# a b c

# we can assign that array to a scalar variable and it is still and array
my $y = @x;
say $y.WHICH; # Array|140498399577376
say $y[0];# a
$y.push('d');
say $y;   # a b c d


# but if we assign the same < > construct directly to a scalar
# then we get a Parcel
my $z = ;
say $z.WHICH; # Parcel|(Str|a)(Str|b)
# $z.push('c');   # Cannot call push(Parcel: Str); none of these signatures
match: (Any:U \SELF: *@values, *%_)

# but if we wrap it in square brackets it creates an array
my $w = [];
say $w.WHICH;# Array|140272330353168
say $w[0];   # a
$w.push('c');
say $w;  # a b c


Semicolon form of 'class' without 'unit' seen at ...

2015-07-30 Thread Gabor Szabo
I got a lot of the above warning on my code-base, which then goes on and
suggests:

Please use 'unit class' instead

Using unit class indeed silences Rakudo, but I could not find any
information on 'unit'
at http://doc.perl6.org/ and the http://doc.perl6.org/language/classtut
shows class definition
with curly braces.

It would be nice if someone could add some explanation about unit, or point
us to existing explanation if there is some.

regards
  Gabor


Re: Are there any web applications written in Perl 6?

2015-07-19 Thread Gabor Szabo
On Sat, Jul 18, 2015 at 11:49 PM, Rob Hoelz  wrote:

> Hi Gabor,
>
> I believe that http://testers.p6c.org/ is written in Perl 6
> (https://github.com/perl6/cpandatesters.perl6.org)
>
> Are you going to put your talk online?  I'm sure a bunch of Perl 6ers
> (myself included) would be happy to see it!
>
> -Rob
>

I am not sure if there is going to be video recording during YAPC::EU,
but I plan to blog while I prepare the talk and I might even record it
myself.


Blogs starting now: http://perl6maven.com/web-development-using-perl6

Gabor


Are there any web applications written in Perl 6?

2015-07-18 Thread Gabor Szabo
Hi,

I am going to give a 20 min talk about web application development using
Perl 6.
My base plan is to use Bailador https://github.com/tadzik/Bailador and show
the basics,
but I'd like to point out any already existing web application written in
Perl 6.
Web applications that can currently run.

So I wonder are there any web application written in Perl 6 you know about.
I'd appreciate a link to the site if its live and the source code if it is
available.

regards
Gabor


Re: time and now showing different time?

2015-01-12 Thread Gabor Szabo
On Mon, Jan 12, 2015 at 11:48 AM, Tobias Leich  wrote:

>
> $ perl6 -e 'sleep 3; say now - BEGIN now;'
> 3.0180351
>
>

Oh, so this what they call bending time around space. (Or was that the
other way around?)
You call now in the BEGIN block which is the first thing to finish in that
code, but it is placed
later in the script so it will appear only after the sleep and the second
now (written as first now)
will have been executed.

It's clear.

:)

Gabor


Re: time and now showing different time?

2015-01-12 Thread Gabor Szabo
On Mon, Jan 12, 2015 at 10:35 AM, Tobias Leich  wrote:

>  Also interesting might be the fact that BEGIN statements/blocks do return
> a value:
>
> say now() - BEGIN now; # parens needed to there so that it does not gobble 
> args
>
>
Hmm, actually it does not let me put the parens there:
$ perl6 -e 'say now() - BEGIN now;'

===SORRY!=== Error while compiling -e
Undeclared routine:
now used at line 1

This works:

$ perl6 -e 'say now - BEGIN now;'
0.0467931

but I am not sure why is that interesting. Could you elaborate please?



>>  One of them counts leap seconds, the other doesn't. Instant is supposed
>> to be a monotonic clock, the other isn't.
>>
>>
Oh and Timo,  I think, if I understand this correctly, they are both
monotonic in the mathematical sense.
Neither can decreases, can day?
The difference is that 'time' stops here-and-there and waits for a leap
second to pass before it resumes increasing.

Gabor


Re: time and now showing different time?

2015-01-11 Thread Gabor Szabo
Neat. Based on that I tried to explain it here:
http://perl6maven.com/tutorial/timestamp
Gabor

On Sat, Jan 10, 2015 at 4:13 PM,  wrote:

>
> On 01/10/2015 03:12 PM, Gabor Szabo wrote:
> > > say time; say now; say time; say now;
> >
> > 1420898839
> > Instant:1420898874.659941
> > 1420898839
> > Instant:1420898874.663946
> >
> > This looks really strange to me.
> > Why do the calls to 'now' show different full seconds than the calls
> > to 'time' ?
> >
> > Gabor
> >
>
> One of them counts leap seconds, the other doesn't. Instant is supposed
> to be a monotonic clock, the other isn't.
>
> regards
>   - Timo
>


Re: Missing or wrong version of dependency

2015-01-10 Thread Gabor Szabo
BTW the same happens if I try to run this command in the freshly cloned
copy of https://github.com/supernovus/perl6-http-easy

On Sat, Jan 10, 2015 at 11:28 PM, Gabor Szabo  wrote:

> I have the Rakudo Star installation with HTTP::Easy in it. I was trying to
> play a bit
>
> with the source code of HTTP::Easy, copied the HTTP/Easy.pm6 file to a
> private lib directory and the
>
> tried to launch a simple script using Bailador that uses HTTP::Easy.
>
> perl6 -Ilib sample.pl6
>
> This is the error I got:
>
> ===SORRY!===
>
> Missing or wrong version of dependency
> '/Users/gabor/rakudo-star-2014.12.1/install/languages/perl6/lib/HTTP/Easy.pm6'
>
>
>
> And I have not even changes Easy.pm6 file!
> What does this error mean and what else do I need to to in order to be
> able to use my own copy of this module?
>
> Gabor
>
>
>


Missing or wrong version of dependency

2015-01-10 Thread Gabor Szabo
 I have the Rakudo Star installation with HTTP::Easy in it. I was trying to
play a bit

with the source code of HTTP::Easy, copied the HTTP/Easy.pm6 file to a
private lib directory and the

tried to launch a simple script using Bailador that uses HTTP::Easy.

perl6 -Ilib sample.pl6

This is the error I got:

===SORRY!===

Missing or wrong version of dependency
'/Users/gabor/rakudo-star-2014.12.1/install/languages/perl6/lib/HTTP/Easy.pm6'



And I have not even changes Easy.pm6 file!
What does this error mean and what else do I need to to in order to be able
to use my own copy of this module?

Gabor


  1   2   >