Re: &MAIN signature to preserve @*ARGFILES ?

2015-12-01 Thread yary
So that's no longer an issue, good news! Thanks for running that test
on the latest Rakudo Star and sharing the result.
-y


On Tue, Dec 1, 2015 at 5:16 PM, Andrew Kirkpatrick  wrote:
> @yary, I'm using linux and for your program with the sole option -t

> Rakudo 2015.11:
> Usage:
>   /tmp/test.pl6 [-t=] [<*ARGS> ...]
>


Re: &MAIN signature to preserve @*ARGFILES ?

2015-12-01 Thread Andrew Kirkpatrick
@yary, I'm using linux and for your program with the sole option -t
Rakudo 2015.07.2:
(Bool)
:True:

Rakudo 2015.11:
Usage:
  /tmp/test.pl6 [-t=] [<*ARGS> ...]

On 2 December 2015 at 02:36, yary  wrote:
> This variation confuses me. I expect $t to be constrained to "Str",
> but MAIN is letting it be a "Bool." I'm using Rakudo* from 201509, the
> 11 release isn't out for Windows-
>
> sub MAIN (*@*ARGS,Str :$t) {
> say $t.WHAT;
> say ":$t:"
> # .say for padded-cols $t, $*ARGFILES.lines.map: (*.split($t))
> }
>
>> perl6 foo\m.p6 -t
> (Bool)
> :True:


Re: &MAIN signature to preserve @*ARGFILES ?

2015-12-01 Thread yary
This variation confuses me. I expect $t to be constrained to "Str",
but MAIN is letting it be a "Bool." I'm using Rakudo* from 201509, the
11 release isn't out for Windows-

sub MAIN (*@*ARGS,Str :$t) {
say $t.WHAT;
say ":$t:"
# .say for padded-cols $t, $*ARGFILES.lines.map: (*.split($t))
}

> perl6 foo\m.p6 -t
(Bool)
:True:


Re: &MAIN signature to preserve @*ARGFILES ?

2015-12-01 Thread yary
On Mon, Nov 30, 2015 at 2:56 AM, Marc Chantreux  wrote:
> sub MAIN (*@*ARGS,:$t) {
> say "$t"
> # .say for padded-cols $t, $*ARGFILES.lines.map: (*.split($t))
> }


I changed your test code to better show the space, and it displays it OK.

sub MAIN (*@*ARGS,:$t) {
say ":$t:"
}

> perl6.bat test-MAIN.pl -t=" "
: :

-y


Re: &MAIN signature to preserve @*ARGFILES ?

2015-11-29 Thread Marc Chantreux
Thanks for testing, Andrew

On Sun, Nov 29, 2015 at 09:16:23AM -0500, yary wrote:
> The problem is in the line that builds the format string:
> sub record-fmt( $col ) { "\%-{ [max] @sheet[*;$col].map: *.chars }s" }; 

i don't think so: i just replaced my &MAIN with and it seems the problem
remains so i don't think this is about my code.

sub MAIN (*@*ARGS,:$t) {
say "$t"
# .say for padded-cols $t, $*ARGFILES.lines.map: (*.split($t))
}

i'm now running with 
This is perl6 version 2015.11 built on MoarVM version 2015.11 

regards


-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
-- Abraham Lincoln


Re: &MAIN signature to preserve @*ARGFILES ?

2015-11-29 Thread yary
The problem is in the line that builds the format string:
sub record-fmt( $col ) { "\%-{ [max] @sheet[*;$col].map: *.chars }s" };

when $col eq ' ' it builds an invalid format. I don't know the proper
fix, but as a workaround does t="' '" work?
-y


Re: &MAIN signature to preserve @*ARGFILES ?

2015-11-28 Thread Andrew Kirkpatrick
Tangentally related, I gave this program a go and the first separator
I tried was a space, but found that while other strings work, one or
more spaces doesn't. I tried -t and --t, with or without an equals
sign to no avail:

$ ./padded-cols.pl6 -t=" " padded.txt
Cannot invoke this object
  in block  at ./padded-cols.pl6:9

The error is a bit cryptic. Any idea why it doesn't work and how space
might be allowed?

On 29 November 2015 at 05:42, Marc Chantreux  wrote:
> On Sat, Nov 28, 2015 at 06:57:11PM +0100, Moritz Lenz wrote:
>> sub MAIN(*@*ARGS, Bool :$mean) { ... }
>
> damn it! i was so close! it will take me some time to understand that
> the positions of the parameters are completely revisited.
>
> so i mixed your answer and some interesting notes on lisibility by
> cognominal and finally get the following code.
>
> thanks a lot, perl6 hackers!
>
> #! env perl6
>
> sub padded-cols ($sep,@sheet) {
> sub record-fmt( $col ) { "\%-{ [max] @sheet[*;$col].map: *.chars }s" };
> my $fmt = @sheet[0].keys.map(&record-fmt).join: $sep;
> @sheet.map: {$fmt.sprintf(|$_)}
> }
>
> sub MAIN (*@*ARGS,:$t) {
> .say for padded-cols $t, $*ARGFILES.lines.map: (*.split($t)).eager;
> }
>
> --
> Marc Chantreux (eiro on github and freenode)
> http://eiro.github.com/
> http://eiro.github.com/atom.xml
> "Don't believe everything you read on the Internet"
> -- Abraham Lincoln


Re: &MAIN signature to preserve @*ARGFILES ?

2015-11-28 Thread Marc Chantreux
On Sat, Nov 28, 2015 at 06:57:11PM +0100, Moritz Lenz wrote:
> sub MAIN(*@*ARGS, Bool :$mean) { ... }

damn it! i was so close! it will take me some time to understand that
the positions of the parameters are completely revisited.

so i mixed your answer and some interesting notes on lisibility by
cognominal and finally get the following code. 

thanks a lot, perl6 hackers! 

#! env perl6

sub padded-cols ($sep,@sheet) {
sub record-fmt( $col ) { "\%-{ [max] @sheet[*;$col].map: *.chars }s" };
my $fmt = @sheet[0].keys.map(&record-fmt).join: $sep;
@sheet.map: {$fmt.sprintf(|$_)}
}

sub MAIN (*@*ARGS,:$t) {
.say for padded-cols $t, $*ARGFILES.lines.map: (*.split($t)).eager;
}

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
-- Abraham Lincoln


Re: &MAIN signature to preserve @*ARGFILES ?

2015-11-28 Thread Moritz Lenz
Hi,

On 11/28/2015 05:49 PM, Marc Chantreux wrote:
> hello,
> 
> i would like to write a better version of the unix `column` with some
> options like 'preserve separator' so i started to write it down.
> 
> sub padded-cols ($sep,@sheet) {
> my $fmt =
> join $sep,
> @sheet[0].keys.map: 
> -> $col { "\%-{ [max] @sheet[*;$col].map: *.chars }s" };
> @sheet.map: {$fmt.sprintf(|$_)}
> }
> 
> my $sep = @*ARGS.shift;
> .say for padded-cols $sep, $*ARGFILES.lines.map: (*.split($sep)).eager;
> 
> now i would like to add options like -mean -max 1:25 and it would be
> nice to write a MAIN function to delegate borring stuff to perl6. 
> 
> i googled, tried to read the doc and grep in roast but i found no way to
> do it. any idea to help me. so thanks thanks for reading and helping.

Since $*ARGFILES (the thing behind lines() for example) uses @*ARGS to
determine what files to open, you can say


sub MAIN(*@*ARGS, Bool :$mean) { ... }

Cheers,
Moritz