### Re: how do I do this index in p6?

```Of course, you can also use Math::Constants

use Math::Constants;

say "We are flying at speed ", .1c;

--
JJ

```

### Re: how do I do this index in p6?

```On Thu, Sep 13, 2018 at 11:52 PM Todd Chester  wrote:
>
> >> Le jeu. 13 sept. 2018 à 23:12, ToddAndMargo  >> > a écrit :
> >>
> >
> >> \$ p6 'constant c=299792458; say c ~" metres per second";'
> >> 299792458 metres per second
> >>
> >> Hm. Now I am wondering how to format the
> >> commas into the say.
> >>
>
>
>
> On 09/13/2018 02:43 PM, Laurent Rosenfeld wrote:
> > Not very pretty, but this works:
> >
> > constant c = 299792458;
> > say c.flip.subst(/(\d**3)/, {"\$0,"}, :g).flip.subst(/^\,/, "");
> >
>
> Oh Dude!

It's simpler to use comb and join

constant c = 299792458;
say c.flip.comb(3).join(',').flip;

```

### Re: how do I do this index in p6?

```Le jeu. 13 sept. 2018 à 23:12, ToddAndMargo > a écrit :

\$ p6 'constant c=299792458; say c ~" metres per second";'
299792458 metres per second

Hm. Now I am wondering how to format the
commas into the say.

On 09/13/2018 02:43 PM, Laurent Rosenfeld wrote:

Not very pretty, but this works:

constant c = 299792458;
say c.flip.subst(/(\d**3)/, {"\$0,"}, :g).flip.subst(/^\,/, "");

Oh Dude!

```

### Re: how do I do this index in p6?

```
On 09/13/2018 12:10 PM, Parrot Raiser wrote:

https://docs.perl6.org/language/terms#Identifier_terms

On 9/13/18, ToddAndMargo  wrote:

On 09/12/2018 07:14 AM, Parrot Raiser wrote:

Built-in constants:
pi, tau, e, i

Do you know where I can find the list ?

https://duckduckgo.com/?q=perl6+built+in+constants=ffab=web

is no help

Thank you!

What ??? What ??? No Universal Constant?  Next I will
find that there is no Gravitational Constant either!
Kids these days!

:-)

\$ p6 'constant c=299792458; say c ~" metres per second";'
299792458 metres per second

Hm. Now I am wondering how to format the
commas into the say.

```

### Re: how do I do this index in p6?

```https://docs.perl6.org/language/terms#Identifier_terms

On 9/13/18, ToddAndMargo  wrote:
> On 09/12/2018 07:14 AM, Parrot Raiser wrote:
>> Built-in constants:
>> pi, tau, e, i
>
> Do you know where I can find the list ?
>
>  https://duckduckgo.com/?q=perl6+built+in+constants=ffab=web
>
> is no help
>

```

### Re: how do I do this index in p6?

```
On 09/12/2018 07:14 AM, Parrot Raiser wrote:

Built-in constants:
pi, tau, e, i

Do you know where I can find the list ?

https://duckduckgo.com/?q=perl6+built+in+constants=ffab=web

is no help

```

### Re: how do I do this index in p6?

```Neat. The answer's round about right.

On 9/12/18, Fernando Santagata  wrote:
> Patched :-)
> say (e**(i*pi)+1).round(10⁻¹²)
>
> On Wed, Sep 12, 2018 at 4:28 PM Parrot Raiser <1parr...@gmail.com> wrote:
>
>> Just for giggles, say e**(i*pi) + 1 prints 0+1.2246467991473532e-16i
>> which isn't exactly right, but close enough for government work.
>>  (You could call it really right, the error is imaginary. :-)* )
>>
>>
>> On 9/12/18, Parrot Raiser <1parr...@gmail.com> wrote:
>> > Built-in constants:
>> > pi, tau, e, i
>> >
>> > perl6 -e  'say pi ~ "  " ~ tau ~ "   " ~ e ~ "  " ~ i';
>> >
>> > 3.141592653589793  6.283185307179586  2.718281828459045  0+1i
>> > (tau is 2pi, useful if you want to calculate the circumference of your
>> > tuits.
>> > Pi and tau can also be accessed as the Unicode characters.
>> >
>> > User-defined
>> > constant answer = 42;
>> >
>> > Scope is lexical:
>> > constant where = "outer";
>> > say where; {
>> > constant where = "inner";
>> > say where;
>> > }
>> > say where;
>> >
>>
>
>
> --
> Fernando Santagata
>

```

### Re: how do I do this index in p6?

```Patched :-)
say (e**(i*pi)+1).round(10⁻¹²)

On Wed, Sep 12, 2018 at 4:28 PM Parrot Raiser <1parr...@gmail.com> wrote:

> Just for giggles, say e**(i*pi) + 1 prints 0+1.2246467991473532e-16i
> which isn't exactly right, but close enough for government work.
>  (You could call it really right, the error is imaginary. :-)* )
>
>
> On 9/12/18, Parrot Raiser <1parr...@gmail.com> wrote:
> > Built-in constants:
> > pi, tau, e, i
> >
> > perl6 -e  'say pi ~ "  " ~ tau ~ "   " ~ e ~ "  " ~ i';
> >
> > 3.141592653589793  6.283185307179586  2.718281828459045  0+1i
> > (tau is 2pi, useful if you want to calculate the circumference of your
> > tuits.
> > Pi and tau can also be accessed as the Unicode characters.
> >
> > User-defined
> > constant answer = 42;
> >
> > Scope is lexical:
> > constant where = "outer";
> > say where; {
> > constant where = "inner";
> > say where;
> > }
> > say where;
> >
>

--
Fernando Santagata

```

### Re: how do I do this index in p6?

```Just for giggles, say e**(i*pi) + 1 prints 0+1.2246467991473532e-16i
which isn't exactly right, but close enough for government work.
(You could call it really right, the error is imaginary. :-)* )

On 9/12/18, Parrot Raiser <1parr...@gmail.com> wrote:
> Built-in constants:
> pi, tau, e, i
>
> perl6 -e  'say pi ~ "  " ~ tau ~ "   " ~ e ~ "  " ~ i';
>
> 3.141592653589793  6.283185307179586  2.718281828459045  0+1i
> (tau is 2pi, useful if you want to calculate the circumference of your
> tuits.
> Pi and tau can also be accessed as the Unicode characters.
>
> User-defined
>
> Scope is lexical:
> constant where = "outer";
> say where; {
> constant where = "inner";
> say where;
> }
> say where;
>

```

### Re: how do I do this index in p6?

```Built-in constants:
pi, tau, e, i

perl6 -e  'say pi ~ "  " ~ tau ~ "   " ~ e ~ "  " ~ i';

3.141592653589793  6.283185307179586  2.718281828459045  0+1i
(tau is 2pi, useful if you want to calculate the circumference of your tuits.
Pi and tau can also be accessed as the Unicode characters.

User-defined

Scope is lexical:
constant where = "outer";
say where; {
constant where = "inner";
say where;
}
say where;

```

### Re: how do I do this index in p6?

