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\


[perl #131399] Feature Request: Better NativeCall Array termination

2017-05-29 Thread via RT
# New Ticket Created by  Benjamin Goldberg 
# Please include the string:  [perl #131399]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=131399 >


There are lots of C APIs where a data structure has an array of pointers, with 
a NULL value indicating where that array ends.

It would be nice if I could tell NativeCall that some CArray returned by some C 
function is such an array, and prevent the user from reading the NULL, or 
anything beyond it.

This could also automatically append a NULL if necessary when a NativeCall 
managed CArray is passed to some C function.

For example:

my $environ = cglobal( Str, ‘environ’, CArray[Str] is NULL-terminated );
my %e = map split( ‘=’, *, 2 ), @$environ;


There are also C functions where the length is passed as a separate integer.  
It would be nice if, for this type of API, a CArray could be given an explicit 
length, which would then prevent the user from accidentally reading beyond the 
end of the array.

Perhaps something like:

sub poll( CArray[pollfd] $fds, int32 $nfds, int32 timeout –> int32 is 
CArray-elems(‘$fds’) ) is native;

It would also be nice if CArray did the role Iterable, though obviously only if 
it’s NULL terminated or the length has been assigned to.


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


[perl #131398] Feature Request: trait for unimplemented subs/methods

2017-05-29 Thread Aleks-Daniel Jakimenko-Aleksejev via RT
But we already have ..., !!! and ???. Isn't it what you want?

 m: sub foo() { … }; foo
 rakudo-moar 608e88: OUTPUT: «Stub code executed␤ in sub foo at 
line 1␤ in block  at  line 1␤␤Actually thrown at:␤ in block 
at  line 1␤␤»
 m: sub foo() { !!! }; foo
 rakudo-moar 608e88: OUTPUT: «Stub code executed␤ in sub foo at 
line 1␤ in block  at  line 1␤␤»
 m: sub foo() { ??? }; foo
 rakudo-moar 608e88: OUTPUT: «Stub code executed␤ in sub foo at 
line 1␤»

On 2017-05-29 16:03:29, ben-goldb...@hotmail.com wrote:
> There should be a trait, called either nyi or unimplemented (choose your
> favorite name and capitalization) which changes the subroutine or method
> it's applied to so that, when it's called, it dies or fails with an X::NYI
> exception.
>
> Alternatively, a slightly more generic solution might be more useful:
>
> role AutoDie[$class, $message?] {
> method CALL-ME(*@_, *%_)) {
> die $class.new: $message // |();
> }
> };
> role AutoFail[$class, $message?] {
> method CALL-ME(*@_, *%_) {
> fail $class.new: $message // |();
> }
> }
>
> sub foo does AutoFail[X::NYI, "Sorry, we haven't gotten to foo yet!"] {...}


[perl #131398] Feature Request: trait for unimplemented subs/methods

2017-05-29 Thread Zoffix Znet via RT
On Mon, 29 May 2017 16:03:29 -0700, ben-goldb...@hotmail.com wrote:
> There should be a trait, called either nyi or unimplemented (choose your 
> favorite name and capitalization) which changes the subroutine or method 
> it's applied to so that, when it's called, it dies or fails with an X::NYI 
> exception.
> 
> Alternatively, a slightly more generic solution might be more useful:
> 
> role AutoDie[$class, $message?] {
>method CALL-ME(*@_, *%_)) {
>   die $class.new: $message // |();
>}
> };
> role AutoFail[$class, $message?] {
> method CALL-ME(*@_, *%_) {
>fail $class.new: $message // |();
> }
> }
> 
> sub foo does AutoFail[X::NYI, "Sorry, we haven't gotten to foo yet!"] {...}


Thank you for the suggestion. However, I don't believe there's any serious 
demand for this feature, to justify it being included in core.

In fact, `does AutoFail[X::NYI, "Sorry, we haven't gotten to foo yet!"] ` is 1 
MORE characters to type than `die X::NYI.new: :feature`

Perhaps, you could publish it as a module: 
https://docs.perl6.org/language/modules


[perl #131398] Feature Request: trait for unimplemented subs/methods

2017-05-29 Thread Zoffix Znet via RT
On Mon, 29 May 2017 16:03:29 -0700, ben-goldb...@hotmail.com wrote:
> There should be a trait, called either nyi or unimplemented (choose your 
> favorite name and capitalization) which changes the subroutine or method 
> it's applied to so that, when it's called, it dies or fails with an X::NYI 
> exception.
> 
> Alternatively, a slightly more generic solution might be more useful:
> 
> role AutoDie[$class, $message?] {
>method CALL-ME(*@_, *%_)) {
>   die $class.new: $message // |();
>}
> };
> role AutoFail[$class, $message?] {
> method CALL-ME(*@_, *%_) {
>fail $class.new: $message // |();
> }
> }
> 
> sub foo does AutoFail[X::NYI, "Sorry, we haven't gotten to foo yet!"] {...}


Thank you for the suggestion. However, I don't believe there's any serious 
demand for this feature, to justify it being included in core.

In fact, `does AutoFail[X::NYI, "Sorry, we haven't gotten to foo yet!"] ` is 1 
MORE characters to type than `die X::NYI.new: :feature`

Perhaps, you could publish it as a module: 
https://docs.perl6.org/language/modules


[perl #131398] Feature Request: trait for unimplemented subs/methods

2017-05-29 Thread via RT
# New Ticket Created by  Benjamin Goldberg 
# Please include the string:  [perl #131398]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=131398 >


There should be a trait, called either nyi or unimplemented (choose your 
favorite name and capitalization) which changes the subroutine or method 
it's applied to so that, when it's called, it dies or fails with an X::NYI 
exception.

Alternatively, a slightly more generic solution might be more useful:

role AutoDie[$class, $message?] {
   method CALL-ME(*@_, *%_)) {
  die $class.new: $message // |();
   }
};
role AutoFail[$class, $message?] {
method CALL-ME(*@_, *%_) {
   fail $class.new: $message // |();
}
}

sub foo does AutoFail[X::NYI, "Sorry, we haven't gotten to foo yet!"] {...}


[perl #131397] semicolon subscripting in multi dim arrays has odd interactions with numeric string indexes

2017-05-29 Thread via RT
# New Ticket Created by  Steve Schulze 
# Please include the string:  [perl #131397]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=131397 >


Semicolon subscripting in multi dim arrays has odd interactions with 
indexes that are numeric strings ( but not IntStrings )

See gist: 
https://gist.github.com/thundergnat/d6dd2d319afc71ee16234c58b3883f0f

sub d(*@d) {
 #say @d; # Debugging
 my @a = [0, 1], [1, 0];
 my $r = 0;
 for @d -> $c {
 $r = @a[$r;$c]
 };
 print $r.WHAT.gist, ', '; # Debugging
 $r
};

say d( (1,1,0).List );
say d( (1,1,0).Seq );
say d( (1,1,0).Array );
say d( [1,1,0] );
say d( <1 1 0> );
say d( 1,1,0 );
say d( 110.comb ); # WAT


See IRClogs around https://irclog.perlgeek.de/perl6/2017-05-29#i_14654879

 Hmmm. Don't know if this rises to the level of a bug, it 
it is certainly a WAT at least to me.
 m: 
https://gist.github.com/thundergnat/d6dd2d319afc71ee16234c58b3883f0f
 rakudo-moar 608e88: OUTPUT: «(Int), 0␤(Int), 0␤(Int), 0␤(Int), 
0␤(Int), 0␤(Int), 0␤(List), (1)␤»
 hmmm..  I guess we could have a .comb candidate for Int that 
would generate Int's
 but that feels a bit too magic
 lizmat: The weird thing is that the d sub gets an array 
from .comb like every other instance, it just treats the array 
subindexing differently.
 because it gets Str as indexes
 as does <1 1 0> but _that_ works as expected...
 thundergnat: but those are IntStr's
 so they use the Int candidate
 erm... Good point.
 m: dd <1>, "1"
 rakudo-moar 608e88: OUTPUT: «IntStr.new(1, "1")␤"1"␤»
 Anyway, As I said not really a bug, but it confused me for 
about 15 minutes today.
 thundergnat: I think this WAT warrants a rakudobug fwiw
 it shouldn't make a difference
 Want me to rakudobug it?
 lizmat The other odd thing; if I do the subscripting as 
@d[$r][$c] ( rather than @d[$r;$c] ) it works as expected in all cases.
 yeah, so the [;] candidate handles Str differently
 definitely rakudobug this  :-)


[perl #131396] Documentation improvement for NativeCall

2017-05-29 Thread via RT
# New Ticket Created by  Benjamin Goldberg 
# Please include the string:  [perl #131396]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=131396 >


The ‘is native’ trait works on methods.  It would be nice if this were 
documented.
Also, users can (and probably should) create their own traits which call
trait_mod:(Routine, :$native);

If we start with the code in
https://perl6advent.wordpress.com/2015/12/21/day-21-nativecall-backs-and-beyond-c/
we can modify it as follows:

multi trait_mod:(Routine $r, :$e!) {
trait_mod:($r, native => ‘expat’);
trait_mod:($r, symbol => ‘XML_’ ~ $name);
};
class XML_Parser is repr(‘CPointer’) {
 multi trait_mod:(Routine $r, :$p!) {
trait_mod:($r, native => ‘expat’);
trait_mod:($r, symbol => ‘XML_Parser’ ~ $name);
};

method SetElemetHandler(
 (OpaquePointer, Str, CArray[Str]),  (OpaquePointer, Str))
) {...} is e;
our sub Create(Str -> XML_Parser) is p {...};
method Free() is p {...};
method Parse(Buf, int32, int32 --> int32) is e {...};
}

my $xml = ...;
my $parser = XML_Parser::Create('UTF-8');
$parser.SetElementHandler($parser, , );
my $buf = $xml.encode('UTF-8');
$parser.Parse($buf, $buf.elems, 1);
$parser.Free;

We could make the code even more compact, with the aid of a module to
generate 'e' and 'p' for us.
That module might be used as:
use NativeCall::MakeTrait "e", native => "expat", prefix => 'XML_';
use NativeCall::MakeTrait "p", native => "expat", prefix => 
'XML_Parser';
with details for that module left as an exercise for the reader :).


