Re: I need help testing for Nil

2020-05-26 Thread ToddAndMargo via perl6-users

On 2020-05-26 16:29, Brad Gilbert wrote:

There are various equality operators.

「==」 Tests for numeric equality
「eq」 Tests for string equality
「===」 Tests for value identity
「=:=」 Tests for pointer equality (Note that it looks a bit like 「:=」)
「eqv」 Tests for structure equivalence.

The 「==」 and 「eq」 operators are special because they force their values 
to be numbers or strings before they do anything else.


Thank you!  Wrote it down.


Re: I need help testing for Nil

2020-05-26 Thread Brad Gilbert
There are various equality operators.

「==」 Tests for numeric equality
「eq」 Tests for string equality
「===」 Tests for value identity
「=:=」 Tests for pointer equality (Note that it looks a bit like 「:=」)
「eqv」 Tests for structure equivalence.

The 「==」 and 「eq」 operators are special because they force their values to
be numbers or strings before they do anything else.

There are similarly a variety of comparison operators.

On Tue, May 26, 2020 at 5:06 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Tue, May 26, 2020 at 4:24 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> How do I turn this:
> >>
> >> $ raku -e 'my $x="abc"; say $x.index( "q" );'
> >> Nil
> >>
> >> into a test?
> >>
> >> $ raku -e 'my $x="abc"; if $x.index( "q" ) eq Nil {say
> "Nil"}else{say
> >> "Exists";}'
> >> Use of Nil in string context
> >> in block  at -e line 1
> >> Use of Nil in string context
> >> in block  at -e line 1
> >> Nil
> >>
> >>
> >>     Many thanks,
> >> -T
> >>
>
> On 2020-05-26 15:00, Brad Gilbert wrote:
> > Generally you don't need to test for 「Nil」.
> > You can just test for defined-ness.
>
> True enough
>
> >
> >  $ raku -e 'my $x="abc"; with $x.index( "q" ) {say "Exists"} else
> > {say "Nil";}'
> >
> > Also 「Nil」 is not a 「Str」, so why would you use 「eq」?
>
> Because == did not work
>
>
> >  $ raku -e 'Nil.Str'
> >  Use of Nil in string context
> >
> > If you really need to check specifically for 「Nil」 (which you probably
> > don't), then you can use 「===」.
> >
> >  for Str, Int, Nil {
> >  say 'Nil' if $_ === Nil;
> >  }
> >
> > The 「//」 operator can also be useful to deal with undefined values such
> > as 「Nil」.
> >
> >  my $x = 'abc';
> >  say $x.index('q') // 'cannot find the index of 「q」';
> >
> >
>
> Hi Brad,
>
> Did not know about the triple =
>
> Thank you!
>
> -T
>
>
> $ raku -e 'my $x="abc"; if $x.index( "q" ) === Nil {say "Nil"}else{say
> "Exists";}'
> Nil
>
> $ raku -e 'my $x="abc"; if $x.index( "a" ) === Nil {say "Nil"}else{say
> "Exists";}'
> Exists
>
> And I found buried in my Nil notes that `=:=` works too
>
> $ raku -e 'my $x="abc"; if $x.index( "q" ) =:= Nil {say "Nil"}else{say
> "Exists";}'
> Nil
>
> $ raku -e 'my $x="abc"; if $x.index( "b" ) =:= Nil {say "Nil"}else{say
> "Exists";}'
> Exists
>


Re: I need help testing for Nil

2020-05-26 Thread ToddAndMargo via perl6-users
On Tue, May 26, 2020 at 4:24 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Hi All,

How do I turn this:

$ raku -e 'my $x="abc"; say $x.index( "q" );'
Nil

into a test?

$ raku -e 'my $x="abc"; if $x.index( "q" ) eq Nil {say "Nil"}else{say
"Exists";}'
Use of Nil in string context
in block  at -e line 1
    Use of Nil in string context
in block  at -e line 1
Nil


Many thanks,
-T



On 2020-05-26 15:00, Brad Gilbert wrote:

Generally you don't need to test for 「Nil」.
You can just test for defined-ness.


True enough



     $ raku -e 'my $x="abc"; with $x.index( "q" ) {say "Exists"} else 
{say "Nil";}'


Also 「Nil」 is not a 「Str」, so why would you use 「eq」?


Because == did not work



     $ raku -e 'Nil.Str'
     Use of Nil in string context

If you really need to check specifically for 「Nil」 (which you probably 
don't), then you can use 「===」.


     for Str, Int, Nil {
         say 'Nil' if $_ === Nil;
     }

The 「//」 operator can also be useful to deal with undefined values such 
as 「Nil」.


     my $x = 'abc';
     say $x.index('q') // 'cannot find the index of 「q」';




Hi Brad,

Did not know about the triple =

Thank you!

-T


$ raku -e 'my $x="abc"; if $x.index( "q" ) === Nil {say "Nil"}else{say 
"Exists";}'

Nil

$ raku -e 'my $x="abc"; if $x.index( "a" ) === Nil {say "Nil"}else{say 
"Exists";}'

Exists

And I found buried in my Nil notes that `=:=` works too

$ raku -e 'my $x="abc"; if $x.index( "q" ) =:= Nil {say "Nil"}else{say 
"Exists";}'

Nil

$ raku -e 'my $x="abc"; if $x.index( "b" ) =:= Nil {say "Nil"}else{say 
"Exists";}'

Exists


Re: I need help testing for Nil

2020-05-26 Thread Brad Gilbert
Generally you don't need to test for 「Nil」.
You can just test for defined-ness.

