What is the syntax of a reference pointer in p6?

What is the syntax of a reference pointer in p6?
0
perl6
10/6/2018 6:10:25 AM
perl.perl6.users 1088 articles. 0 followers. Follow

8 Replies
18 Views

Similar Articles

[PageSpeed] 2

--00000000000092c1f505778ba236
Content-Type: text/plain; charset="UTF-8"

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

--00000000000092c1f505778ba236
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">I don&#39;t know exactly what you mean by=
 a reference pointer. If you mean a pointer, there&#39;s no such thing as a=
 pointer, although there is some way to represent pointers in the NativeCal=
l interface (which is properly Rakudo) <a href=3D"https://docs.perl6.org/la=
nguage/traits#index-entry-CPointer">https://docs.perl6.org/language/traits#=
index-entry-CPointer</a>.</div><div>There are no references either, as such=
.. You can bind a variable to another, but there&#39;s no special syntax for=
 that.<br></div><br>-- <br><div dir=3D"ltr" class=3D"gmail_signature" data-=
smartmail=3D"gmail_signature">JJ</div></div>

--00000000000092c1f505778ba236--
0
jjmerelo
10/6/2018 9:01:21 AM
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
0
perl6
10/6/2018 10:16:11 AM
--0000000000000cdc0a05778cbe07
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

El s=C3=A1b., 6 oct. 2018 a las 12:16, ToddAndMargo via perl6-users (<
perl6-users@perl.org>) escribi=C3=B3:

> 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        =3D $_[1];
>        my $WorkingDirectory =3D $_[2];
>        my $CallingFunction  =3D $_[3];
>
>        # Outgoing.  Note: these are reference pointers to
>        #                  the calling variables
>        #                  do not pass constants ("") to them
>
>        my $BaseTagPtr     =3D \$_[0];
>        my $OldRevPtr      =3D \$_[4];  $$OldRevPtr =3D -9999;
>        my $OldFileNamePtr =3D \$_[5];  $$OldFileNamePtr =3D "";
>
> I will be happy if I never have to see a Reference Pointer ever again.
>

I know, I've been using Perl since circa 1993 and pointers since they came
out in Perl 5 (if memory serves). No, we don't have that in Perl 6,
explicitly so.
--=20
JJ

--0000000000000cdc0a05778cbe07
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">El s=
=C3=A1b., 6 oct. 2018 a las 12:16, ToddAndMargo via perl6-users (&lt;<a hre=
f=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt;) escribi=C3=
=B3:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">On 10/6/18 2:01 AM, JJ Merelo =
wrote:<br>
&gt; I don&#39;t know exactly what you mean by a reference pointer. If you =
mean a <br>
&gt; pointer, there&#39;s no such thing as a pointer, although there is som=
e way <br>
&gt; to represent pointers in the NativeCall interface (which is properly <=
br>
&gt; Rakudo) <a href=3D"https://docs.perl6.org/language/traits#index-entry-=
CPointer" rel=3D"noreferrer" target=3D"_blank">https://docs.perl6.org/langu=
age/traits#index-entry-CPointer</a>.<br>
&gt; There are no references either, as such. You can bind a variable to <b=
r>
&gt; another, but there&#39;s no special syntax for that.<br>
&gt; <br>
&gt; -- <br>
&gt; JJ<br>
<br>
Hi JJ,<br>
<br>
This is what they look like in Perl 5:<br>
<br>
sub GetOldRev ( $$$$$$ ) {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0# Incomming:<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my $Extension=C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D $_[=
1];<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my $WorkingDirectory =3D $_[2];<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my $CallingFunction=C2=A0 =3D $_[3];<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0# Outgoing.=C2=A0 Note: these are reference poin=
ters to<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0#=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 the calling variables<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0#=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 do not pass constants (&quot;&quot;) to them<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my $BaseTagPtr=C2=A0 =C2=A0 =C2=A0=3D \$_[0];<br=
>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my $OldRevPtr=C2=A0 =C2=A0 =C2=A0 =3D \$_[4];=C2=
=A0 $$OldRevPtr =3D -9999;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my $OldFileNamePtr =3D \$_[5];=C2=A0 $$OldFileNa=
mePtr =3D &quot;&quot;;<br>
<br>
I will be happy if I never have to see a Reference Pointer ever again.<br c=
lear=3D"all"></blockquote></div><div><br></div><div>I know, I&#39;ve been u=
sing Perl since circa 1993 and pointers since they came out in Perl 5 (if m=
emory serves). No, we don&#39;t have that in Perl 6, explicitly so. <br></d=
iv>-- <br><div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmai=
l_signature">JJ</div></div>