```
On 09/11/2018 07:08 PM, Vadim Belman wrote:

Of course constants!

constant ACONST = pi;
constant \$SCONST = "aaa";

Even

constant @a = [1,2,3];

though it doesn't affect the actual array content making '@a = []'
possible due to the way '=' works in the array context. But

constant @a = <1 2 3>;

works as expected. I could leave it as a homework for you to find out why!  A
tip which you wouldn't find in the documentation: '=' in array context does
element-by-element assign to the left hand array.

11 вер. 2018 р. о 20:17 ToddAndMargo  написав(ла):

On 09/11/2018 08:11 AM, yary wrote:

"Nil... it's a constant, so you have to use =:= to check for equality."

Constants?  I thought we did not have constants!  Am I mixing
Perl 5 with Perl 6, again?

Best regards,

G   Foiled by Perl 5 again!

\$ p6 'constant Pi= 3.1415; say Pi.perl;'
3.1415

\$ p6 'constant Pi= "3.1415"; say Pi.perl;'
"3.1415"

\$ p6 'constant Pi= "3.1415"; say "<" ~ Pi ~">";'
<3.1415>

\$ p6 'constant Pi= "3.1415"; say Pi / 2;'
1.57075

\$ p6 'constant Pi= "3.1415"; say "Pi";'
Pi

\$ p6 'constant Pi= "3.1415"; say Pi;'
3.1415

Thank you!

-T

--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~

```

### Re: how do I do this index in p6?

```Of course constants!

constant ACONST = pi;
constant \$SCONST = "aaa";

Even

constant @a = [1,2,3];

though it doesn't affect the actual array content making '@a = []'
possible due to the way '=' works in the array context. But

constant @a = <1 2 3>;

works as expected. I could leave it as a homework for you to find out why!  A
tip which you wouldn't find in the documentation: '=' in array context does
element-by-element assign to the left hand array.

> 11 вер. 2018 р. о 20:17 ToddAndMargo  написав(ла):
>
> On 09/11/2018 08:11 AM, yary wrote:
>> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Constants?  I thought we did not have constants!  Am I mixing
> Perl 5 with Perl 6, again?
>

Best regards,

```

### Re: how do I do this index in p6?

```
On 09/11/2018 08:11 AM, yary wrote:

"Nil... it's a constant, so you have to use =:= to check for equality."

Constants?  I thought we did not have constants!  Am I mixing
Perl 5 with Perl 6, again?

```

### Re: how do I do this index in p6?

```Oh, I guess Timo suggested .defined.  I should relearn to read, now that
I can see again...

Larry

```

### Re: how do I do this index in p6?

```On Tue, Sep 11, 2018 at 02:42:20AM -0700, ToddAndMargo wrote:
: How do I clean this up for use with Perl 6?
:
: \$ perl -E 'say index("abc", "z") == -1 ? "False" : "True"'
: False

I'm a little bit surprised nobody suggested the most basic method:

say index("abc", "z").defined ?? "True" !! "False"

Larry

```

### Re: how do I do this index in p6?

```"with"...

with 'apple'.index('a') { say "Found at position \$_" } else { "Not here" }

# Found at position 0

with 'apple'.index('b') { say "Found at position \$_" } else { "Not here" }

# Not here

-y

On Tue, Sep 11, 2018 at 8:16 AM, Timo Paulssen  wrote:

> On 11/09/18 17:11, yary wrote:
>
> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Can you elaborate on that requirement? == works for an equality checks
> with numeric constants- must be more than Nil's constant-ness that makes
> one use =:= - perhaps that Nil doesn't numify to anything?
>
>
> Nil does numify, but using == comparison for this is still problematic for
> two reasons:
>
> 1) Nil numifies to 0, which is a valid "true" result for the index method
> and
> 2) it outputs a warning:
>
> Use of Nil in numeric context
>   in block  at -e line 1
>
> using ~~ instead of =:= should also be okay, or checking for definedness
> with either .defined or using "with" instead of "if", which is very useful
> especially for index and friends.
>
> HTH
>   - Timo
>

```

### Re: how do I do this index in p6?

```On 11/09/18 17:11, yary wrote:
> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Can you elaborate on that requirement? == works for an equality checks
> with numeric constants- must be more than Nil's constant-ness that
> makes one use =:= - perhaps that Nil doesn't numify to anything?

Nil does numify, but using == comparison for this is still problematic
for two reasons:

1) Nil numifies to 0, which is a valid "true" result for the index
method and
2) it outputs a warning:

Use of Nil in numeric context
in block  at -e line 1

using ~~ instead of =:= should also be okay, or checking for definedness
with either .defined or using "with" instead of "if", which is very
useful especially for index and friends.

HTH
- Timo

```

### Re: how do I do this index in p6?

```El mar., 11 sept. 2018 a las 17:12, yary () escribió:

> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Can you elaborate on that requirement? == works for an equality checks
> with numeric constants- must be more than Nil's constant-ness that makes
> one use =:= - perhaps that Nil doesn't numify to anything?
>

That's correct. It yields an error when you try to numify it.

Cheers

JJ

--
JJ

```

### Re: how do I do this index in p6?

```"Nil... it's a constant, so you have to use =:= to check for equality."

Can you elaborate on that requirement? == works for an equality checks with
numeric constants- must be more than Nil's constant-ness that makes one use
=:= - perhaps that Nil doesn't numify to anything?

```

### Re: how do I do this index in p6?

```
On 09/11/2018 02:57 AM, JJ Merelo wrote:

perl6 -e 'say "abc".index("z") =:= Nil  ?? "False" !! "True"'

-e runs the script from the CL
https://github.com/rakudo/rakudo/wiki/Running-rakudo-from-the-command-line

"abc" is on front (but it could be in the same way)
index return Nil if it does not found (more logical than -1)
https://docs.perl6.org/routine/index; it's a constant, so you have to
use =:= to check for equality. https://docs.perl6.org/routine/=:=
??!! is the ternary operator in Perl 6
https://docs.perl6.org/language/operators#index-entry-operator_ternary-ternary_operator

JJ
PS: ObStackOverflow plug.

Thank you!  And thank you for the home work!  I am slowly
learning.

```

### Re: how do I do this index in p6?

```
On 09/11/2018 03:11 AM, Simon Proctor wrote:

Why not use contains though?

Because I am torturing myself.  I am trying to learn what
all this does.

I love contains, start-with, and ends with.  I need
to learn this other stuff too.

```

### Re: how do I do this index in p6?

```Why not use contains though?

perl6 -e 'say "abc".contains("z")'
False

Use index if the index is important. Use contains if you just want to know
if it's there.

On Tue, 11 Sep 2018 at 10:57 JJ Merelo  wrote:

> perl6 -e 'say "abc".index("z") =:= Nil  ?? "False" !! "True"'
>
> -e runs the script from the CL
> https://github.com/rakudo/rakudo/wiki/Running-rakudo-from-the-command-line
> "abc" is on front (but it could be in the same way)
> index return Nil if it does not found (more logical than -1)
> https://docs.perl6.org/routine/index; it's a constant, so you have to use
> =:= to check for equality. https://docs.perl6.org/routine/=:=
> ??!! is the ternary operator in Perl 6
> https://docs.perl6.org/language/operators#index-entry-operator_ternary-ternary_operator
>
>
> JJ
> PS: ObStackOverflow plug.
>
--
Simon Proctor
Cognoscite aliquid novum cotidie

```

### Re: how do I do this index in p6?

```perl6 -e 'say "abc".index("z") =:= Nil  ?? "False" !! "True"'

-e runs the script from the CL
https://github.com/rakudo/rakudo/wiki/Running-rakudo-from-the-command-line
"abc" is on front (but it could be in the same way)
index return Nil if it does not found (more logical than -1)
https://docs.perl6.org/routine/index; it's a constant, so you have to use
=:= to check for equality. https://docs.perl6.org/routine/=:=
??!! is the ternary operator in Perl 6
https://docs.perl6.org/language/operators#index-entry-operator_ternary-ternary_operator

JJ
PS: ObStackOverflow plug.

```

### how do I do this index in p6?

```
Hi All,

How do I clean this up for use with Perl 6?

\$ perl -E 'say index("abc", "z") == -1 ? "False" : "True"'
False

Many thanks,
-T

--

Yesterday it worked.
Today it is not working.
Windows is like that.

```