$ raku -e 'my $x="abc"; with $x.index( "q" ) {say "Exists"} else {say
"Nil";}'

Also 「Nil」 is not a 「Str」, so why would you use 「eq」?

$ raku -e 'Nil.Str'
Use of Nil in string context

If you really need to check specifically for 「Nil」 (which you probably
don't), then you can use 「===」.

for Str, Int, Nil {
say 'Nil' if $_ === Nil;
}

The 「//」 operator can also be useful to deal with undefined values such as
「Nil」.

my $x = 'abc';
say $x.index('q') // 'cannot find the index of 「q」';


On Tue, May 26, 2020 at 4:24 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> How do I turn this:
>
> $ raku -e 'my $x="abc"; say $x.index( "q" );'
> Nil
>
> into a test?
>
> $ raku -e 'my $x="abc"; if $x.index( "q" ) eq Nil {say "Nil"}else{say
> "Exists";}'
> Use of Nil in string context
>in block  at -e line 1
> Use of Nil in string context
>in block  at -e line 1
> Nil
>
>
> Many thanks,
> -T
>


I need help testing for Nil

2020-05-26 Thread ToddAndMargo via perl6-users

Hi All,

How do I turn this:

$ raku -e 'my $x="abc"; say $x.index( "q" );'
Nil

into a test?

$ raku -e 'my $x="abc"; if $x.index( "q" ) eq Nil {say "Nil"}else{say 
"Exists";}'

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


Many thanks,
-T


Re: Different return values with "say" vs "put" (Nil representation... )

2020-05-18 Thread William Michels via perl6-users
On Mon, May 18, 2020 at 10:18 AM Brad Gilbert  wrote:
>
> You are misunderstanding what `put` does.
>
> It does not print the internal representation.
>
> What it does do is turn the value into a `Str` object, then print it with a 
> trailing newline.
>
> It just so happens that objects will by default return something that looks 
> like an internal representation when you coerce it to a `Str`.
>
> class Point {
> has ($.x, $.y);
> }
> put Point.new( x => 1, y => 2 ).Str
> # Point<94102525076384>
>
> put Point.new( x => 1, y => 2 ).gist
> # Point.new(x => 1, y => 2)
>
> put Point.new( x => 1, y => 2 ).raku
> # Point.new(x => 1, y => 2)
>
> Unless they have a `.Str` method that returns something more sensible.
>
> class Point {
> has ($.x, $.y);
> method Str () {
> "[$!x,$!y]"
> }
> }
> put Point.new( x => 1, y => 2 ).Str
> # [1,2]
>
> put Point.new( x => 1, y => 2 ).gist
> # Point.new(x => 1, y => 2)
>
> put Point.new( x => 1, y => 2 ).raku
> # Point.new(x => 1, y => 2)
>
> Note that the default of `.gist` is do the same thing as calling `.raku`.
> (Many/Most built-in objects have a `.gist` method that returns something 
> different.)
>
> ---
>
> `s///` and `S///` are both intended as working on `Str` objects. So when you 
> give them something that is not a `Str`, they turn it into a `Str` first.
> Actually all operations that are `Str` operations will turn it into a `Str` 
> first.
> Like `.starts-with`, `.ends-with`, `.chars`, `.codes`, `.index`, `.substr`, 
> `print`, and `put`
>
> What `say` does, is that instead of calling `.Str` it calls `.gist`
>
> `.gist` is defined as giving enough information for a human to be able to 
> figure out what object was printed.
> (Which is why the default is to return the same thing as `.raku` for defined 
> objects)
>
> Actually almost all operations are intended for one type of object, and will 
> coerce to that type.
>
> > say ['a', 'b', 'c']   +   %( d => 10, e => 20 )
> 5
>
> ---
>
> Many objects will throw an error if you call `.Str` on them when they are 
> undefined.
>
> > Bool.Str
> Use of uninitialized value of type Bool in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to 
> something meaningful.
>   in block  at  line 1
>
> > Nil.Str
> Use of Nil in string context
>   in block  at  line 1
>
> Which means they also throw an error if you try to use one of the methods 
> intended for `Str` objects on them.
>
> > Bool.substr(0,1)
> Use of uninitialized value of type Bool in string context.
> Methods .^name, .raku, .gist, or .say can be used to stringify it to 
> something meaningful.
>   in block  at  line 1
>
> > Bool.^name.substr(0,1)
> B
>
> The reason for it generating an error is that generally when you try to turn 
> an undefined object into a Str, there is likely a bug somewhere.
>
> ---
>
> Since `.gist` is for a human, it doesn't matter if the returned value is a 
> little wrong, so it doesn't fail.
> (A human can notice if something is wrong. A program that only does what you 
> told it to, generally doesn't.)
>
> > Bool.gist
> (Bool)
>
> Note that the reason it puts ( and ) around the name of the object is so that 
> you know that you might have a problem somewhere in your code.
>
> ---
>
> Further, Nil is actually the most basic of the Failure objects.
>
> > for Failure.^mro { say .^name }
> Failure
> Nil
> Cool
> Any
> Mu
>
> If you get a Nil, there is probably some sort of failure somewhere.
>
> > say ( 1, 2, 3, 4 ).first( 'one' )
> Nil
>
> Which means that if you try to use a Nil as a Str, there is definitely a bug 
> in your code.
>

Thank you very much, Brad. --Bill.


Re: Different return values with "say" vs "put" (Nil representation... )

2020-05-18 Thread William Michels via perl6-users
On Mon, May 18, 2020 at 4:03 AM Patrick R. Michaud  wrote:
>
> "say $x" is essentially equivalent to "put $x.gist".
>
> Since Nil is undefined (roughly equivalent to a type object), Nil.gist has a 
> string value of "Nil" and can be printed.  However, attempting to convert Nil 
> directly into a Str throws an error because that's attempting to stringify an 
> undefined object.
>
> You can see this with the following:
>
> $ rakudo
> To exit type 'exit' or '^D'
> > say Nil
> Nil
> > put Nil
> Use of Nil in string context
>   in block  at  line 1
> > say Nil.Str
> Use of Nil in string context
>   in block  at  line 1
> > put Nil.gist
> Nil
>
> So, the difference in your example is that when the result of s/.../.../ is 
> Nil (representing a failed Match), C calls .gist on Nil which produces a 
> printable string, while C attempts to stringify the Nil object directly 
> and that throws an error.
>
> Pm
>

Thank you very much, Patrick. --Bill.


Re: Different return values with "say" vs "put" (Nil representation... )

2020-05-18 Thread Brad Gilbert
You are misunderstanding what `put` does.

It does not print the internal representation.

What it does do is turn the value into a `Str` object, then print it with a
trailing newline.

It just so happens that objects will by default return something that looks
like an internal representation when you coerce it to a `Str`.

class Point {
has ($.x, $.y);
}
put Point.new( x => 1, y => 2 ).Str
# Point<94102525076384>

put Point.new( x => 1, y => 2 ).gist
# Point.new(x => 1, y => 2)

put Point.new( x => 1, y => 2 ).raku
# Point.new(x => 1, y => 2)

Unless they have a `.Str` method that returns something more sensible.

class Point {
has ($.x, $.y);
method Str () {
"[$!x,$!y]"
}
}
put Point.new( x => 1, y => 2 ).Str
# [1,2]

put Point.new( x => 1, y => 2 ).gist
# Point.new(x => 1, y => 2)

put Point.new( x => 1, y => 2 ).raku
# Point.new(x => 1, y => 2)

Note that the default of `.gist` is do the same thing as calling `.raku`.
(Many/Most built-in objects have a `.gist` method that returns something
different.)

---

`s///` and `S///` are both intended as working on `Str` objects. So when
you give them something that is not a `Str`, they turn it into a `Str`
first.
Actually all operations that are `Str` operations will turn it into a `Str`
first.
Like `.starts-with`, `.ends-with`, `.chars`, `.codes`, `.index`, `.substr`,
`print`, and `put`

What `say` does, is that instead of calling `.Str` it calls `.gist`

`.gist` is defined as giving enough information for a human to be able to
figure out what object was printed.
(Which is why the default is to return the same thing as `.raku` for
defined objects)

Actually almost all operations are intended for one type of object, and
will coerce to that type.

> say ['a', 'b', 'c']   +   %( d => 10, e => 20 )
5

---

Many objects will throw an error if you call `.Str` on them when they are
undefined.

> Bool.Str
Use of uninitialized value of type Bool in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to
something meaningful.
  in block  at  line 1

> Nil.Str
Use of Nil in string context
  in block  at  line 1

Which means they also throw an error if you try to use one of the methods
intended for `Str` objects on them.

> Bool.substr(0,1)
Use of uninitialized value of type Bool in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to
something meaningful.
  in block  at  line 1

> Bool.^name.substr(0,1)
B

The reason for it generating an error is that generally when you try to
turn an undefined object into a Str, there is likely a bug somewhere.

---

Since `.gist` is for a human, it doesn't matter if the returned value is a
little wrong, so it doesn't fail.
(A human can notice if something is wrong. A program that only does what
you told it to, generally doesn't.)

> Bool.gist
(Bool)

Note that the reason it puts ( and ) around the name of the object is so
that you know that you might have a problem somewhere in your code.

---

Further, Nil is actually the most basic of the Failure objects.

> for Failure.^mro { say .^name }
Failure
Nil
Cool
Any
Mu

If you get a Nil, there is probably some sort of failure somewhere.

> say ( 1, 2, 3, 4 ).first( 'one' )
Nil

Which means that if you try to use a Nil as a Str, there is definitely a
bug in your code.

On Mon, May 18, 2020 at 2:00 AM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Hello,
>
> I'm interested in knowing the differences between the return values
> when "say" is used compared to "put". My understanding is that "put"
> returns Raku's internal representation of a value held by a variable,
> while "say" is merely "put" with the .gist method called on it (a
> "human readable", often-abbreviated return value).
>
> Below I do "S///" (non-destructive) and "s///" (destructive) text
> replacement on a three line text file in bash line [1]. In bash line
> [2], the full substituted text file is correctly returned; in bash
> line [3] using "say" only the $/ match string is returned. So far so
> good. However, a virtually-identical call in bash line [4] using "put"
> instead of "say" returns an error for the first line of the target
> text file: "Use of Nil in string context in block  at -e line 1".
>
> [1] homedir$ cat demo1.txt
> this is a test,
> I love Unix,
> I like Linux too,
>
> [2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt
> this is a test,
> I admire Unix,
> I admire Linux too,
>
> [3] homedir$ perl6 -ne

Re: Different return values with "say" vs "put" (Nil representation... )

2020-05-18 Thread Patrick R. Michaud
"say $x" is essentially equivalent to "put $x.gist".

Since Nil is undefined (roughly equivalent to a type object), Nil.gist has a 
string value of "Nil" and can be printed.  However, attempting to convert Nil 
directly into a Str throws an error because that's attempting to stringify an 
undefined object.

You can see this with the following:

$ rakudo
To exit type 'exit' or '^D'
    > say Nil
    Nil
> put Nil
Use of Nil in string context
  in block  at  line 1
> say Nil.Str
Use of Nil in string context
  in block  at  line 1
> put Nil.gist
Nil

So, the difference in your example is that when the result of s/.../.../ is Nil 
(representing a failed Match), C calls .gist on Nil which produces a 
printable string, while C attempts to stringify the Nil object directly 
and that throws an error.

Pm

On Sun, May 17, 2020 at 11:59:18PM -0700, William Michels via perl6-users wrote:
> Hello,
> 
> I'm interested in knowing the differences between the return values
> when "say" is used compared to "put". My understanding is that "put"
> returns Raku's internal representation of a value held by a variable,
> while "say" is merely "put" with the .gist method called on it (a
> "human readable", often-abbreviated return value).
> 
> Below I do "S///" (non-destructive) and "s///" (destructive) text
> replacement on a three line text file in bash line [1]. In bash line
> [2], the full substituted text file is correctly returned; in bash
> line [3] using "say" only the $/ match string is returned. So far so
> good. However, a virtually-identical call in bash line [4] using "put"
> instead of "say" returns an error for the first line of the target
> text file: "Use of Nil in string context in block  at -e line 1".
> 
> [1] homedir$ cat demo1.txt
> this is a test,
> I love Unix,
> I like Linux too,
> 
> [2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt
> this is a test,
> I admire Unix,
> I admire Linux too,
> 
> [3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt
> Nil
> 「love」
> 「like」
> 
> [4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt
> Use of Nil in string context
>   in block  at -e line 1
> 
> love
> like
> 
> [5] homedir$
> 
> I'm really trying to understand this error message:  doesn't Raku know
> that this is a text replacement operation? How can a 'Nil' be
> correctly represented when called by "say", but throw an error when
> called by "put"? If the value is absent at the Raku representational
> level and throws an error, wouldn't it be reasonable to assume that
> the same case would hold for "say"? And finally, does this "say / put"
> difference mean that some textual information will be lost from return
> values (because "say" will have to be used instead of "put" to avoid
> errorring-out)?
> 
> Any enlightenment appreciated,
> 
> TIA, Bill.


Different return values with "say" vs "put" (Nil representation... )

2020-05-18 Thread William Michels via perl6-users
Hello,

I'm interested in knowing the differences between the return values
when "say" is used compared to "put". My understanding is that "put"
returns Raku's internal representation of a value held by a variable,
while "say" is merely "put" with the .gist method called on it (a
"human readable", often-abbreviated return value).

Below I do "S///" (non-destructive) and "s///" (destructive) text
replacement on a three line text file in bash line [1]. In bash line
[2], the full substituted text file is correctly returned; in bash
line [3] using "say" only the $/ match string is returned. So far so
good. However, a virtually-identical call in bash line [4] using "put"
instead of "say" returns an error for the first line of the target
text file: "Use of Nil in string context in block  at -e line 1".

[1] homedir$ cat demo1.txt
this is a test,
I love Unix,
I like Linux too,

[2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt
this is a test,
I admire Unix,
I admire Linux too,

[3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt
Nil
「love」
「like」

[4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt
Use of Nil in string context
  in block  at -e line 1

love
like

[5] homedir$

I'm really trying to understand this error message:  doesn't Raku know
that this is a text replacement operation? How can a 'Nil' be
correctly represented when called by "say", but throw an error when
called by "put"? If the value is absent at the Raku representational
level and throws an error, wouldn't it be reasonable to assume that
the same case would hold for "say"? And finally, does this "say / put"
difference mean that some textual information will be lost from return
values (because "say" will have to be used instead of "put" to avoid
errorring-out)?

Any enlightenment appreciated,

TIA, Bill.


Re: Nil ?

2018-09-13 Thread Todd Chester




On 09/13/2018 02:24 PM, Elizabeth Mattijsen wrote:

On 13 Sep 2018, at 23:21, ToddAndMargo  wrote:



$ p6 'my $x="\na\nb\nc\n"; for ( split "\n", $x ) -> $i {print "<$i>\n"};'
<>



<>

with beginning and ending new lines.


FWIW, a more Perl6ish way would be:

$ p6 'my $x="\na\nb\nc\n"; for $x.lines -> $i {print "<$i>\n"};'



That is pretty looking.  Thank you!


Re: Nil ?

2018-09-13 Thread Elizabeth Mattijsen
> On 13 Sep 2018, at 23:21, ToddAndMargo  wrote:
> On 09/13/2018 12:29 PM, Elizabeth Mattijsen wrote:
>>> On 13 Sep 2018, at 20:47, ToddAndMargo  wrote:
>>> On 09/12/2018 10:09 AM, Larry Wall wrote:
>>>> Basically, ignore any advice to treat Nil as a normal value, because
>>>> it really is intended to represent the *absence* of a value as much as
>>>> possible.  It's a bit like the way solid-state electronics treats "holes"
>>>> as if they were real particles, and gets away with it much of the time.
>>>> But not all the time, because the hole isn't real; it's the collective
>>>> behavior of everything around a thing that's missing.
>>>> So while you can test explicitly for Nil if you try hard enough, it's
>>>> better not to try at all, because lots of places internally are using
>>>> that Nil to select some kind of default behavior that might or might
>>>> not look like Nil afterwards.
>>>> It was probably a mistake to put Nil into the type hierarchy underneath
>>>> the Any type in the first place.  It's more of a concept type like
>>>> Junction, so probably belongs outside of Any, which sits the top of the
>>>> "normal" object hierarchy.
>>>> These types are deeply magical.  Whenever you find yourself trying to
>>>> use Nil or Junction as a normal value, you have to ask yourself whether
>>>> you're just Mickey Mouse falling into the Sorcerer's Apprentice trap.
>>>> Unless you're a wizard, with Nil and Junction it's better to cargo cult
>>>> a few common usages and stay the heck away the rest of the time.
>>>> Larry
>>> 
>>> Hi Larry,
>>> 
>>> Beautiful description!  Almost magical!  :-)
>>> 
>>> I will stick with .defined that you suggested in another
>>> thread.
>> Another way to deal with Nil is to use “with”, especially if you don’t need 
>> to do anything if the value is Nil:
>> with “foo”.index(“o”) -> $index {
>> say “Found at index $index”;
>> }
>> Documentation: 
>> https://docs.perl6.org/language/control#index-entry-control_flow_with_orwith_without-with%2C_orwith%2C_without
> 
> Where I typically have to deal with Nil's is when I
> am looping through something I read back from a system
> call.  I never thought much of it when I was using bash,
> but when you see the raw stuff ...
> 
> Not a Nil, but things read back and looped with split
> can be interesting too.
> 
> $ p6 'my $x="\na\nb\nc\n"; for ( split "\n", $x ) -> $i {print "<$i>\n"};'
> <>
> 
> 
> 
> <>
> 
> with beginning and ending new lines.

FWIW, a more Perl6ish way would be:

$ p6 'my $x="\na\nb\nc\n"; for $x.lines -> $i {print "<$i>\n"};'


Re: Nil ?

2018-09-12 Thread Larry Wall
Basically, ignore any advice to treat Nil as a normal value, because
it really is intended to represent the *absence* of a value as much as
possible.  It's a bit like the way solid-state electronics treats "holes"
as if they were real particles, and gets away with it much of the time.
But not all the time, because the hole isn't real; it's the collective
behavior of everything around a thing that's missing.

So while you can test explicitly for Nil if you try hard enough, it's
better not to try at all, because lots of places internally are using
that Nil to select some kind of default behavior that might or might
not look like Nil afterwards.

It was probably a mistake to put Nil into the type hierarchy underneath
the Any type in the first place.  It's more of a concept type like
Junction, so probably belongs outside of Any, which sits the top of the
"normal" object hierarchy.

These types are deeply magical.  Whenever you find yourself trying to
use Nil or Junction as a normal value, you have to ask yourself whether
you're just Mickey Mouse falling into the Sorcerer's Apprentice trap.
Unless you're a wizard, with Nil and Junction it's better to cargo cult
a few common usages and stay the heck away the rest of the time.

Larry


Re: Nil ?

2018-09-12 Thread JJ Merelo
When you assign Nil to a string or any object, it takes its default value.

Cheers



El mié., 12 sept. 2018 a las 10:23, Simon Proctor ()
escribió:

> O learn something new everyday :)
>
> On Wed, 12 Sep 2018 at 08:46 Elizabeth Mattijsen  wrote:
>
>> Also:
>>
>> my $a is default(Nil);
>>
>> > On 12 Sep 2018, at 09:25, Simon Proctor 
>> wrote:
>> >
>> > If you don't define the type of a Scalar and don't assign to it you'll
>> have an undefined Any (the Parent class of all the other types). If you
>> assign Nil to it then you have the same effect.
>> >
>> > You can make $x to be Nil by iether casting it : my Nil $x; or binding
>> it to Nil; my $x; $x := Nil;
>> >
>> > Basically Nil is special, slippery and a bit hard to catch.
>> >
>> >
>> >
>> > On Wed, 12 Sep 2018 at 06:56 ToddAndMargo 
>> wrote:
>> > What am, I missing?
>> >
>> > $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
>> > Not Nil
>> >
>> > $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
>> > Not Nil
>> > --
>> > Simon Proctor
>> > Cognoscite aliquid novum cotidie
>>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>


-- 
JJ


Re: Nil ?

2018-09-12 Thread Simon Proctor
O learn something new everyday :)

On Wed, 12 Sep 2018 at 08:46 Elizabeth Mattijsen  wrote:

> Also:
>
> my $a is default(Nil);
>
> > On 12 Sep 2018, at 09:25, Simon Proctor  wrote:
> >
> > If you don't define the type of a Scalar and don't assign to it you'll
> have an undefined Any (the Parent class of all the other types). If you
> assign Nil to it then you have the same effect.
> >
> > You can make $x to be Nil by iether casting it : my Nil $x; or binding
> it to Nil; my $x; $x := Nil;
> >
> > Basically Nil is special, slippery and a bit hard to catch.
> >
> >
> >
> > On Wed, 12 Sep 2018 at 06:56 ToddAndMargo  wrote:
> > What am, I missing?
> >
> > $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> > Not Nil
> >
> > $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> > Not Nil
> > --
> > Simon Proctor
> > Cognoscite aliquid novum cotidie
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Re: Nil ?

2018-09-12 Thread Elizabeth Mattijsen
Also:

my $a is default(Nil);

> On 12 Sep 2018, at 09:25, Simon Proctor  wrote:
> 
> If you don't define the type of a Scalar and don't assign to it you'll have 
> an undefined Any (the Parent class of all the other types). If you assign Nil 
> to it then you have the same effect. 
> 
> You can make $x to be Nil by iether casting it : my Nil $x; or binding it to 
> Nil; my $x; $x := Nil; 
> 
> Basically Nil is special, slippery and a bit hard to catch.
> 
> 
> 
> On Wed, 12 Sep 2018 at 06:56 ToddAndMargo  wrote:
> What am, I missing?
> 
> $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> Not Nil
> 
> $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> Not Nil
> -- 
> Simon Proctor
> Cognoscite aliquid novum cotidie


Re: Nil ?

2018-09-12 Thread Simon Proctor
If you don't define the type of a Scalar and don't assign to it you'll have
an undefined Any (the Parent class of all the other types). If you assign
Nil to it then you have the same effect.

You can make $x to be Nil by iether casting it : my Nil $x; or binding it
to Nil; my $x; $x := Nil;

Basically Nil is special, slippery and a bit hard to catch.



On Wed, 12 Sep 2018 at 06:56 ToddAndMargo  wrote:

> What am, I missing?
>
> $ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> Not Nil
>
> $ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
> Not Nil
>
-- 
Simon Proctor
Cognoscite aliquid novum cotidie


Nil ?

2018-09-11 Thread ToddAndMargo

What am, I missing?

$ p6 'my $x; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
Not Nil

$ p6 'my $x = Nil; if $x =:= Nil { say "Nil" } else { say "Not Nil"; };'
Not Nil


Re: nil mystery

2018-04-30 Thread ToddAndMargo

On 04/30/2018 05:20 PM, Andrew Kirkpatrick wrote:

I couldn't
reproduce this by assigning Nil to a variable



Well as it transpires, when I tested the {$x} version, I
forgot to press "save".  Also, a one liner operated
differently than a program.  And to top things off,
when reading "this" data back from the secondary clipboard,
a nil got stuck at the end of the string.

I use ${x} a lot in bash and Perl5, so {$x} in Perl6
is my preference too.

Good times!


Re: nil mystery

2018-04-30 Thread ToddAndMargo



On Sun, Apr 29, 2018 at 10:20:48PM -0700, ToddAndMargo wrote:

On 04/29/2018 10:12 PM, ToddAndMargo wrote:

On 04/29/2018 09:32 PM, Andrew Kirkpatrick wrote:

There is not enough context to answer or even reproduce the problem -
how are the variables declared and what values do they have just prior
to this line?


Some simpler examples:

$ perl6 -e 'my $x="abcde"; say $x;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x" ~ ""; say $y;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x"; say $y;'
Type Str does not support associative indexing.
in block  at -e line 1

$ perl6 -e 'my $x="abcde"; my $y="{$x}"; say $y;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x\"; say $y;'
abcde


So when is "<" and ">" a letter and when is it a redirect?





On 04/30/2018 12:09 AM, Patrick Spek wrote:
> It seems like in the one case it throws an error, it's because `<>` 
are being
> used to index a hash. Or at least tried to. In Perl 6, you can access 
a Hash's

> elements using `%foo`, which will access the index `bar` on the Hash
> `%foo`.
>
> The other cases are explicitly not referring to a variable, or have 
delimiters
> in place to make it known to the compiler that you're not trying to 
access a

> Hash index.
>
> The error you're getting is "Type Str does not support associative 
indexing.",
> which is correct, though perhaps a little unexpected for you. `$x` 
contains a
> Str, not a Hash, but the `` still try to retrieve the index `br` 
from it.
> The solution is to use any of the other options you're using, with my 
personal

> preference going out to `{$x}`.
>


Hi Patrick,

Now it makes sense.  It was trying to resolve a hash.

Thank you!

-T

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


Re: nil mystery

2018-04-29 Thread ToddAndMargo

On 04/29/2018 10:12 PM, ToddAndMargo wrote:

On 04/29/2018 09:32 PM, Andrew Kirkpatrick wrote:

There is not enough context to answer or even reproduce the problem -
how are the variables declared and what values do they have just prior
to this line?


Some simpler examples:

$ perl6 -e 'my $x="abcde"; say $x;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x" ~ ""; say $y;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x"; say $y;'
Type Str does not support associative indexing.
  in block  at -e line 1

$ perl6 -e 'my $x="abcde"; my $y="{$x}"; say $y;'
abcde

$ perl6 -e 'my $x="abcde"; my $y="$x\"; say $y;'
abcde


So when is "<" and ">" a letter and when is it a redirect?


Re: nil mystery

2018-04-29 Thread ToddAndMargo

On 04/29/2018 09:32 PM, Andrew Kirkpatrick wrote:

There is not enough context to answer or even reproduce the problem -
how are the variables declared and what values do they have just prior
to this line? Also, what version of rakudo?

On 30 April 2018 at 11:29, ToddAndMargo <toddandma...@zoho.com> wrote:

Hi All,

These two throw an operating on a "Nil" error:
 $PartsStr ~= "$PartNo";
 $PartsStr ~= "{$PartNo}";


But this does not:
 $PartsStr ~= "{$PartNo}" ~ "";


And this does not either:
 $PartsStr ~= "abcde";

Huh?


Many thanks,
-T



$ perl6 -v
This is Rakudo version 2018.02.1 built on MoarVM version 2018.02
implementing Perl 6.c.



sub TransferParts() {
my $ClipStr;
my $PartNo;
my $Description;
my $Qty;
my $ItemPrice;

$ClipStr = ReadSecondaryClipboard();
# PrintRed( "$ClipStr\n" );
# for split( '', $ClipStr ) -> $Char { say "$Char = <", ord( $Char 
), ">"  };


$ClipStr ~~ s:global/ ord( 10 )/"\n"/;
for split( "\n", $ClipStr ) -> $Line {
if not $Line { last };
# PrintBlue( "<$Line>\n" );
# for split( '', $Line ) -> $Char { say "$Char = <", ord( $Char 
), ">"  }; say "\n\n";


$Line ~~ m/(.*?)\t(.*?)\t(.*?)\t(.*)/;
$PartNo  = $0;
$Description = $1;
$Qty = $2;
$ItemPrice   = $3;
#  PrintBlue( "PartNo <$PartNo>\nDescription 
<$Description>\nQty <$Qty>\nItemPrice <$ItemPrice>\n\n" );


$PartsStr ~= "{$PartNo}" ~ "";
$PartsStr ~= "{$Description}" ~ "";
if $Qty > 1 { $PartsStr ~= "" };
$PartsStr ~= "Qty = {$Qty}" ~ "";
if $Qty > 1 { $PartsStr ~= "" };
$PartsStr ~= "Item Price   ~{$ItemPrice}" ~ "";
$PartsStr ~= "";
}
}



Re: nil mystery

2018-04-29 Thread Andrew Kirkpatrick
There is not enough context to answer or even reproduce the problem -
how are the variables declared and what values do they have just prior
to this line? Also, what version of rakudo?

On 30 April 2018 at 11:29, ToddAndMargo <toddandma...@zoho.com> wrote:
> Hi All,
>
> These two throw an operating on a "Nil" error:
> $PartsStr ~= "$PartNo";
> $PartsStr ~= "{$PartNo}";
>
>
> But this does not:
> $PartsStr ~= "{$PartNo}" ~ "";
>
>
> And this does not either:
> $PartsStr ~= "abcde";
>
> Huh?
>
>
> Many thanks,
> -T
>
> --
> ~~~
> Serious error.
> All shortcuts have disappeared.
> Screen. Mind. Both are blank.
> ~~~


nil mystery

2018-04-29 Thread ToddAndMargo

Hi All,

These two throw an operating on a "Nil" error:
$PartsStr ~= "$PartNo";
$PartsStr ~= "{$PartNo}";


But this does not:
$PartsStr ~= "{$PartNo}" ~ "";


And this does not either:
$PartsStr ~= "abcde";

Huh?


Many thanks,
-T

--
~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~


Re: zef install Linenoise: Use of Nil in string context, (Linenoise) line 15

2018-04-26 Thread ToddAndMargo

On 04/26/2018 12:45 AM, mimosinnet wrote:

El Wednesday, 25 de April del 2018 a les 18:31, Todd Chester va escriure:


On 04/24/2018 11:30 AM, mimosinnet wrote:

This message appears when installing Linenoise

<---
$ zef install Linenoise
===> Installing: Linenoise:ver<0.1.1>:auth
Use of Nil in string context
  in block  at home#sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9
(Linenoise) line 15
--->


When I get a tough one, this "sometimes"  (watch the weasel word)
works.

Go to https://github.com/hoelzro/p6-linenoise and download Linenoise
and download Linenoise.

From inside the root of the Linesnoise director, try
 $ zef install .


Todd,

Thanks for the answer! Unfortunately, I get the same outcome:

$ zef install .
===> Testing [OK] for Linenoise:ver<0.1.1>:auth
===> Installing: Linenoise:ver<0.1.1>:auth
Use of Nil in string context
  in block  at home#sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9 
(Linenoise) line 15


Cheers!



Try asking the guys over on the Chat page.  Often times there are
bugs in the modules and they are good about getting them
fixed or coming up with workaround.

https://docs.perl6.org/webchat.html

Remember to tell them your version of Perl


Re: zef install Linenoise: Use of Nil in string context, (Linenoise) line 15

2018-04-26 Thread mimosinnet

El Wednesday, 25 de April del 2018 a les 18:31, Todd Chester va escriure:


On 04/24/2018 11:30 AM, mimosinnet wrote:

This message appears when installing Linenoise

<---
$ zef install Linenoise
===> Installing: Linenoise:ver<0.1.1>:auth
Use of Nil in string context
  in block  at home#sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9
(Linenoise) line 15
--->


When I get a tough one, this "sometimes"  (watch the weasel word)
works.

Go to https://github.com/hoelzro/p6-linenoise and download Linenoise
and download Linenoise.

From inside the root of the Linesnoise director, try
 $ zef install .


Todd,

Thanks for the answer! Unfortunately, I get the same outcome:

$ zef install .
===> Testing [OK] for Linenoise:ver<0.1.1>:auth
===> Installing: Linenoise:ver<0.1.1>:auth
Use of Nil in string context
 in block  at home#sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9 (Linenoise) 
line 15

Cheers! 


--
(≧∇≦) Mimosinnet (Linux User: #463211)

(≧∇≦) Ningún Lugar

★ Activisme Cultural per a la Transformació Social

(≧∇≦) Fractalitats en Investigació Crítica

* Investigació Crítica per a la Transformació Social
* http://psicologiasocial.uab.es/fic


Re: zef install Linenoise: Use of Nil in string context, (Linenoise) line 15

2018-04-25 Thread Todd Chester

On 04/24/2018 11:30 AM, mimosinnet wrote:

This message appears when installing Linenoise

<---
$ zef install Linenoise
===> Installing: Linenoise:ver<0.1.1>:auth
Use of Nil in string context
  in block  at home#sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9 
(Linenoise) line 15

--->

The above mentioned line is:

<---
$ sed -n '15p' .perl6/sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9

my constant LIBLINENOISE = %?RESOURCES.Str;
--->

This is a post on the %?RESOURCES variable:

https://hoelz.ro/blog/distributing-helper-libraries-with-perl6-modules

Nevertheless, I have fail to to solve this issue. Any hints appreciated.

Thanks!


P.D.: Perl6 info:
<---
$ perl6 -v
This is Rakudo version 2018.02 built on MoarVM version 2018.02
implementing Perl 6.c.
--->



Hi Mimosinnet,

When I get a tough one, this "sometimes"  (watch the weasel word)
works.

Go to https://github.com/hoelzro/p6-linenoise and download Linenoise
and download Linenoise.

From inside the root of the Linesnoise director, try
 $ zef install .

-T


zef install Linenoise: Use of Nil in string context, (Linenoise) line 15

2018-04-24 Thread mimosinnet

This message appears when installing Linenoise

<---
$ zef install Linenoise 


===> Installing: Linenoise:ver<0.1.1>:auth
Use of Nil in string context
 in block  at home#sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9 (Linenoise) 
line 15
--->

The above mentioned line is:

<---
$ sed -n '15p' .perl6/sources/0BDF8C54D33921FEA066491D8D13C96A7CB144B9

my constant LIBLINENOISE = %?RESOURCES.Str;
--->

This is a post on the %?RESOURCES variable:

https://hoelz.ro/blog/distributing-helper-libraries-with-perl6-modules

Nevertheless, I have fail to to solve this issue. Any hints appreciated.

Thanks!


P.D.: Perl6 info:
<---
$ perl6 -v 


This is Rakudo version 2018.02 built on MoarVM version 2018.02
implementing Perl 6.c.
--->

--
(≧∇≦) Mimosinnet (Linux User: #463211)


Re: Need help with Nil values

2016-02-23 Thread Lloyd Fournier
You could just do:

method new (Str $value?) { ... } # makes value optional

and then not pass anything to .new.

On Tue, Feb 23, 2016 at 1:27 PM TS xx <maringa...@hotmail.com> wrote:

> Thanks Brandon,
>
>
> That was what I was looking for.
>
> I'm trying it already.
>
>
> Regards,
>
> Emiliano
>
>
> --
> *From:* Brandon Allbery <allber...@gmail.com>
> *Sent:* Tuesday, February 23, 2016 2:21 AM
> *To:* TS xx
> *Cc:* perl6-users@perl.org
>
> *Subject:* Re: Need help with Nil values
> On Mon, Feb 22, 2016 at 9:15 PM, TS xx <maringa...@hotmail.com> wrote:
>
>> I expect $.value to hold Strings, but I want to be able to instantiate
>> MyClass whether I have a value already or not, and I also want to be able
>> to tell if $.value has a real String or not. Is this possible?
>
>
> You don't want Nil there; it's not the undefined value, it's a value of a
> special type. You want Str, the type object for Strings, which also serves
> as the undefined value (also true for other types). You can test it with
> `defined`.
>
> $myObject = MyClass.new(Str);
>
> then you can test $!value.defined or whatever.
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: Need help with Nil values

2016-02-22 Thread TS xx
Thanks,

That was it.
Somtimes I get confused with the way other languages treat undefined/null/nil 
values.

Regards,
Emiliano


From: Timo Paulssen <t...@wakelift.de>
Sent: Tuesday, February 23, 2016 2:20 AM
To: perl6-users@perl.org
Subject: Re: Need help with Nil values

Hello Emiliano,

In this case, I think you may want to use just "Str" instead of "Nil".
"Str" is the "type object" for Str objects, and you can check whether
it's a string like "foo" or just the Str object by checking $!value.defined.

There's a FAQ answer that's about "Any", but it works the same way for
"Str":

 http://doc.perl6.org/language/faq#What_is_%28Any%29%3F

And there's the classtut that talks about this a bit more in depth,
search for "type object":

 http://doc.perl6.org/language/classtut


I hope this'll get you towards your goal. If not, just keep asking :)

Have fun with Perl 6!
   - Timo



Re: Need help with Nil values

2016-02-22 Thread Brandon Allbery
On Mon, Feb 22, 2016 at 9:15 PM, TS xx <maringa...@hotmail.com> wrote:

> I expect $.value to hold Strings, but I want to be able to instantiate
> MyClass whether I have a value already or not, and I also want to be able
> to tell if $.value has a real String or not. Is this possible?


You don't want Nil there; it's not the undefined value, it's a value of a
special type. You want Str, the type object for Strings, which also serves
as the undefined value (also true for other types). You can test it with
`defined`.

$myObject = MyClass.new(Str);

then you can test $!value.defined or whatever.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Need help with Nil values

2016-02-22 Thread Timo Paulssen

Hello Emiliano,

In this case, I think you may want to use just "Str" instead of "Nil". 
"Str" is the "type object" for Str objects, and you can check whether 
it's a string like "foo" or just the Str object by checking $!value.defined.


There's a FAQ answer that's about "Any", but it works the same way for 
"Str":


http://doc.perl6.org/language/faq#What_is_%28Any%29%3F

And there's the classtut that talks about this a bit more in depth, 
search for "type object":


http://doc.perl6.org/language/classtut


I hope this'll get you towards your goal. If not, just keep asking :)

Have fun with Perl 6!
  - Timo