--0000000000000cdc0a05778cbe07--
0
jjmerelo
10/6/2018 10:20:35 AM
On 10/6/18 3:20 AM, JJ Merelo wrote:
> No, we don't have that in Perl 6, explicitly so.

Hi JJ,

Yippee !!!!!  P6 is a wonderful clean up of P5.  I hated
having to send arrays to subroutines as pointers.  What
was Larry thinking !?!?!?  ( He has redeemed himself 1000+
times over with P6.)

-T
0
perl6
10/7/2018 8:28:50 AM
--0000000000004149dd0577a65f64
Content-Type: text/plain; charset="UTF-8"

He was thinking "don't make perl 5 as incompatible with perl 4".
Pass-by-reference objects make for a major change to the language's
behavior; it and its consequences are a large part of why perl 6 is
incompatible with perl 5.

On Sun, Oct 7, 2018 at 4:29 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 10/6/18 3:20 AM, JJ Merelo wrote:
> > No, we don't have that in Perl 6, explicitly so.
>
> Hi JJ,
>
> Yippee !!!!!  P6 is a wonderful clean up of P5.  I hated
> having to send arrays to subroutines as pointers.  What
> was Larry thinking !?!?!?  ( He has redeemed himself 1000+
> times over with P6.)
>
> -T
>


-- 
brandon s allbery kf8nh
allbery.b@gmail.com

--0000000000004149dd0577a65f64
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">He was thinking &quot;don&#39;t make perl 5 as incompatibl=
e with perl 4&quot;. Pass-by-reference objects make for a major change to t=
he language&#39;s behavior; it and its consequences are a large part of why=
 perl 6 is incompatible with perl 5.</div><br><div class=3D"gmail_quote"><d=
iv dir=3D"ltr">On Sun, Oct 7, 2018 at 4:29 AM ToddAndMargo via perl6-users =
&lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wr=
ote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">On 10/6/18 3:20 AM, JJ Merelo =
wrote:<br>
&gt; No, we don&#39;t have that in Perl 6, explicitly so.<br>
<br>
Hi JJ,<br>
<br>
Yippee !!!!!=C2=A0 P6 is a wonderful clean up of P5.=C2=A0 I hated<br>
having to send arrays to subroutines as pointers.=C2=A0 What<br>
was Larry thinking !?!?!?=C2=A0 ( He has redeemed himself 1000+<br>
times over with P6.)<br>
<br>
-T<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"l=
tr"><div><div dir=3D"ltr"><div>brandon s allbery kf8nh</div><div><a href=3D=
"mailto:allbery.b@gmail.com" target=3D"_blank">allbery.b@gmail.com</a></div=
></div></div></div></div>

--0000000000004149dd0577a65f64--
0
allbery
10/7/2018 4:55:18 PM
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
0
b2gills
10/7/2018 7:39:05 PM
On 10/7/18 9:55 AM, Brandon Allbery wrote:
> He was thinking "don't make perl 5 as incompatible with perl 4". 
> Pass-by-reference objects make for a major change to the language's 
> behavior; it and its consequences are a large part of why perl 6 is 
> incompatible with perl 5.

Hi Brandon,

I am glad he finally got around to doing it.  The sub declarations
are miserable in Perl 5, especially for someone who live and dies in
Top Down.

Perl 5 has the reputation of being a "write only" language.  But
that is unfounded.  It only gives you the ability to write poorly.
And virtually any language can give you that ability.  (Harder
in some than others, like Modula2 or Pascal.)

Now what exactly does `//\/\//\///\/\//?//\\` mean?  Yup, I can
maintain that!  No problem!

:-)

-T
0
perl6
10/7/2018 11:46:27 PM
On 10/7/18 12:39 PM, Brad Gilbert wrote:
> 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

Nice explanation. Thank you!

I will stick with `is rw`

-- 
~~~~~~~~~~~~~~~~~~~~~~~~
Yesterday it worked.
Today it is not working.
Windows is like that.
~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
10/8/2018 3:12:26 AM
Reply: