Re: for and ^ question

2020-12-31 Thread ToddAndMargo via perl6-users

^ 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

2020-12-31 Thread ToddAndMargo via perl6-users

^ 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,

I am glad to be wrong!

I am going to have to play with REPL a bunch.
I will write back my new notes.

Thank you!

-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-users@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

2020-12-31 Thread ToddAndMargo via perl6-users

On 12/31/20 1:56 PM, Brad Gilbert wrote:

just before


Hi Brad,

Believe it or not, things fell into place with
just those two word from your letter.  Excellent!

-T


Re: for and ^ question

2020-12-31 Thread ToddAndMargo via perl6-users

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

2020-12-31 Thread ToddAndMargo via perl6-users

On 12/31/20 1:56 PM, Brad Gilbert wrote:
It does not look like an array from 0 to ($nCount - 1). It only iterates 
like that.


It is a Range object from 0 to $nCount excluding $nCount.

     ^9 === Range.new( 0, 9, :excludes-max ) # True
     0 ~~ ^9 # True
     1 ~~ ^9 # True
     0.5 ~~ ^9 # True
     8 ~~ ^9 # True
     8.9 ~~ ^9 # True

     9 ~~ ^9 # False

In the case of `for ^9 {…}` it iterates starting at 0, and continuing to 
just before 9.


It does that because `for` iterates the Range object.

It does NOT store any values other than the min, max and either excludes.

An array would store the values in the middle. Which would be a waste of 
memory.

Which is why it does not do that.

On Wed, Dec 30, 2020 at 8:09 PM ToddAndMargo via perl6-users 
mailto:perl6-users@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

Used in context, the ^ makes the integer $nCount look
like an array of 0 to ($nCount - 1).  Am I missing
something?

my $x=4;
for ^$x -> $i { print "i = $i\n"; }

i = 0
i = 1
i = 2
i = 3




Thank you!



Re: for and ^ question

2020-12-31 Thread ToddAndMargo via perl6-users

On 12/31/20 7:44 AM, William Michels via perl6-users wrote:

There's an open Github issue on the interaction between Seqs and carets:

https://github.com/rakudo/rakudo/issues/3881

Scroll down to the section entitled, "EDIT 08/29/2020 -- TL;DR
Version" for the crux of the issue.


> 8 ... ^16   # now I want 8 elements--get 24 instead, WAT? :
(8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)

Yikes!



Re: for and ^ question

2020-12-31 Thread Brad Gilbert
It does not look like an array from 0 to ($nCount - 1). It only iterates
like that.

It is a Range object from 0 to $nCount excluding $nCount.

^9 === Range.new( 0, 9, :excludes-max ) # True
0 ~~ ^9 # True
1 ~~ ^9 # True
0.5 ~~ ^9 # True
8 ~~ ^9 # True
8.9 ~~ ^9 # True

9 ~~ ^9 # False

In the case of `for ^9 {…}` it iterates starting at 0, and continuing to
just before 9.

It does that because `for` iterates the Range object.

It does NOT store any values other than the min, max and either excludes.

An array would store the values in the middle. Which would be a waste of
memory.
Which is why it does not do that.

On Wed, Dec 30, 2020 at 8:09 PM ToddAndMargo via perl6-users <
perl6-users@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
>
> Used in context, the ^ makes the integer $nCount look
> like an array of 0 to ($nCount - 1).  Am I missing
> something?
>
> my $x=4;
> for ^$x -> $i { print "i = $i\n"; }
>
> i = 0
> i = 1
> i = 2
> i = 3
>
>


Re: for and ^ question

2020-12-31 Thread Andy Bach
> try out these
3 .. 7
3 ..^ 7
3 ^.. 7
3 ^..^ 7

Is the last one called the kitten or the bat operator? ;->

Happy New Year to all those for whom the year ends tonight. For the rest Happy 
Tomorrow!

From: yary 
Sent: Wednesday, December 30, 2020 9:06 PM
To: ToddAndMargo 
Cc: perl6-users 
Subject: Re: for and ^ question

CAUTION - EXTERNAL:

Look up ..^ which is the long form of ^ when used in ^8 sort of thing

https://docs.raku.org/routine/..$CIRCUMFLEX_ACCENT

"Constructs a Range from the arguments, 
excluding the end point."

try out these
3 .. 7
3 ..^ 7
3 ^.. 7
3 ^..^ 7

and also see
https://docs.raku.org/routine/...html
https://docs.raku.org/routine/$CIRCUMFLEX_ACCENT...html
https://docs.raku.org/routine/$CIRCUMFLEX_ACCENT..$CIRCUMFLEX_ACCENT





-y


On Wed, Dec 30, 2020 at 9:42 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:
On 12/30/20 6:04 PM, Curt Tilmes wrote:
> On Wed, Dec 30, 2020 at 8:40 PM ToddAndMargo via perl6-users
> mailto:perl6-users@perl.org>> wrote:
>> In the following for loop:
>>
>>   for ^$nCount -> $i {
>>
>> What is the ^ doing?
>
> https://docs.raku.org/type/Range   About the third paragraph from the top:
>
> The caret is also a prefix operator for constructing numeric ranges
> starting from zero:
>  my $x = 10;
>  say ^$x; # same as 0 ..^ $x.Numeric
>

Thank you!

In a for look, it looks like 0 through 9.  Is that
the for loops doing?

CAUTION - EXTERNAL EMAIL: This email originated outside the Judiciary. Exercise 
caution when opening attachments or clicking on links.



Re: for and ^ question

2020-12-31 Thread William Michels via perl6-users
On Wed, Dec 30, 2020 at 7:20 PM ToddAndMargo via perl6-users
 wrote:
>
> On 12/30/20 7:06 PM, yary wrote:
> > Look up ..^ which is the long form of ^ when used in ^8 sort of thing
> >
> > https://docs.raku.org/routine/..$CIRCUMFLEX_ACCENT
> > 
> >
> > "Constructs a Range  from the
> > arguments, excluding the end point."
> >
> > try out these
> > 3 .. 7
> > 3 ..^ 7
> > 3 ^.. 7
> > 3 ^..^ 7
>
> Hi Yary,
>
> You have got to love Raku!   Thank you!
>
> -T
>
>  > $x=4; for 3..7 -> $i { print "i = $i\n"; }
> i = 3
> i = 4
> i = 5
> i = 6
> i = 7
>
>  > $x=4; for 3..^7 -> $i { print "i = $i\n"; }
> i = 3
> i = 4
> i = 5
> i = 6
>
>  > $x=4; for 3^..7 -> $i { print "i = $i\n"; }
> i = 4
> i = 5
> i = 6
> i = 7
>
>  > $x=4; for 3^..^7 -> $i { print "i = $i\n"; }
> i = 4
> i = 5
> i = 6
>

Hi Todd (and Yary, and Curt),

There's an open Github issue on the interaction between Seqs and carets:

https://github.com/rakudo/rakudo/issues/3881

Scroll down to the section entitled, "EDIT 08/29/2020 -- TL;DR
Version" for the crux of the issue.

And please feel free to comment on Github!

Best, Bill.