Technically there is a way to reason about some Perl 6 features as pointers.

It would probably complicate it to view it this way though.

You can think about `is raw` as making it so that arguments are passed
by as bare "pointers".

    sub foo ( $a is raw ) {
        $a = 42;
    }

    my $b = 0;
    foo( $b );
    say $b; # 42

    foo( 1 ) # error: Cannot assign to an immutable value

Note that even that isn't quite the same as pointers in other languages.

You can also check what type of thing it points to

    sub bar ( $a is raw ) {
        if $a.VAR.WHAT =:= Scalar {
            $a = 42; # only change it if it is changeable
        }
    }

`is rw` is very similar to `is raw`, except it only accepts things
that can change.

---

Note that the default read only "view" of the arguments can also be
thought of as passing a pointer.

It's just a pointer that you can't do pointery things to.

So it doesn't (really) make a performance difference to use `is rw` or `is raw`.

(Technically there is a tiny speed-up to using `is raw`, but it should
go away once the code gets JITted.
So don't use `is raw` to get a performance boost.)
On Sat, Oct 6, 2018 at 5:16 AM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> On 10/6/18 2:01 AM, JJ Merelo wrote:
> > I don't know exactly what you mean by a reference pointer. If you mean a
> > pointer, there's no such thing as a pointer, although there is some way
> > to represent pointers in the NativeCall interface (which is properly
> > Rakudo) https://docs.perl6.org/language/traits#index-entry-CPointer.
> > There are no references either, as such. You can bind a variable to
> > another, but there's no special syntax for that.
> >
> > --
> > JJ
>
> Hi JJ,
>
> This is what they look like in Perl 5:
>
> sub GetOldRev ( $$$$$$ ) {
>        # Incomming:
>        my $Extension        = $_[1];
>        my $WorkingDirectory = $_[2];
>        my $CallingFunction  = $_[3];
>
>        # Outgoing.  Note: these are reference pointers to
>        #                  the calling variables
>        #                  do not pass constants ("") to them
>
>        my $BaseTagPtr     = \$_[0];
>        my $OldRevPtr      = \$_[4];  $$OldRevPtr = -9999;
>        my $OldFileNamePtr = \$_[5];  $$OldFileNamePtr = "";
>
> I will be happy if I never have to see a Reference Pointer ever again.
>
> -T

Reply via email to