bug in REPL and REPL comment Was: Re: bug in REPL

2022-11-25 Thread rir
On Thu, Nov 24, 2022 at 08:55:05PM -0800, ToddAndMargo via perl6-users wrote:
> Fedora 36
> rakudo-pkg-2022.7.0-03.x86_64
> 
> 
> > use NativeCall
> 
> > $j =6; $k = CArray[uint8].new(0xFF xx $j ); print $j ~ "\n";
> Cannot find method 'qast' on object of type NQPMu
> 
> 
> REPL does not like the $j.

This works for me when I add a couple of 'my's for $j and $k.  So it
seems a bug to me.  Environment details follow signature.

My usual plaint with the REPL is just that it is a REPL and so cannot
always behave like the compiler unless it gets an entire program in one
Read and has not polluted the Eval with state saved from a prior Loop.
Which is what makes it great for snippets; but allows the occasional
false failure.

Maybe worse is that it helps me be bad-lazy about typing ';'.


➜  ~ raku -v
Welcome to Rakudo™ v2022.03.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2022.03.
➜  ~ uname -a
Linux shrew 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 
GNU/Linux



Rakudo CoreDev Class

2022-11-25 Thread Vadim Belman
Since no other proposals were made I plan to hold the class on Saturday, Dec 3, 
20:00UTC. Here is the link to Google Calendar entry with Jitsy Meet reference:

https://calendar.google.com/calendar/event?action=TEMPLATE&tmeid=MGdpYWNpZGNmdHMxZHYzNnA5bGJhdG5qc2IgdnJ1cmcwMUBt&tmsrc=vrurg01%40gmail.com

Comments are welcome on:

- Reddit: 
https://www.reddit.com/r/rakulang/comments/z4qsnh/rakudo_coredev_class_announcement/
- Facebook: 
https://www.facebook.com/groups/raku.perl6/permalink/3371142626485406/

Best regards,
Vadim Belman



What does this line mean?

2022-11-25 Thread ToddAndMargo via perl6-users

Hi All,


I am confused!


sub blob-from-pointer(Pointer:D \ptr, Int :$elems!, Blob:U :$type = Buf) 
is export {


What is `Pointer:D \ptr`?

Why the `\`?


What is `:$elems!`?

Why the `:`?

Why the `!`?


What is `Blob:U :$type = Buf`

What does `Blob:U` mean?

What does `:type` mean?

Is `$type` being assigned the type of `Buf`


:'(


Yours in confusion,
-T


Re: What does this line mean?

2022-11-25 Thread Bruce Gray


> On Nov 25, 2022, at 9:21 PM, ToddAndMargo via perl6-users 
>  wrote:
> Hi All,
> I am confused!

The documentation at https://github.com/salortiz/NativeHelpers-Blob would 
certainly benefit from example code!
No examples in the t/ directory use the `blob-from-pointer` sub.

The main doc for NativeCall,
 https://docs.raku.org/language/nativecall#Buffers_and_blobs
, *does* contain a single example, but it uses a too-clever-to-be-helpful 
shortcut for a named argument, so I will rephrase it as:
my $esponja = blob-from-pointer( $inter, elems => 2, type => Blob[int8] );
or:
my $esponja = blob-from-pointer( $inter, :elems(2), :type(Blob[int8]) );


> sub blob-from-pointer(Pointer:D \ptr, Int :$elems!, Blob:U :$type = Buf) is 
> export {
> 
> What is `Pointer:D \ptr`?
> Why the `\`?

Defining a variable with a backslash-where-the-sigil-should-go creates a 
"sigilless variable":
https://docs.raku.org/language/variables#Sigilless_variables
The original coder's choice to use this should not be relevant to the caller, 
and the distinction is not mentioned in the docs at

https://github.com/salortiz/NativeHelpers-Blob#sub-blob-from-pointerpointerd-int-elems-blobu-type--buf
 ,
which document the sub as:
sub blob-from-pointer(Pointer:D, Int :$elems!, Blob:U :$type = Buf)
You can ignore the confusing backslash; just be sure to pass an defined object 
of type Pointer (or a sub-class of Pointer).

> What is `:$elems!`?
> Why the `:`?
> Why the `!`?

The colon is the standard way to define a *named* parameter.
https://docs.raku.org/type/Signature#Positional_vs._named_arguments
Named params default to being optional, and the exclamation point changes the 
parameter to be required.
This is an unusual choice for the API (since it could have been specified as 3 
positional parameters), but this API forces more "clues to the reader" to be 
embedded in each call, providing more clarity in a problem domain prone to 
pitfalls.

> What is `Blob:U :$type = Buf`
> What does `Blob:U` mean?

:D means "Must be defined"
:U means "Must be undefined"
:_ means "can be defined or undefined" and is the default.

SomeObjectType:U means that the parameter must be undefined, and be of the type 
SomeObjectType, or a *subclass* of SomeObjectType.
That part of the API looks *very* weird (Why pass a undefined value???), until 
we observe that Blob and Buf have *sized* subclasses via parameterized role!


> What does `:type` mean?

You are missing the `$` in that question.
`:$type` means that the caller can pass this datum in a named argument style, 
like `type => SomeTypename` or `:type(SomeTypename)`,
and the called sub will receive the argument in the `$type` variable.
In other words, it is a *named* parameter like the mandatory `:$elems` above, 
but `:$type` is optional.

> Is `$type` being assigned the type of `Buf`

The equals-sign in a Parameter list defines a default value. `$type` gets 
assigned the undefined-but-still-useful type-object of `Buf` only if no `type` 
argument is passed.


So, a real-life call might look like:
my $q = blob-from-pointer( $p, elems => 10, type => Blob[uint8] );


> :'(
> 
> Yours in confusion,
> -T

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks)