Re: What is the syntax of a reference pointer in p6?
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 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 = -; 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.
Re: What is the syntax of a reference pointer in p6?
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
Re: What is the syntax of a reference pointer in p6?
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 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 = -; >my $OldFileNamePtr = \$_[5]; $$OldFileNamePtr = ""; > > I will be happy if I never have to see a Reference Pointer ever again. > > -T
Re: What is the syntax of a reference pointer in p6?
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 allber...@gmail.com
Re: What is the syntax of a reference pointer in p6?
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
Re: What is the syntax of a reference pointer in p6?
El sáb., 6 oct. 2018 a las 12:16, ToddAndMargo via perl6-users (< perl6-users@perl.org>) escribió: > 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 = -; >my $OldFileNamePtr = \$_[5]; $$OldFileNamePtr = ""; > > 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. -- JJ
Re: What is the syntax of a reference pointer in p6?
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 = -; my $OldFileNamePtr = \$_[5]; $$OldFileNamePtr = ""; I will be happy if I never have to see a Reference Pointer ever again. -T
Re: What is the syntax of a reference pointer in p6?
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