[perl #131385] NQP converts large integers to floats when it shouldn't/doesn't need to

2017-05-29 Thread Will Coleda via RT
Moved ticket to

https://github.com/perl6/nqp/issues/363

in the NQP issues queue.

-- 
Will "Coke" Coleda


[perl #131385] NQP converts large integers to floats when it shouldn't/doesn't need to

2017-05-29 Thread Will Coleda via RT
Moved ticket to

https://github.com/perl6/nqp/issues/363

in the NQP issues queue.

-- 
Will "Coke" Coleda


[perl #131395] Using a cross meta operator on an empty list complains about not supporting elems

2017-05-29 Thread Zoffix Znet via RT
On Mon, 29 May 2017 10:02:27 -0700, thunderg...@comcast.net wrote:
> Using a cross meta operator on an empty list complains "This type 
> (Scalar) does not support elems".
> 
>  say (1,2).elems; say ().elems; say (1,2) X ();
> 
> yields "2␤0␤This type (Scalar) does not support elems"
> 
> Seems to work correctly with arrays instead of lists.
> 
>  say [1,2].elems; say [].elems; say [1,2] X [];
> 
> 
> Linux Mint 17.2
> 
>  >perl6 -v
>  >This is Rakudo version 2017.05 built on MoarVM version 2017.05 
> implementing Perl 6.c.


Thank you for the report. lizmat++ fixed the issue.

Fix: https://github.com/rakudo/rakudo/commit/9494cbd3b9
Test: https://github.com/perl6/roast/commit/0faf3c354f


[perl #131395] Using a cross meta operator on an empty list complains about not supporting elems

2017-05-29 Thread Zoffix Znet via RT
On Mon, 29 May 2017 10:02:27 -0700, thunderg...@comcast.net wrote:
> Using a cross meta operator on an empty list complains "This type 
> (Scalar) does not support elems".
> 
>  say (1,2).elems; say ().elems; say (1,2) X ();
> 
> yields "2␤0␤This type (Scalar) does not support elems"
> 
> Seems to work correctly with arrays instead of lists.
> 
>  say [1,2].elems; say [].elems; say [1,2] X [];
> 
> 
> Linux Mint 17.2
> 
>  >perl6 -v
>  >This is Rakudo version 2017.05 built on MoarVM version 2017.05 
> implementing Perl 6.c.


Thank you for the report. lizmat++ fixed the issue.

Fix: https://github.com/rakudo/rakudo/commit/9494cbd3b9
Test: https://github.com/perl6/roast/commit/0faf3c354f


Re: [perl #131395] Using a cross meta operator on an empty list complains about not supporting elems

2017-05-29 Thread Elizabeth Mattijsen via RT
> On 29 May 2017, at 19:06, Zoffix Znet via RT  
> wrote:
> 
> https://irclog.perlgeek.de/perl6/2017-05-29#i_14654174
> 
> 16:54 bisectable6 MasterDuke, bisect log: 
> https://gist.github.com/7d49ce1401bee0ab3127c5d1be2a919e
> 16:54 MasterDuke, (2017-01-16) 
> https://github.com/rakudo/rakudo/commit/8a3ff7b64b51a66e0e90437bbeb4793534a07026
> 
> 16:57 Zoffix  m: use nqp; nqp::elems(nqp::getattr((), List, '$!reified'))
> 16:57 camelia rakudo-moar a18c06: OUTPUT: «This type (Scalar) does not 
> support elems␤  in block  at  line 1␤␤»
> 
> 
> 17:00 m: use nqp; dd nqp::getattr((), List, '$!reified').^name; dd 
> nqp::getattr([], List, '$!reified').^name
> 17:00 camelia rakudo-moar a18c06: OUTPUT: «"Mu"␤"IterationBuffer"␤»
> 17:00 Zoffix  Both prolly should be the same? So this bug doesn't occur 
> elsewhere?

FWIW, I’m testing a fix.



Liz


Re: [perl #131395] Using a cross meta operator on an empty list complains about not supporting elems

2017-05-29 Thread Elizabeth Mattijsen
> On 29 May 2017, at 19:06, Zoffix Znet via RT  
> wrote:
> 
> https://irclog.perlgeek.de/perl6/2017-05-29#i_14654174
> 
> 16:54 bisectable6 MasterDuke, bisect log: 
> https://gist.github.com/7d49ce1401bee0ab3127c5d1be2a919e
> 16:54 MasterDuke, (2017-01-16) 
> https://github.com/rakudo/rakudo/commit/8a3ff7b64b51a66e0e90437bbeb4793534a07026
> 
> 16:57 Zoffix  m: use nqp; nqp::elems(nqp::getattr((), List, '$!reified'))
> 16:57 camelia rakudo-moar a18c06: OUTPUT: «This type (Scalar) does not 
> support elems␤  in block  at  line 1␤␤»
> 
> 
> 17:00 m: use nqp; dd nqp::getattr((), List, '$!reified').^name; dd 
> nqp::getattr([], List, '$!reified').^name
> 17:00 camelia rakudo-moar a18c06: OUTPUT: «"Mu"␤"IterationBuffer"␤»
> 17:00 Zoffix  Both prolly should be the same? So this bug doesn't occur 
> elsewhere?

FWIW, I’m testing a fix.



Liz

[perl #131395] Using a cross meta operator on an empty list complains about not supporting elems

2017-05-29 Thread Zoffix Znet via RT
https://irclog.perlgeek.de/perl6/2017-05-29#i_14654174

16:54   bisectable6 MasterDuke, bisect log: 
https://gist.github.com/7d49ce1401bee0ab3127c5d1be2a919e
16:54   MasterDuke, (2017-01-16) 
https://github.com/rakudo/rakudo/commit/8a3ff7b64b51a66e0e90437bbeb4793534a07026

16:57   Zoffix  m: use nqp; nqp::elems(nqp::getattr((), List, '$!reified'))
16:57   camelia rakudo-moar a18c06: OUTPUT: «This type (Scalar) does not 
support elems␤  in block  at  line 1␤␤»


17:00   m: use nqp; dd nqp::getattr((), List, '$!reified').^name; dd 
nqp::getattr([], List, '$!reified').^name
17:00   camelia rakudo-moar a18c06: OUTPUT: «"Mu"␤"IterationBuffer"␤»
17:00   Zoffix  Both prolly should be the same? So this bug doesn't occur 
elsewhere?


[perl #131395] Using a cross meta operator on an empty list complains about not supporting elems

2017-05-29 Thread Zoffix Znet via RT
https://irclog.perlgeek.de/perl6/2017-05-29#i_14654174

16:54   bisectable6 MasterDuke, bisect log: 
https://gist.github.com/7d49ce1401bee0ab3127c5d1be2a919e
16:54   MasterDuke, (2017-01-16) 
https://github.com/rakudo/rakudo/commit/8a3ff7b64b51a66e0e90437bbeb4793534a07026

16:57   Zoffix  m: use nqp; nqp::elems(nqp::getattr((), List, '$!reified'))
16:57   camelia rakudo-moar a18c06: OUTPUT: «This type (Scalar) does not 
support elems␤  in block  at  line 1␤␤»


17:00   m: use nqp; dd nqp::getattr((), List, '$!reified').^name; dd 
nqp::getattr([], List, '$!reified').^name
17:00   camelia rakudo-moar a18c06: OUTPUT: «"Mu"␤"IterationBuffer"␤»
17:00   Zoffix  Both prolly should be the same? So this bug doesn't occur 
elsewhere?


[perl #131395] Using a cross meta operator on an empty list complains about not supporting elems

2017-05-29 Thread via RT
# New Ticket Created by  Steve Schulze 
# Please include the string:  [perl #131395]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=131395 >


Using a cross meta operator on an empty list complains "This type 
(Scalar) does not support elems".

 say (1,2).elems; say ().elems; say (1,2) X ();

yields "2␤0␤This type (Scalar) does not support elems"

Seems to work correctly with arrays instead of lists.

 say [1,2].elems; say [].elems; say [1,2] X [];


Linux Mint 17.2

 >perl6 -v
 >This is Rakudo version 2017.05 built on MoarVM version 2017.05 
implementing Perl 6.c.


Re: zef, zef-j, zef-m

2017-05-29 Thread Fernando Santagata
Thank you!

On Mon, May 29, 2017 at 6:47 PM, Elizabeth Mattijsen  wrote:

>
> > On 29 May 2017, at 17:33, Fernando Santagata 
> wrote:
> >
> > On Mon, May 29, 2017 at 12:20 PM, Brent Laabs  wrote:
> > > On 29 May 2017, at 11:22, Fernando Santagata <
> nando.santag...@gmail.com> wrote:
> > >
> > > /me sighs: NQP is still so poorly documented!
> >
> > Believe it or not, this is documented in nqp/docs/ops.markdown in the
> section under stat.
> >
> > That is not under https://docs.perl6.org/, I presume.
>
> No, as it is specific to the Rakudo / nqp implementation of Perl 6.
>
> You can find it here in rendered format:
>
>   https://github.com/perl6/nqp/blob/master/docs/ops.markdown
>
>
>
> Liz




-- 
Fernando Santagata


Re: [perl #131392] %() creates a Map

2017-05-29 Thread Elizabeth Mattijsen
> On 29 May 2017, at 18:26, brian d foy  wrote:
> I did pull my first example out of a slightly larger program I was
> playing with, but I thought that a match would surely have no effect.
> Stupid me, because I've been around long enough to know that
> assumption is almost always false. That "harmless" thing you leave out
> is the actual problem. Here's a complete program that reproduces it:
> 
>'abcdef' ~~ m/ cd /;
> 
>my $thingy = %();
>put $thingy.^name;  #Map

Well, do we consider the named matches of a match modifiable or not?  Feels to 
me having it as an (immutable) Map feels actually closer to the intent, rather 
than it being a (modifiable) Hash.  It also gives more opportunity for 
optimization.

So perhaps the Hashes should be considered the odd ones out?



Liz

Re: [perl #131392] %() creates a Map

2017-05-29 Thread Elizabeth Mattijsen via RT
> On 29 May 2017, at 18:26, brian d foy  wrote:
> I did pull my first example out of a slightly larger program I was
> playing with, but I thought that a match would surely have no effect.
> Stupid me, because I've been around long enough to know that
> assumption is almost always false. That "harmless" thing you leave out
> is the actual problem. Here's a complete program that reproduces it:
> 
>'abcdef' ~~ m/ cd /;
> 
>my $thingy = %();
>put $thingy.^name;  #Map

Well, do we consider the named matches of a match modifiable or not?  Feels to 
me having it as an (immutable) Map feels actually closer to the intent, rather 
than it being a (modifiable) Hash.  It also gives more opportunity for 
optimization.

So perhaps the Hashes should be considered the odd ones out?



Liz


Re: zef, zef-j, zef-m

2017-05-29 Thread Elizabeth Mattijsen

> On 29 May 2017, at 17:33, Fernando Santagata  
> wrote:
> 
> On Mon, May 29, 2017 at 12:20 PM, Brent Laabs  wrote:
> > On 29 May 2017, at 11:22, Fernando Santagata  
> > wrote:
> >
> > /me sighs: NQP is still so poorly documented!
> 
> Believe it or not, this is documented in nqp/docs/ops.markdown in the section 
> under stat.
> 
> That is not under https://docs.perl6.org/, I presume.

No, as it is specific to the Rakudo / nqp implementation of Perl 6.

You can find it here in rendered format:

  https://github.com/perl6/nqp/blob/master/docs/ops.markdown



Liz

Re: [perl #131392] %() creates a Map

2017-05-29 Thread brian d foy via RT
I did pull my first example out of a slightly larger program I was
playing with, but I thought that a match would surely have no effect.
Stupid me, because I've been around long enough to know that
assumption is almost always false. That "harmless" thing you leave out
is the actual problem. Here's a complete program that reproduces it:

'abcdef' ~~ m/ cd /;

my $thingy = %();
put $thingy.^name;  #Map


Re: [perl #131392] %() creates a Map

2017-05-29 Thread brian d foy
I did pull my first example out of a slightly larger program I was
playing with, but I thought that a match would surely have no effect.
Stupid me, because I've been around long enough to know that
assumption is almost always false. That "harmless" thing you leave out
is the actual problem. Here's a complete program that reproduces it:

'abcdef' ~~ m/ cd /;

my $thingy = %();
put $thingy.^name;  #Map


Re: zef, zef-j, zef-m

2017-05-29 Thread Fernando Santagata
On Mon, May 29, 2017 at 12:20 PM, Brent Laabs  wrote:

> > On 29 May 2017, at 11:22, Fernando Santagata 
>> wrote:
>> >
>> > /me sighs: NQP is still so poorly documented!
>>
>
> Believe it or not, this is documented in nqp/docs/ops.markdown in the
> section under stat.
>

That is not under https://docs.perl6.org/, I presume.

-- 
Fernando Santagata


Nativecall and CArray

2017-05-29 Thread Fernando Santagata
Hello,

I'm trying to encapsulate a C struct, one member of which is an array of
pointers to structs, and I'm having some problems to figure out how to do
it.

I tried to follow the hint in the documentation
https://docs.perl6.org/language/nativecall#Structs

use NativeCall;

class A is repr('CStruct') {
  has uint8 $.u8;
}

class B is repr('CStruct') {
  has CArray[A] $.a;
  submethod TWEAK {
my $arr := CArray[A].new;
for ^5 { $arr[$_] = A.new(u8 => $_) }
$!a := $arr;
  }
}

sub MAIN
{
  my B $b .= new;
  say $b.a[2];
  say 'Size of $b: ' ~ nativesizeof($b);
}

but this way the resulting size is of one pointer, 8 bytes (on my
computer), while what I'm trying to get is a size of 5 pointers, 40 bytes.

Obviously I can do this:

use NativeCall;

class A is repr('CStruct') {
  has uint8 $.u8;
}

class C is repr('CStruct') {
  has A $.a1;
  has A $.a2;
  has A $.a3;
  has A $.a4;
  has A $.a5;
}

sub MAIN
{
  my C $c .= new;
  say nativesizeof($c);
}

which returns the size I need. Yet this solution hurts my feelings :-)

Is there any other way to do it, without resorting to this:

https://stackoverflow.com/questions/43544931/passing-an-array-of-structures-to-a-perl-6-nativecall-function

(Which is presented as "enough rope to -hang yourself- *build a workaround*
")

-- 
Fernando Santagata


Re: zef, zef-j, zef-m

2017-05-29 Thread Brent Laabs
On Mon, May 29, 2017 at 2:25 AM, Elizabeth Mattijsen  wrote:

> Perhaps Zoffix is willing to take a PR for an IO::Path.nlinks method as
> part of the IO grant.
>
>
I think I'd rather have IO::Path.inode myself.  Although, I did roll my own
version in IO::Path::More.


> > On 29 May 2017, at 11:22, Fernando Santagata 
> wrote:
> >
> > /me sighs: NQP is still so poorly documented!
>

Believe it or not, this is documented in nqp/docs/ops.markdown in the
section under stat.


> >
> > On Mon, May 29, 2017 at 11:10 AM, Brent Laabs  wrote:
> > This works without a module on Rakudo:
> >
> > use nqp;
> > my $path = "foo".IO;
> > my $hardlink-count =  nqp::stat($path.absolute,
> nqp::const::STAT_PLATFORM_NLINKS);
> >
> >
> >
> >
> > On Mon, May 29, 2017 at 1:54 AM, Elizabeth Mattijsen 
> wrote:
> > > On 29 May 2017, at 10:42, Fernando Santagata <
> nando.santag...@gmail.com> wrote:
> > >
> > > The three files are already hard-linked, no need for soft links.
> > >
> > > BTW, is there a way to detect hard links in Perl6?
> > > Perl5 "stat" operator returns an array whose fourth element is the
> number of hard links of a file, but I don't see anything like that in the
> Perl6 docs.
> >
> > Generally, unixisms are not directly supported in Perl 6 in the core.
> It should be relatively trivial to create an ecosystem module for this
> using NativeCall directly accessing functionality in libc (which then of
> course won’t work on Windows).
> >
> >
> > Liz
> >
> >
> >
> >
> > --
> > Fernando Santagata
>


Re: zef, zef-j, zef-m

2017-05-29 Thread Elizabeth Mattijsen
Perhaps Zoffix is willing to take a PR for an IO::Path.nlinks method as part of 
the IO grant.

> On 29 May 2017, at 11:22, Fernando Santagata  
> wrote:
> 
> /me sighs: NQP is still so poorly documented!
> 
> On Mon, May 29, 2017 at 11:10 AM, Brent Laabs  wrote:
> This works without a module on Rakudo:
> 
> use nqp;
> my $path = "foo".IO;
> my $hardlink-count =  nqp::stat($path.absolute, 
> nqp::const::STAT_PLATFORM_NLINKS);
> 
> 
> 
> 
> On Mon, May 29, 2017 at 1:54 AM, Elizabeth Mattijsen  wrote:
> > On 29 May 2017, at 10:42, Fernando Santagata  
> > wrote:
> >
> > The three files are already hard-linked, no need for soft links.
> >
> > BTW, is there a way to detect hard links in Perl6?
> > Perl5 "stat" operator returns an array whose fourth element is the number 
> > of hard links of a file, but I don't see anything like that in the Perl6 
> > docs.
> 
> Generally, unixisms are not directly supported in Perl 6 in the core.  It 
> should be relatively trivial to create an ecosystem module for this using 
> NativeCall directly accessing functionality in libc (which then of course 
> won’t work on Windows).
> 
> 
> Liz
> 
> 
> 
> 
> -- 
> Fernando Santagata


Re: zef, zef-j, zef-m

2017-05-29 Thread Fernando Santagata
/me sighs: NQP is still so poorly documented!

On Mon, May 29, 2017 at 11:10 AM, Brent Laabs  wrote:

> This works without a module on Rakudo:
>
> use nqp;
> my $path = "foo".IO;
> my $hardlink-count =  nqp::stat($path.absolute, nqp::const::STAT_PLATFORM_
> NLINKS);
>
>
>
>
> On Mon, May 29, 2017 at 1:54 AM, Elizabeth Mattijsen 
> wrote:
>
>> > On 29 May 2017, at 10:42, Fernando Santagata 
>> wrote:
>> >
>> > The three files are already hard-linked, no need for soft links.
>> >
>> > BTW, is there a way to detect hard links in Perl6?
>> > Perl5 "stat" operator returns an array whose fourth element is the
>> number of hard links of a file, but I don't see anything like that in the
>> Perl6 docs.
>>
>> Generally, unixisms are not directly supported in Perl 6 in the core.  It
>> should be relatively trivial to create an ecosystem module for this using
>> NativeCall directly accessing functionality in libc (which then of course
>> won’t work on Windows).
>>
>>
>> Liz
>
>
>


-- 
Fernando Santagata


Re: zef, zef-j, zef-m

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

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




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

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


Re: zef, zef-j, zef-m

2017-05-29 Thread Elizabeth Mattijsen
> On 29 May 2017, at 10:42, Fernando Santagata  
> wrote:
> 
> The three files are already hard-linked, no need for soft links.
> 
> BTW, is there a way to detect hard links in Perl6?
> Perl5 "stat" operator returns an array whose fourth element is the number of 
> hard links of a file, but I don't see anything like that in the Perl6 docs.

Generally, unixisms are not directly supported in Perl 6 in the core.  It 
should be relatively trivial to create an ecosystem module for this using 
NativeCall directly accessing functionality in libc (which then of course won’t 
work on Windows).


Liz

Re: zef, zef-j, zef-m

2017-05-29 Thread Fernando Santagata
The three files are already hard-linked, no need for soft links.

BTW, is there a way to detect hard links in Perl6?
Perl5 "stat" operator returns an array whose fourth element is the number
of hard links of a file, but I don't see anything like that in the Perl6
docs.

On Sun, May 28, 2017 at 5:31 PM, Parrot Raiser <1parr...@gmail.com> wrote:

> If they are really identical, might it be an idea to use symbolic
> links for 2 of them?
> That would reduce the code to be stored, maintained, and transmitted,
> and make it blatantly obvious if different versions are required.
>
> On 5/28/17, Nelo Onyiah  wrote:
> > I presume that's j for JVM and m for MoarVM.
> >
> > On 28 May 2017 2:42 pm, "Gabor Szabo"  wrote:
> >
> >> 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
> >>
> >
>



-- 
Fernando Santagata