Re: buf to integer?

2019-02-08 Thread Kevin Pye
Unpack is very useful if you have multiple items you want to unpack, and if
you're familiar with the Perl 5 unpack then there's the P5pack module
(which isn't a full implementation of Perl 5's unpack, but is useful for
simpler things). If you want to unpack something from the middle of a Buf
or Blob then you'll need to explicitly skip over the beginning of the
buffer using "x", whereas read-int32 has an explicit position argument.

On Fri, 8 Feb 2019 at 22:00, The Sidhekin  wrote:

> On Fri, Feb 8, 2019 at 7:36 AM Todd Chester via perl6-users <
> perl6-us...@perl.org> wrote:
>
>> I am dealing with a Buf what includes 32 bit integers, but
>> they are entered somewhat backwards as view with hexedit:
>>
>> AE 5D 5C 72 represents the number 725C5DAE
>>
>> This is what I have come up with to convert this type of
>> number in a buffer to and integer
>>
>> $ p6 'my Buf $x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 $i=$x[3] +< 0x18
>> +  $x[2] +< 0x10  +  $x[1] +< 0x08  +  $x[0];  say $x; say $i.base(0x10);'
>>
>> Buf:0x
>> 725C5DAE
>>
>>
>> Is there a more "elegant" way to do this?
>>
>
>   The "elegant" way I'd do it, is using unpack():
> https://docs.perl6.org/routine/unpack
>
>   It's experimental, so a declaration is needed, but Buf does Blob, so
> otherwise, it's straight to the point:
>
> $ perl6 -e 'use experimental :pack; my Buf
> $x=Buf.new(0xAE,0x5D,0x5C,0x72); say $x.unpack("L").base(0x10);'
> 725C5DAE
> $
>
>
> Eirik
>
>


What is a LoweredAwayLexical?

2019-10-22 Thread Kevin Pye
Yesterday I created a new when clause in an existing working program, which
worked fine, but today when I came to exercise another previously working
when clause it was broken.

The golfed version...

my $a = 41;

given 6 {
when 5 {
my $a;
}
when 6 {
say $a + 1;
}
}

When run with various version of rakudo (at least on 2019.07.1 and current
HEAD) this produces

Use of uninitialized value of type Rakudo::Internals::LoweredAwayLexical in
numeric context

Is this expected? If nothing else, the error message is decidedly LTA.

I fixed it in my case by removing the unnecessary redeclaration of $a in
the when clause, but there might be times when that is incorrect.

(And on a side note, are there plans to move this mailing list to
raku-users@somewhere? There's nothing about it in the path to raku
document.)

Kevin.


Re: problems with xor

2020-01-17 Thread Kevin Pye
As you say, +^ is an infix operator. Why are you trying to use it as a
function?

Try $z = $x +^ $y.

On Sat, 18 Jan 2020 at 15:03, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> https://docs.raku.org/routine/+$CIRCUMFLEX_ACCENT
>
> (Operators) infix +^§
>
> multi sub infix:<+^>($a, $b --> Int:D)
>
> Integer bitwise XOR operator: Coerces both arguments to Int and does a
> bitwise XOR (exclusive OR) operation.
>
>
> $ p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b_; my uint8 $z =
> +^($x, $y ); say "0", $x.base(2); say "", $y.base(2); say $z.base(2);'
>
> 01010111
> 
> 1101
>
>
> XOR
> A  B   A xor B
> 0  0  0
> 1  0  1
> 0  1  1
> 1  1  0
>
> That s not what I am seeing above.
>
> What am I doing wrong this time?
>
> And who set the high bit making $z negative?
>
> Many thanks,
> -T
>


Re: problems with xor

2020-01-17 Thread Kevin Pye
In Raku, all operators are just functions with a funny syntax, but if you
want to use it as a function, you need the full name.

infix:<+^>($x, $y) would probably work just as well.

And where is the '$' before the z?

On Sat, 18 Jan 2020 at 15:45, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Fri, Jan 17, 2020 at 11:03 PM ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> https://docs.raku.org/routine/+$CIRCUMFLEX_ACCENT
> >>
> >> (Operators) infix +^§
> >>
> >> multi sub infix:<+^>($a, $b --> Int:D)
> >>
> >> Integer bitwise XOR operator: Coerces both arguments to Int and
> does a
> >> bitwise XOR (exclusive OR) operation.
> >>
> >>
> >> $ p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b_; my uint8
> $z =
> >> +^($x, $y ); say "0", $x.base(2); say "", $y.base(2); say
> >> $z.base(2);'
> >>
> >> 01010111
> >> 
> >> 1101
> >>
> >>
> >> XOR
> >> A  B   A xor B
> >> 0  0  0
> >> 1  0  1
> >> 0  1  1
> >> 1  1  0
> >>
> >> That s not what I am seeing above.
> >>
> >> What am I doing wrong this time?
> >>
> >> And who set the high bit making $z negative?
> >>
> >> Many thanks,
> >> -T
>
>
> On 2020-01-17 20:24, Paul Procacci wrote:
> > multi sub infix:<+^>($a, $b-->Int:D)
> >
> >
> > _infix_ here is the keyword for you.
> >
> > my uint8 $z = $x +^ $y;
>
> $ p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b_; my uint8 $z =
> $x +^ $y; say "0", $x.base(2); say "", $y.base(2); say z.base(2);'
> ===SORRY!=== Error while compiling -e
> Undeclared routine:
>  z used at line 1
>
> What does "sub" stand for?
>


Re: problems with xor

2020-01-18 Thread Kevin Pye
As has been explained quite explicitly twice already, you call it as a sub
by using the full explicit name of the subroutine:

$z = infix:<+^>($x, $y)



On Sun, 19 Jan 2020 at 07:22, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-01-18 06:09, Tobias Boege wrote:
> > On Fri, 17 Jan 2020, ToddAndMargo via perl6-users wrote:
> >> Hi All,
> >>
> >> https://docs.raku.org/routine/+$CIRCUMFLEX_ACCENT
> >>
> >> (Operators) infix +^§
> >>
> >> multi sub infix:<+^>($a, $b --> Int:D)
> >>
> >> Integer bitwise XOR operator: Coerces both arguments to Int and does a
> >> bitwise XOR (exclusive OR) operation.
> >>
> >>
> >> $ p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b_; my uint8 $z =
> >> +^($x, $y ); say "0", $x.base(2); say "", $y.base(2); say
> $z.base(2);'
> >>
> >> 01010111
> >> 
> >> 1101
> >>
> >>
> >> XOR
> >> A  B   A xor B
> >> 0  0  0
> >> 1  0  1
> >> 0  1  1
> >> 1  1  0
> >>
> >> That s not what I am seeing above.
> >>
> >> What am I doing wrong this time?
> >>
> >> And who set the high bit making $z negative?
> >>
> >
> > As was already mentioned, if you want to use the &infix:<+^> operator,
> > you have to either call it by its full name as a sub:
> >
> >&infix:<+^>($x, $y)
> >
> > or you have to use it according to its syntax category, as an infix:
> >
> >$x +^ $y
> >
> > When you write +^($x,$y), its cousin &prefix:<+^> is called instead,
> > because now you use +^ as a prefix operator. That one performs bitwise
> > negation on its argument coerced to Int, and since you pass it a list
> > of length two, you actually evaluate +^2. And that's how you get the
> > high bit and a value of -3.
> >
> > Regards,
> > Tobias
> >
>
> Hi Tobias,
>
> This works perfectly using the syntax $a = $b +^ $c
>
> p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b_; my uint8 $z = $x
> +^ $y; say "0", $x.base(2); say "", $y.base(2); say "0",$z.base(2);'
>
> 01010111# $x
> # $y
> 01011000# z = x xor y
>
>
> But what is now confusing me is $c = +^( $a, $b )
>
> p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b_; my uint8 $z =
> +^($x, $y); say "0", $x.base(2); say "", $y.base(2); say $z.base(2);'
>
> 01010111# $x
> # $y
> 1101# z is not  x xor y
>
> Which is clearly not correct.  The manual states:
>
>Integer bitwise XOR operator: Coerces both
>arguments to Int and does a bitwise XOR
>(exclusive OR) operation.
>
> In my example run line, I purposefully left the
> high bit off to keep overly helpful Raku from thinking
> I had a negative number when it annoyingly overrules
> my choice of native type.  (Ordinarily I like this
> feature, except when doing bitwise operations, I
> wish I could turn it off.)
>
> So I am confused.
>
> -T
>


Re: range doc page

2020-01-27 Thread Kevin Pye
There's no need to ask essentially the same question three times.

https://docs.raku.org/routine/range 
is quite clearly the wrong page. That's about a method on the class
X::OutOfRange, and not a method on Int. You want
https://docs.raku.org/routine/Range, which will unfortunately not be much
more useful.

Your original error message "Invocant of method 'Range' must be a type
object of
type 'Int', not an object instance of type 'Int'" is much more useful.

Your variable $u contains a variable of type Int. What the method Range
wants is a "type object of type 'Int'" which is not the same thing.This is
what you would get with a definition like "my UInt $u;". $u is now a
variable containing no definite value, but is of type UInt. If you were to
"say $u" you would get "(UInt)", which is a type object. "say $u.Range"
would then give "0..^Inf".

This is related to the ":D" and ":U" forms in signatures. "sub x(Int:D
$arg)" would require the subroutine to be passed an actual object of type
Int. "sub y(Int:U $arg)" would need to be passed a "type object of type
'Int'". If you were to check the source you would find the signature of
Range to be something like "method Range(Int:U --> Range)".

Kevin.

On Tue, 28 Jan 2020 at 16:09, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> On https://docs.raku.org/routine/range, it states:
>
> method range(--> Range:D)
>
> What is being said?
>
> method I understand.
>
> Range would be the name of the method
>
> --> means is return the range of what was fed the
> method and is defined
>
>
> This one ain't all the hard to decipher.
>
> So why does this not work?
>
>  > my int8 $u = 0xF8; $u.range
>
> No such method 'range' for invocant of type 'Int'. Did you mean any of
> these?
>  Range
>  rand
>
>
> Perplexed,
> -T
>


Re: printf question

2020-02-11 Thread Kevin Pye
The "workaround" is well documented:
https://docs.raku.org/language/create-cli#%*SUB-MAIN-OPTS

It's just a matter of setting named-anywhere option in the %*SUB-MAIN-OPTS
hash, which you will also need to create. There's an example in that doc
page.

Kevin.

On Tue, 11 Feb 2020 at 20:07, WFB  wrote:

> Interesting stuff.
> I would like to take the change and ask one question:
> One thing, I had to get used to is the MAIN handling of parameters.
> On the command line it is important to write then named parameter in front
> of the positional ones:
> MAIN('compile', :$verbose, :$test-only)
> needs to write:
> builder.raku --verbose compile
> Its not possible to write
> builder.raku compile --verbose.
> That is not intuitive, at least for me because that breaks with the other
> unix command line tools and is annoying if you have to change the script
> call several times.
>
> Why is that so? And is there a workaround for that?
> Thanks
> Wolfgang
>
> On Mon, 10 Feb 2020 at 12:18, Timo Paulssen  wrote:
>
>> Hi Paul and Todd,
>>
>> just a little extra info: the limitation for nameds to come after
>> positionals is only for declarations of signatures.
>>
>> Usage of subs/methods as well as capture literals (which you don't use
>> often, i imagine, so feel free to disregard) allow you to mix nameds and
>> positionals freely; it will handle named parameters that are put between
>> positionals as if they were after the positional parameters.
>>
>> > sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }
>> &abcdefg
>> > abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
>> 51991024
>>
>> Most cases where I wanted named parameters early in the call was when
>> there was something big in the call, for example if a sub takes a block and
>> a few options, i prefer to put the options before the block, so they are
>> visible at a glance rather than after scrolling. I suppose this mirrors how
>> regex modifiers (like :ignorecase / :i, :global, etc) have been moved to
>> the front of regexes.
>>
>> Hope that's interesting
>>   - Timo
>> On 10/02/2020 07:48, Paul Procacci wrote:
>>
>> Named parameters must come after all positional parameters.
>> Your example subroutine is invalid for this reason, while the following
>> would be fine:
>>
>> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>>
>> abcdefg("position1", "position2", "position3", :e("named_e"),
>> :a("named_a"), :c("named_c"));
>>
>>
>>
>> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users <
>> perl6-us...@perl.org> wrote:
>>
>>> On 2020-02-09 14:53, Paul Procacci wrote:
>>> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>>>
>>> Hi Paul,
>>>
>>> What I wanted to see is how something liek
>>>
>>> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>>>
>>> would be called
>>>
>>> -T
>>>
>>
>>
>> --
>> __
>>
>> :(){ :|:& };:
>>
>>


Re: Question about Blob and Buf

2020-02-11 Thread Kevin Pye
~ works fine for concatenating Bufs; For example:

my $a = Buf.new(1,2,3);
my $b = $a ~ Buf.new(4,5,6)

will assign correctly to $b.

I can't work out what the problem is here, despite trying various
combinations. Perhaps socket isn't really returning a Blob?

Kevin.

On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:

> You are using ~, which stringifies. Bufs are not strings: you need to
> decode them to concatenate it to a string. If what you want is to
> concatenate the buffer, probably ,= will work (not sure about this, would
> have to check), or any other operator that works on Positionals.
>
> JJ
>
> El mar., 11 feb. 2020 a las 10:56, David Santiago ()
> escribió:
>
>> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
>> deman...@gmail.com> escreveu:
>> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
>> deman...@gmail.com> escreveu:
>> >>
>> >>Hi!
>> >>
>> >>Can someone explain me why this doesn't work:
>> >>
>> >>my Blob $read;
>> >>$read ~= $socket.read(1024);
>> >>
>> >>Dies with error:
>> >>
>> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>> method on it
>> >>
>> >>This also doesn't work:
>> >>
>> >>my Buf $read;
>> >>$read ~= $socket.read(1024);
>> >>
>> >>Dies with the same error as above.
>> >>
>> >>
>> >>But this works?
>> >>
>> >>my Blob $read = Buf.new;
>> >>$read ~= $socket.read(1024);
>> >>
>> >>
>> >>Best regards,
>> >>David Santiago
>> >
>> >
>> >Hi!
>> >
>> >Can someone explain me why this doesn't work:
>> >
>> >my Blob $read;
>> >$read ~= $socket.read(1024);
>> >
>> >Dies with error:
>> >
>> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>> method on it
>> >
>> >This also doesn't work:
>> >
>> >my Buf $read;
>> >$read ~= $socket.read(1024);
>> >
>> >Dies with the same error as above.
>> >
>> >
>> >But this works?
>> >
>> >my Blob $read = Buf.new;
>> >$read ~= $socket.read(1024);
>> >
>> >
>> >Best regards,
>> >David Santiago
>>
>>
>> Hi!
>>
>> Can someone explain me why this doesn't work:
>>
>> my Blob $read;
>> $read ~= $socket.read(1024);
>>
>> Dies with error:
>>
>> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>> method on it
>>
>> This also doesn't work:
>>
>> my Buf $read;
>> $read ~= $socket.read(1024);
>>
>> Dies with the same error as above.
>>
>>
>> But this works?
>>
>> my Blob $read = Buf.new;
>> $read ~= $socket.read(1024);
>>
>>
>> Best regards,
>> David Santiago
>>
>> --
>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>>
>
>
> --
> JJ
>


Re: I need help with IO.e

2020-05-16 Thread Kevin Pye
There are three possibilities for the.d test -- the file exists and is a
directory, the files exists and is not a directory, and the file does not
exist. The test needs to distinguish between these three cases.

The documentation for .d states:

Returns True if the invocant is a path that exists and is a directory. The
method will fail  with
X::IO::DoesNotExist if the path points to a non-existent filesystem entity.

(and by implication False if the file exists and is not a directory). In
other words it is behaving exactly as specified.

If you want to allow for the possibility that the file does not exist at
all, then you either need to catch the exception, or check for file
existence first.

Something like
'p7lib'.IO ~~ :e & :d
might work, although I haven't tested it.

Kevin.


On Sat, 16 May 2020 at 20:16, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-05-15 22:30, ToddAndMargo via perl6-users wrote:
> > Hi All,.
> >
> > Windows 7, sp1, x64
> >
> >  >raku -v
> > This is Rakudo version 2020.01 built on MoarVM version
> > 2020.01.1 implementing Perl 6.d.
> >
> >
> > I am trying to get perl to tell me if a drive letter exists
> >
> > This is from Git's df command:
> >
> >  >df -kPT H:\
> > Filesystem Type 1024-blocks  Used Available Capacity Mounted on
> > H: ntfs   38908  9964 28944  26% /h
> >
> > So, H:\ is there
> >
> >  >raku "say H:\.IO.e"
> > Could not open say H:\.IO.e. Failed to stat file: no such file or
> directory
> >
> > And in case I need \\
> >
> >  >raku "say H:\\.IO.e"
> > Could not open say H:\\.IO.e. Failed to stat file: no such file or
> > directory
> >
> > And in case I need a forward slashL:
> >  >raku "say H:/.IO.e"
> > Could not open say H:/.IO.e. Failed to stat file: no such file or
> directory
> >
> > What am I doing wrong, this time?
> >
> > -T
> >
>
>
> As far as I can tell IO.e and IO.d is completely trashed
> in Windows:
>
> K:\Windows\NtUtil>dir H:
>   Volume in drive H is BACKUP
>   Volume Serial Number is 00D0-CAD4
>
>   Directory of H:\
>
> 05/15/2020  22:21 0 IAmBackup
> 05/15/2020  22:43  MyDocsBackup
> 1 File(s)  0 bytes
> 1 Dir(s)  29,638,656 bytes free
>
>
>
> K:\Windows\NtUtil>raku "say 'h://IAmBackup'.IO.e"
> Could not open say 'h://IAmBackup'.IO.e. Failed to stat file: no such
> file or di
> rectory
>
> K:\Windows\NtUtil>raku "say 'h:/IAmBackup'.IO.e"
> Could not open say 'h:/IAmBackup'.IO.e. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h:\IAmBackup'.IO.e"
> Could not open say 'h:\IAmBackup'.IO.e. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h:\\IAmBackup'.IO.e"
> Could not open say 'h:\\IAmBackup'.IO.e. Failed to stat file: no such
> file or directory
>
>
> And that goes for IO.d too:
>
> K:\Windows\NtUtil>raku "say 'h:\\MyDocsBackup'.IO.d"
> Could not open say 'h:\\MyDocsBackup'.IO.d. Failed to stat file: no such
> file or
>   directory
>
> K:\Windows\NtUtil>raku "say 'h:\MyDocsBackup'.IO.d"
> Could not open say 'h:\MyDocsBackup'.IO.d. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h:/MyDocsBackup'.IO.d"
> Could not open say 'h:/MyDocsBackup'.IO.d. Failed to stat file: no such
> file or directory
>
> K:\Windows\NtUtil>raku "say 'h://MyDocsBackup'.IO.d"
> Could not open say 'h://MyDocsBackup'.IO.d. Failed to stat file: no such
> file or  directory
>
> This gets a TRIPLE:  :'(  :'(  :'(
>
>
>
> And it only works slightly better under Fedora:
>
> $ p6 'say "GetOptLongTest.pl6".IO.e'
> True
>
> $ p6 'say "GetOptLongTest.pl7".IO.e'
> False
>
> $ p6 'say "p6lib".IO.d'
> True
>
> $ p6 'say "p7lib".IO.d'
> Failed to find '/home/linuxutil/p7lib' while trying to do '.d'
>in block  at -e line 1
>
> Notice that it crashed instead of returning a False.
>
> This gets a single :'(
>
>  AAHH 
>


Re: question on pod comments

2020-05-30 Thread Kevin Pye
They're not Pod comments, they're Pod abbreviated blocks:

https://docs.raku.org/language/pod

Kevin.

On Sun, 31 May 2020 at 12:43, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> I am somewhat confused about pod comments:
>
> https://docs.raku.org/language/syntax#Pod_comments
>
> Seems pretty straight forward.  But when I look at
>
> https://github.com/tadzik/perl6-Config-INI/blob/master/lib/Config/INI.pm
>
> starting line 45, I see
>
> =begin pod
> =head1 NAME
> =head1 SYNOPSIS
> =head1 DESCRIPTION
> =end pod
>
> I see no "=end xxx"
>
> =end head1 NAME
> =end head1 SYNOPSIS
> =end head1 DESCRIPTION
>
> What am I missing?
>
> Many thanks,
> -T
>


Re: question on pod comments

2020-05-30 Thread Kevin Pye
As I said, they're abbreviated blocks. Keep reading.

On Sun, 31 May 2020 at 13:30, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Sun, 31 May 2020 at 12:43, ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> I am somewhat confused about pod comments:
> >>
> >> https://docs.raku.org/language/syntax#Pod_comments
> >>
> >> Seems pretty straight forward.  But when I look at
> >>
> >>
> https://github.com/tadzik/perl6-Config-INI/blob/master/lib/Config/INI.pm
> >>
> >> starting line 45, I see
> >>
> >> =begin pod
> >> =head1 NAME
> >> =head1 SYNOPSIS
> >> =head1 DESCRIPTION
> >> =end pod
> >>
> >> I see no "=end xxx"
> >>
> >> =end head1 NAME
> >> =end head1 SYNOPSIS
> >> =end head1 DESCRIPTION
> >>
> >> What am I missing?
> >>
> >> Many thanks,
> >> -T
> >>
>
> On 2020-05-30 20:20, Kevin Pye wrote:
> > They're not Pod comments, they're Pod abbreviated blocks:
> >
> > https://docs.raku.org/language/pod
> >
> > Kevin.
> >
>
> I see that:
>
> https://docs.raku.org/language/pod#Delimited_blocks
>   =begin head1
>   Top Level Heading
>   =end head1
>
> So back to my original question, where are the "=end " for
> the other blocks?
>
> I am confused.
> -T
>


Re: question on pod comments

2020-05-30 Thread Kevin Pye
While the original documentation you were referring to called them Pod
comments, that's not really accurate. The full documentation (to which I
referred you) calls them "Pod documents" which is much more descriptive.
The Pod document is parsed by Rakudo, and the contents can be used. Pod
documents are structured, and need to be consistent. Unless you do
something to explicitly refer to the pod, it is ignored by the running
program, and is a comment in that sense.

To further confuse you, Pod documents can contain comments in a couple of
ways.

Note that the documentation at docs.raku.org is written in Pod (in this
case in files containing no normal raku code).

On Sun, 31 May 2020 at 13:50, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Sun, 31 May 2020 at 13:30, ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >>  >> On Sun, 31 May 2020 at 12:43, ToddAndMargo via perl6-users
> >>  >> mailto:perl6-us...@perl.org>
> >> <mailto:perl6-us...@perl.org <mailto:perl6-us...@perl.org>>> wrote:
> >>  >>
> >>  >> Hi All,
> >>  >>
> >>  >> I am somewhat confused about pod comments:
> >>  >>
> >>  >> https://docs.raku.org/language/syntax#Pod_comments
> >>  >>
> >>  >> Seems pretty straight forward.  But when I look at
> >>  >>
> >>  >>
> >>
> https://github.com/tadzik/perl6-Config-INI/blob/master/lib/Config/INI.pm
> >>  >>
> >>  >> starting line 45, I see
> >>  >>
> >>  >> =begin pod
> >>  >> =head1 NAME
> >>  >> =head1 SYNOPSIS
> >>  >> =head1 DESCRIPTION
> >>  >> =end pod
> >>  >>
> >>  >> I see no "=end xxx"
> >>  >>
> >>  >> =end head1 NAME
> >>  >> =end head1 SYNOPSIS
> >>  >> =end head1 DESCRIPTION
> >>  >>
> >>  >> What am I missing?
> >>  >>
> >>  >> Many thanks,
> >>  >> -T
> >>  >>
> >>
> >> On 2020-05-30 20:20, Kevin Pye wrote:
> >>  > They're not Pod comments, they're Pod abbreviated blocks:
> >>  >
> >>  > https://docs.raku.org/language/pod
> >>  >
> >>  > Kevin.
> >>  >
> >>
> >> I see that:
> >>
> >> https://docs.raku.org/language/pod#Delimited_blocks
> >>=begin head1
> >>Top Level Heading
> >>=end head1
> >>
> >> So back to my original question, where are the "=end " for
> >> the other blocks?
> >>
> >> I am confused.
> >> -T
> >>
>
> On 2020-05-30 20:37, Kevin Pye wrote:
> > As I said, they're abbreviated blocks. Keep reading.
> >
>
>
> https://docs.raku.org/language/pod#Abbreviated_blocks
> Abbreviated blocks
>
> Abbreviated blocks begin by an '=' sign, which is followed immediately
> by the typename of the block. All following data are part of the
> contents of the block, thus configuration data cannot be specified for
> an abbreviated block. The block ends at the next Pod6 directive or the
> first blank line.
>
> =head1 Top level heading
>
>
> So basically, since they did not contain a "begin",
> `=begin `, they do not use and `=end ` and
> the terminate themselves after the first blank line.
>
> Do I FINALLY have it down?
>
> Also, in
>
> https://github.com/tadzik/perl6-Config-INI/blob/master/lib/Config/INI.pm
>
> since these Abbreviated Block were inside his
>
> =begin pod
> =end pod
>
> He was just being fancy since they would have no
> effect anyway as they were inside a comment already?
>
> -T
>


Re: for and ^ question

2020-12-31 Thread Kevin Pye
>
> ^ note: ^3 means the integer "just before" 3  (zero is presume to be the
> start point)
>
>   3^ means the integer "just after" 3  (an ending point is
> required)
>

No, it does not. Go back and read what Brad wrote; he was quite explicit.

Nothing about the range 0 ..^ 3 (for which "^3" is just a short-cut) says
anything about integers. It is the range of numbers (real numbers if you
like) ranging from 0 to 3, but excluding 3. In standard mathematical
notation that would be "[0,3)". If you iterate over the range then you
start with the beginning of the range and keep adding one until you reach
the end (in this case ignoring the final value if it is equal to the
end-point).

If the range were 0.5 .. 3 then the iterated values would be 0.5, 1.5 and
2.5.

On Fri, 1 Jan 2021 at 16:32, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 12/30/20 5:39 PM, ToddAndMargo via perl6-users wrote:
> > Hi All,
> >
> > In the following for loop:
> >
> >  for ^$nCount -> $i {
> >
> > What is the ^ doing?
> >
> > Confused again,
> > -T
>
> With wonderful explanations for many others, my notes:
>
>
> ^ note: ^3 means the integer "just before" 3  (zero is presume to be the
> start point)
>
>   3^ means the integer "just after" 3  (an ending point is
> required)
>
>
> Looping using an integer (avoids having to use a C loop):
>
> # loop to "just before" $x starting at 0 by 1
> > my $x=3; for ^$x -> $i { print "i = $i\n"; }
> i = 0
> i = 1
> i = 2
>
> # loop from 3 to 5 by 1
> > for 3..5 -> $i { print "i = $i\n"; }
> i = 3
> i = 4
> i = 5
>
> # loop from 3 to "just before" 6 by 1
> > for 3..^6 -> $i { print "i = $i\n"; }
> i = 3
> i = 4
> i = 5
>
> # loop from "just after" 3 to 6 by 1
> > for 3^..6 -> $i { print "i = $i\n"; }
> i = 4
> i = 5
> i = 6
>
> # loop from "just after" 3 to "just before" 7 by 1
> > for 3^..^7 -> $i { print "i = $i\n"; }
> i = 4
> i = 5
> i = 6
>
>
>


Re: for and ^ question

2021-01-01 Thread Kevin Pye
 We have established that ^2.1 is a range, meaning all the real numbers
from 0 to 2.1, not including the 2.1.

What do you expect ^2.1 .. 2.5 to mean, That's a range (the "..") from
"^2.1", another range to the number 2.5. You can't have a range starting
with a range, A range is between two numbers. Hence the error message is
quite correct.

There are four infix operators which create ranges: "..", "^..", "..^" and
"^..^"
and the prefix operator "^:"; you're trying to mix two of them.

All of those take numbers as their arguments, not ranges.

Try something like

.say for 2.1 .. 2.5

You can try
.say for 2.1 ^.. 2.5
and then explain the output.

On Fri, 1 Jan 2021 at 18:59, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> ^ note: ^3 means the integer "just before" 3  (zero is presume to
> be the
> >> start point)
> >>
> >>3^ means the integer "just after" 3  (an ending point is
> >> required)
> >>
> >>
>
> On 12/31/20 10:15 PM, Kevin Pye wrote:
> > No, it does not. Go back and read what Brad wrote; he was quite explicit.
> >
> > Nothing about the range 0 ..^ 3 (for which "^3" is just a short-cut)
> > says anything about integers. It is the range of numbers (real numbers
> > if you like) ranging from 0 to 3, but excluding 3. In standard
> > mathematical notation that would be "[0,3)". If you iterate over the
> > range then you start with the beginning of the range and keep adding one
> > until you reach the end (in this case ignoring the final value if it is
> > equal to the end-point).
> >
> > If the range were 0.5 .. 3 then the iterated values would be 0.5, 1.5
> > and 2.5.
>
>
> Hi Kevin,
>
> My notes were for "for" loops.
>
> > for ^2 {print "$_\n";}
> 0
> 1
>
>
> I am not able to reproduce your comments:
>
> > for ^2.1..2.5 {print "$_\n";}
> Range objects are not valid endpoints for Ranges
>   in block  at  line 1
>
> > for ^2.1 .. 2.5 {print "$_\n";}
> Range objects are not valid endpoints for Ranges
>   in block  at  line 1
>
> Would you mind throwing me an REPL example?
>
> Many thanks,
> -T
>
>
>


Re: for and ^ question

2021-01-01 Thread Kevin Pye
..^ is an operator. You can't put spaces in the middle of an operator.

On Fri, 1 Jan 2021 at 22:13, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> >> On Fri, 1 Jan 2021 at 18:59, ToddAndMargo via perl6-users
> >> mailto:perl6-us...@perl.org>> wrote:
> >>
> >>  >> ^ note: ^3 means the integer "just before" 3  (zero is
> >> presume to be the
> >>  >> start point)
> >>  >>
> >>  >>3^ means the integer "just after" 3  (an ending
> >> point is
> >>  >> required)
> >>  >>
> >>  >>
> >>
> >> On 12/31/20 10:15 PM, Kevin Pye wrote:
> >>  > No, it does not. Go back and read what Brad wrote; he was quite
> >> explicit.
> >>  >
> >>  > Nothing about the range 0 ..^ 3 (for which "^3" is just a
> short-cut)
> >>  > says anything about integers. It is the range of numbers (real
> >> numbers
> >>  > if you like) ranging from 0 to 3, but excluding 3. In standard
> >>  > mathematical notation that would be "[0,3)". If you iterate over
> the
> >>  > range then you start with the beginning of the range and keep
> >> adding one
> >>  > until you reach the end (in this case ignoring the final value if
> >> it is
> >>  > equal to the end-point).
> >>  >
> >>  > If the range were 0.5 .. 3 then the iterated values would be 0.5,
> >> 1.5
> >>  > and 2.5.
> >>
> >>
> >> Hi Kevin,
> >>
> >> My notes were for "for" loops.
> >>
> >>  > for ^2 {print "$_\n";}
> >>      0
> >>  1
> >>
> >>
> >> I am not able to reproduce your comments:
> >>
> >>  > for ^2.1..2.5 {print "$_\n";}
> >>  Range objects are not valid endpoints for Ranges
> >>in block  at  line 1
> >>
> >>  > for ^2.1 .. 2.5 {print "$_\n";}
> >>  Range objects are not valid endpoints for Ranges
> >>in block  at  line 1
> >>
> >> Would you mind throwing me an REPL example?
> >>
> >> Many thanks,
> >> -T
>
> On 1/1/21 12:39 AM, Kevin Pye wrote:
> >   We have established that ^2.1 is a range, meaning all the real numbers
> > from 0 to 2.1, not including the 2.1.
> >
> > What do you expect ^2.1 .. 2.5 to mean, That's a range (the "..") from
> > "^2.1", another range to the number 2.5. You can't have a range starting
> > with a range, A range is between two numbers. Hence the error message is
> > quite correct.
> >
> > There are four infix operators which create ranges: "..", "^..", "..^"
> > and "^..^"
> > and the prefix operator "^:"; you're trying to mix two of them.
> >
> > All of those take numbers as their arguments, not ranges.
> >
> > Try something like
> >
> > .say for 2.1 .. 2.5
> >
> > You can try
> > .say for 2.1 ^.. 2.5
>
>  > .say for 2.1 .. 2.5
> 2.1
>
>
>  > .say for 2.1 .. ^2.5
> Range objects are not valid endpoints for Ranges
>in block  at  line 1
>
>
> > and then explain the output.
>
> Hi Kevin,
>
> I am trying to get it to work in a "for" loop.
>
> I am doing something wrong.
>
> Would you mind sending me the proper syntax
> for this from REPL?
>
> -T
>
>
>
>
>


Re: 'CALL-ME' Math problem?

2021-03-02 Thread Kevin Pye
Just because mathematics allows an implied multiplication doesn't mean Raku
does -- in fact I can't think of any programming language which does. You
need to stick an explicit multiplication operator ('*' or '×') between the
5 and the left parenthesis.

The reason for the error message is that adding parentheses after something
is interpreted as trying to invoke a function. Callable objects such as
functions have a CALL-ME method which is what is invoked to call the
function. An integer lacks such a method, since it isn't callable.

On Tue, 2 Mar 2021 at 19:13, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

>
> Hi All,
>
> Math problem:
>  x = 60÷5(7−5)
>
> raku -e 'say 60÷5(7−5)'
> No such method 'CALL-ME' for invocant of type 'Int'
>in block  at -e line 1
>
> Seems raku does not like the ().  How do I fix this
> and maintain the flow and look of the equation?
>
> -T
>
> The correct answer is 24
>
>
>


Re: ftp client yet?

2021-10-21 Thread Kevin Pye
Both modules.raku.org and raku.land know about the Net::FTP module, but it 
appears to be rather limited and may not do what you want.

Why not just use the Perl Net::FTP?

Kevin.

On Fri, 22 Oct 2021, at 15:48, Henrik Peng wrote:
> perhaps not from what I had searched for.
> 
> On Fri, Oct 22, 2021 at 11:43 AM ToddAndMargo via perl6-users 
>  wrote:
>> Hi All,
>> 
>> I have a program in Perl 5 that uses Perl 5's ftp
>> client. I would dearly love to port it to Raku,
>> which is much easier to maintain.
>> 
>> Do we have a working ftp module yet?
>> 
>> Many thanks,
>> -T

Re: ftp client yet?

2021-10-21 Thread Kevin Pye
You can still use the Perl 5 module from Raku without writing any Perl code. It 
should allow a fairly seamless update to a usable Raku module when one becomes 
available.

On Fri, 22 Oct 2021, at 16:18, ToddAndMargo via perl6-users wrote:
> On 10/21/21 22:03, Kevin Pye wrote:
>> Both modules.raku.org and raku.land know about the Net::FTP module, but 
>> it appears to be rather limited and may not do what you want.
>> 
>> Why not just use the Perl Net::FTP?
>
> I use that in Perl 5.  I am trying to divorce
> myself of Perl 5.


Re: ftp client yet?

2021-10-22 Thread Kevin Pye
https://raku.land/cpan:NINE/Inline::Perl5

On Fri, 22 Oct 2021, at 18:44, ToddAndMargo via perl6-users wrote:
>> On Fri, 22 Oct 2021, at 16:18, ToddAndMargo via perl6-users wrote:
>>> On 10/21/21 22:03, Kevin Pye wrote:
>>>> Both modules.raku.org and raku.land know about the Net::FTP module, but
>>>> it appears to be rather limited and may not do what you want.
>>>>
>>>> Why not just use the Perl Net::FTP?
>>>
>>> I use that in Perl 5.  I am trying to divorce
>>> myself of Perl 5.
>
> On 10/21/21 23:48, Kevin Pye wrote:
>  > You can still use the Perl 5 module from Raku without writing any 
> Perl code. It should allow a fairly seamless update to a usable Raku 
> module when one becomes available.
>  >
>
> If I have to, then a hybrid solution.  Can you
> point me to a paper on how to do that?
>
>
> -- 
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~


Re: I need a better regex with a literal in it

2021-10-23 Thread Kevin Pye
Assuming that all you are trying to do is to delete everything at the start
of a line up to and including that string, the first thing I would do is
get rid of all the superfluous parts of the regex.

Does
$NewRev ~~ s/ .* 'Release Notes V' //
have the problem?

".*" means any number of characters, including zero; thus the "?" is
superfluous.
The parentheses simply capture the data that is matched, Since the string
is constant, there is not much use capturing it, and I doubt you are using
the captured value (available as $0).

Kevin.

On Sun, 24 Oct 2021 at 10:44, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> Hi All,
>
> Wish I had a Q[;;;] expression inside a regex, but I don't
>
> This is my notes on how to do a regex with a special
> characters in it:
>
>   Regex with literals in it:
>  $JsonAddr ~~ s| (';') .* ||;
>
> It "usually" works.
>
>
> Unfortunately this one hangs my program (I am slicing
> up a web page):
>
> $NewRev ~~ s/ .*? ('Release Notes V') //;
>
> I need a better way of doing the above.
>
> Many thanks,
> -T
>
>
>


Re: how do I turn a real into and array of Integers?

2021-10-31 Thread Kevin Pye
You don't.

sqrt is a function which acts on 64-bit floating point numbers, and there's no 
more meaningful digits available. If you need more precision you're on your own.

On Mon, 1 Nov 2021, at 11:20, ToddAndMargo via perl6-users wrote:
> On 10/31/21 16:42, ToddAndMargo via perl6-users wrote:
>> On 10/31/21 11:20, Sean McAfee wrote:
>>> On Sun, Oct 31, 2021 at 9:08 AM Andinus via perl6-users 
>>> mailto:perl6-us...@perl.org>> wrote:
>>>
>>>      put 2.sqrt.comb.grep(*.Int)>>.Int[^10].raku # 10 digits
>>>
>>>
>>> comb takes an argument that can save you a method call:
>>>
>>>  2.sqrt.comb.grep(*.Int)
>>>    ==>
>>>  2.sqrt.comb(/\d/)
>>>
>> 
>> 
>> 
>>  > 2.sqrt.comb(/\d/)
>> (1 4 1 4 2 1 3 5 6 2 3 7 3 0 9 5 1)
>> 
>> 
>>  > 2.sqrt.comb(/\d/)
>> (1 4 1 4 2 1 3 5 6 2 3 7 3 0 9 5 1)
>> 
>> 
>> 
>> :-)
>
>
> How do I get more digits out of sqrt?


Re: What is `Γäó`?

2022-07-01 Thread Kevin Pye
You need a Unicode terminal.

It's a trademark symbol.

(And the bit following "Raku" on the next line is a "registered mark" symbol.)

Kevin.

On Sat, 2 Jul 2022, at 09:34, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> Windows 10 Pro - 21H2
> RakudoMoar-2022.06.01-win-x86_64-msvc.msi
>
>  > raku -v
> Welcome to RakudoΓäó v2022.06.
> Implementing the Raku® Programming Language v6.d.
> Built on MoarVM version 2022.06.
>
> What is `Γäó`?
>
> Inquiring minds want to know.
>
> -T
>
> -- 
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~


Problems with defining a class

2022-08-23 Thread Kevin Pye
Hi,

The following fairly simple code works well:

   class A {
 has num $!a is required is built;
};

  dd A.new(a => 1e0);

producing "A.new(a => 1e0)".

However, if we make a slight change:

   class A {
 has num $!a is required is built;
};

  dd A.new(a => 0e0);

(i.e. initialising to 0 instead of 1), we get

   The attribute '$!a' is required, but you did not provide a value for it. 
   in block  at test.raku line 5

Any value except 0 seems to work fine.

Am I doing something stupid, or is this a problem with rakudo?

Kevin.

Re: Problems with defining a class

2022-08-23 Thread Kevin Pye
That makes some reasonable sense. I guess "is required" and native attributes 
are more-or-less incompatible.

Kevin.

On Wed, 24 Aug 2022, at 12:45, William Michels via perl6-users wrote:
> It seems to work okay if I change `num` to `Num`:
>
> class A {
>  has Num $!a is required is built;
> };
>
>   dd A.new(a => 0e0);
>
>
> #returns:
>
> A.new(a => 0e0)
>
> Note, I'm on a fairly old version of Rakudo [moar (2021.06).
>
> HTH, Bill.
>
>
> On Tue, Aug 23, 2022 at 6:47 PM Kevin Pye  wrote:
>>
>> Hi,
>>
>> The following fairly simple code works well:
>>
>>class A {
>>  has num $!a is required is built;
>> };
>>
>>   dd A.new(a => 1e0);
>>
>> producing "A.new(a => 1e0)".
>>
>> However, if we make a slight change:
>>
>>class A {
>>  has num $!a is required is built;
>> };
>>
>>   dd A.new(a => 0e0);
>>
>> (i.e. initialising to 0 instead of 1), we get
>>
>>The attribute '$!a' is required, but you did not provide a value for it.
>>in block  at test.raku line 5
>>
>> Any value except 0 seems to work fine.
>>
>> Am I doing something stupid, or is this a problem with rakudo?
>>
>> Kevin.


Re: Test not working so well

2023-12-10 Thread Kevin Pye



On Mon, 11 Dec 2023, at 07:31, ToddAndMargo via perl6-users wrote:

> [0] > my Str $x="abc3defg"; if $x.match( / ^ <[0..9]> ** 8 $ / ) { print 
> "True\n"; } else { print "False\n" };
> False
>
> "3" is in the string.  Why False?

Because you asked for a match with a string consisting entirely of exactly 8 
digits.

> my Str $x="abc3defg"; if $x.match( / ^ <[a..h]> ** 8 $ / ) { print 
> "True\n"; } else { print "False\n" };
> False
>
> a and b and c and d and e and f and g are also in the string.
> Why the false?

Because the string doesn't exist of exactly eight letters in the range a..h. 
I.e. there's a 3 in there which isn't a letter in the range a..h.


Re: Test not working so well

2023-12-10 Thread Kevin Pye



On Mon, 11 Dec 2023, at 09:24, ToddAndMargo via perl6-users wrote:
> On 12/10/23 14:16, Kevin Pye wrote:

>> Because you asked for a match with a string consisting entirely of exactly 8 
>> digits.

> I am not following.  :'(

^beginning of string

<[0..9]> a digit

** 8 repeated exactly eight times

% end of string

so /^ <[0..9]> ** 8 $/ means exactly eight digits in the string, and nothing 
else. You have eight characters, but seven of them aren't digits, so the match 
fails.

Similarly in the second case.


Re: Test not working so well

2023-12-11 Thread Kevin Pye
Seriously Todd? "What is a digit?" The characters '0' to '9' are digits. 
(Unicode probably has a whole lot of others, but those will do for the moment.)

On Mon, 11 Dec 2023, at 18:22, ToddAndMargo via perl6-users wrote:
> On 12/10/23 22:26, William Michels via perl6-users wrote:

> If I do not know the length of the sting and have to ask
> with .chars, is there a way to use a variable in `** 7`
>
>   ** $x.chars   or
>   my $xlen = $x.chars; `** $xlen`
>
> or some such?  Is there a special syntax?
>
> Also, must the `**7`  (does it have a name?) always be the length
> of the string?
>
> Also, if I do not use ^ and $, what happens?

These are really basic questions.

"**7" is a modifier. It means that the previous item must match exactly 7 
times. Just like "+" means "one or more" and "*" means "zero or more". The "7" 
can be a range. Thus "<[0..9]>**1..7" means one to seven digits.

To interpolate code into a regex, use the { raku code } syntax. Perhaps 
"**{$x.chars}" will work. (I'm not sure of that one.) On the other hand, if you 
just want to make sure that everything is a digit, "/ ^ <[0..9]>+ $ /" will 
work fine. Or even simpler "/ ^ \d+ $ /" since "\d" just means "a digit" 
(although you will also get anything else Unicode considers a digit).

If you do not include the '^' and/or '$' characters, then the match may occur 
in the middle (or start or end) of a longer string.


Problem using precompiled Physics::Measure objects

2024-07-30 Thread Kevin Pye
I am trying to build a replacement for the existing Physics::Constants module, 
but running into problems when loading the pre-compiled version. I want to use 
code like:

unit module Physics::Constants;

use Physics::Unit;
use Physics::Measure;

constant \avogadro-constant is export(:DEFAULT, :fundamental, 
:avogadro-constant) = Measure.new(
  value => 6.02214076e+23, 
  error => 0, 
  units => 'mol⁻¹',
);

which compiles and runs quite well. However, when I try to run "mi6 test" which 
will precompile and then load the code, I get the following output:

$ mi6 test
===SORRY!=== Error while compiling 
/home/kevin/git/Physics-Constants/t/01-basic.rakutest
===SORRY!=== Error while compiling 
/home/kevin/git/Physics-Constants/lib/Physics/Constants.rakumod 
(Physics::Constants)
An exception X::Comp::AdHoc occurred while evaluating a constant:
Cannot unbox a P6opaque (NQPMu) type object
at /home/kevin/git/Physics-Constants/lib/Physics/Constants.rakumod 
(Physics::Constants):6
Exception details:
  ===SORRY!=== Error while compiling 
  Cannot unbox a P6opaque (NQPMu) type object
  at line 

at .../Physics-Constants/t/01-basic.rakutest:2
t/01-basic.rakutest .. Dubious, test returned 1
No subtests run

I am guessing that it can't deserialize the serialized Physics::Measure object, 
but I could be quite wrong.

Any ideas on how to make this work?

Thanks,

Kevin.

Re: Problem using precompiled Physics::Measure objects

2024-07-31 Thread Kevin Pye



On Wed, 31 Jul 2024, at 19:20, Elizabeth Mattijsen wrote:
>> On 31 Jul 2024, at 06:10, Kevin Pye  wrote:
>> 
>> I am trying to build a replacement for the existing Physics::Constants 
>> module, but running into problems when loading the pre-compiled version. I 
>> want to use code like:
>> 
>> unit module Physics::Constants;
>> 
>> use Physics::Unit;
>> use Physics::Measure;
>> 
>> constant \avogadro-constant is export(:DEFAULT, :fundamental, 
>> :avogadro-constant) = Measure.new(
>>   value => 6.02214076e+23, 
>>   error => 0, 
>>   units => 'mol⁻¹',
>> );
>> 
>> which compiles and runs quite well. However, when I try to run "mi6 test" 
>> which will precompile and then load the code, I get the following output:
>> 
>> $ mi6 test
>> ===SORRY!=== Error while compiling 
>> /home/kevin/git/Physics-Constants/t/01-basic.rakutest
>> ===SORRY!=== Error while compiling 
>> /home/kevin/git/Physics-Constants/lib/Physics/Constants.rakumod 
>> (Physics::Constants)
>> An exception X::Comp::AdHoc occurred while evaluating a constant:
>> Cannot unbox a P6opaque (NQPMu) type object
>> at /home/kevin/git/Physics-Constants/lib/Physics/Constants.rakumod 
>> (Physics::Constants):6
>> Exception details:
>>   ===SORRY!=== Error while compiling 
>>   Cannot unbox a P6opaque (NQPMu) type object
>>   at line 
>> 
>> at .../Physics-Constants/t/01-basic.rakutest:2
>> t/01-basic.rakutest .. Dubious, test returned 1
>> No subtests run
>> 
>> I am guessing that it can't deserialize the serialized Physics::Measure 
>> object, but I could be quite wrong.
>
> This appears to be an issue with resolving somewhere deep in the 
> bowels.  In RakuAST, the error is slightly more clear:
>
> ===SORRY!===
> Cannot look up attributes in a RakuAST::Resolver type object. Did you 
> forget a '.new'?
>
> I'm pretty sure we won't fix this in the legacy grammar.  I'll be 
> looking at fixing this in RakuAST.  Meanwhile, I would also suggest 
> making this an issue in the Physics::Measure repo 
> https://github.com/librasteve/raku-Physics-Measure so that the author 
> is alerted to this problem, and maybe can figure out what tickles it.

The Physics::Measure author is already aware of the issue.

>
>
>> Any ideas on how to make this work?
>
> Put this in lib/Physics/Constants.rakumod:
> =
> use Physics::Unit;
> use Physics::Measure;
>
> my $avogadro-constant := Measure.new(
>   value => 6.02214076e+23,
>   error => 0,
>   units => 'mol⁻¹',
> );
>
> sub EXPORT {
> Map.new: (:$avogadro-constant)  # must have () to force positional Pair
> }
> =
>
> And then run:
>
> $ raku -Ilib -MConstants -e 'say avogadro-constant'
> 6.02214076e+23mol⁻¹ ±0
>
> In other words: drop the module statement.  The namespace *from* which 
> you export constants, is usually not important.  And use an EXPORT sub 
> (https://docs.raku.org/syntax/sub%20EXPORT) to export whatever values 
> that were created when the mainline of the module runs.
>
> Disadvantages to this approach:
> - you lose the standard capability to selective importing
> - the constants are created at module load time, and not serialized

Unfortunately that won't help much in this case. There are over 300 constants 
planned to be included. Using a separate EXPORT sub decouples the definitions 
and export declarations too much, selective importing will be very useful to 
avoid polluting the namespace of code using the module, and creating hundreds 
of Physics::Measure objects at load time will be simply much too slow. (You 
might get away with it with selective importing and only creating a relatively 
few objects, but without that...)

We'll keep looking at other ways of defining the objects, but thanks anyway. 
(And sorry for increasing the RakuAST work needed.)

Kevin.


Blobs and IEEE floating point

2016-04-18 Thread Kevin Pye
Hi,

I have a several-thousand-line long Perl 5 script which I've been
translating to Perl 6 over some time, and it runs fine, although a little
slowly :-)

There is however one section which I haven't needed to use until recently,
and which I've been avoiding translating because it's not all that easy. It
takes a binary blob out of a database and then unpacks it into various
structures.

This all works now, except that the blob contains several IEEE format
64-bit floating point numbers. The perl 5 code did a simple "unpack 'd',
$buffer", but none of the various pack/unpack implementations I can find
for Perl 6 handle floating point yet.

I can see a couple of possible of possible solutions:

1. Write perl code to rip apart the IEEE format and construct a new Real
which has the same value as the original number; or

2. Write a simple C function to take a pointer to a double and return the
double, put that into a shared library and then use NativeCall.

The first isn't as bad as it looks because the numbers are all of limited
range, and won't contain things like NaN and Inf so a general solution
isn't needed. I'm guessing the second would run more quickly.

Any other ideas?

Kevin.


Re: Blobs and IEEE floating point

2016-04-27 Thread Kevin Pye
Sorry to be so long replying and thanking you for your help -- I've spent
most of the last week in hospital with very limited communications.

Thank you -- lots of interesting information.

I ended up for the moment with something like (retyping from memory)...

method double {
  $!index += 8;
  nativecast((num64), Blob.new(@!bytes[ $index - 8 ..^ $index ] );
}

which (summary to memory errors) is working fine, at least until I try to
run the code on a machine with big-endian floats, when it will require some
reversing of bytes, or a machine without IEEE floating point (do such
machines still exist?) in which case Marcel's code could be very useful. By
then perhaps there will have been consensus and implementation of a
pack/unpack native solution for Perl 6.

Thanks everybody.

On 21 April 2016 at 01:47, mt1957  wrote:

>
> On 19-04-16 10:21, Elizabeth Mattijsen wrote:
>
>> FWIW, I’ll take PR’s for the PackUnpack distribution to make ‘f’ and ‘d’
>> work  :-)
>>
>
> Hi Elizabeth,
>
> For the PackUnpack distro this might come in handy... or might go in the
> examples corner?
>
> Done some experiments and looks well. Please check the attachment for
> encoding/decoding of doubles. decode-double has also an index in the buffer
> to pull out a specific spot in the buffer where the encoded double should
> be. The code is made from snippets from Timo Paulsen and
> David Warren.
>
> You might want to know how much faster it has become. Well it's not that
> much of an improvement, only encoding a double is about 4 times faster.
> The decoding only 1.13 times.
>
> emulated encoded
> 3000 runs total time = 7.211524 s, 0.002404 s per run, 416.000809 runs per
> s
>
> native encoded
> 3000 runs total time = 1.720918 s, 0.000574 s per run, 1743.256109 runs
> per s
>
> emulated decode
> 3000 runs total time = 1.038615 s, 0.000346 s per run, 2888.461538 runs
> per s
>
> native decode
> 3000 runs total time = 0.918133 s, 0.000306 s per run, 3267.498734 runs
> per s
>
>
> Before I pat myself on the back for the 'fast' emulated encode/decode
> already in place in the BSON package the above results might mean that the
> native routines can be done better.
>
> Regards,
> Marcel
>
>
>


Re: Q[] question

2025-01-11 Thread Kevin Pye
On Sun, 12 Jan 2025, at 14:01, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> Is
> Q[...]
>
> the same thing as
> <...>
> ?

No.

Q[…] is the bare quoting construct. There'll be no interpolation of variables, 
no splitting into words, nothing other than creating a bare string.

But Q also takes various adverbs to add all the nice extra available features. 
<…> is the same as Q:w:v[…]. The :w will split the input into words and return 
a list rather than a single string. :v will create allomorphs where possible. 
For example the substring "12" will create an allomorph which can act as either 
the string "12" or the number 12.

The is all explained much better than I can in 
https://docs.raku.org/language/quoting

Kevin.