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

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
=EF=BD=A2love=EF=BD=A3
=EF=BD=A2like=EF=BD=A3

[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.
0
perl6
5/18/2020 6:59:18 AM
perl.perl6.users 1391 articles. 0 followers. Follow

4 Replies
11 Views

Similar Articles

[PageSpeed] 18

"say $x" is essentially equivalent to "put $x.gist".

Since Nil is undefined (roughly equivalent to a type object), Nil.gist ha=
s a string value of "Nil" and can be printed.  However, attempting to con=
vert 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 <unit> at <unknown file> line 1
    > say Nil.Str
    Use of Nil in string context
      in block <unit> at <unknown file> 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<say> calls .gist on Nil which pro=
duces a printable string, while C<put> attempts to stringify the Nil obje=
ct directly and that throws an error.

Pm

On Sun, May 17, 2020 at 11:59:18PM -0700, William Michels via perl6-users=
 wrote:
> Hello,
>=20
> 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).
>=20
> 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".
>=20
> [1] homedir$ cat demo1.txt
> this is a test,
> I love Unix,
> I like Linux too,
>=20
> [2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt
> this is a test,
> I admire Unix,
> I admire Linux too,
>=20
> [3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt
> Nil
> =EF=BD=A2love=EF=BD=A3
> =EF=BD=A2like=EF=BD=A3
>=20
> [4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt
> Use of Nil in string context
>   in block  at -e line 1
>=20
> love
> like
>=20
> [5] homedir$
>=20
> 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)?
>=20
> Any enlightenment appreciated,
>=20
> TIA, Bill.
0
pmichaud
5/18/2020 11:03:01 AM
--00000000000017040c05a5ef5b10
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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 =3D> 1, y =3D> 2 ).Str
    # Point<94102525076384>

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

    put Point.new( x =3D> 1, y =3D> 2 ).raku
    # Point.new(x =3D> 1, y =3D> 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 =3D> 1, y =3D> 2 ).Str
    # [1,2]

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

    put Point.new( x =3D> 1, y =3D> 2 ).raku
    # Point.new(x =3D> 1, y =3D> 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 =3D> 10, e =3D> 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 <unit> at <unknown file> line 1

    > Nil.Str
    Use of Nil in string context
      in block <unit> at <unknown file> 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 <unit> at <unknown file> 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 'say s/love|like/admire/;' demo1.txt
> Nil
> =EF=BD=A2love=EF=BD=A3
> =EF=BD=A2like=EF=BD=A3
>
> [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.
>

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

<div dir=3D"ltr">You are misunderstanding=C2=A0what `put` does.<div><br></d=
iv><div>It does not print the internal representation.</div><div><br></div>=
<div>What it does do is turn the value into a `Str` object, then print it w=
ith a trailing newline.</div><div><br></div><div>It just so happens that ob=
jects will by default return something that looks like an internal represen=
tation when you coerce it to a `Str`.</div><div><br></div><div>=C2=A0 =C2=
=A0 class Point {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 has ($.x, $.y);</di=
v><div>=C2=A0 =C2=A0 }<br></div><div>=C2=A0 =C2=A0 put Point.new( x =3D&gt;=
 1, y =3D&gt; 2 ).Str<br></div><div>=C2=A0 =C2=A0 # Point&lt;94102525076384=
&gt;</div><div><br></div><div>=C2=A0 =C2=A0 put Point.new( x =3D&gt; 1, y =
=3D&gt; 2 ).gist<br></div><div>=C2=A0 =C2=A0 # Point.new(x =3D&gt; 1, y =3D=
&gt; 2)</div><br>=C2=A0 =C2=A0 put Point.new( x =3D&gt; 1, y =3D&gt; 2 ).ra=
ku<br>=C2=A0 =C2=A0 # Point.new(x =3D&gt; 1, y =3D&gt; 2)<div><br></div><di=
v><div></div><div>Unless they have a `.Str` method that returns something m=
ore sensible.</div></div><div><div><br></div><div>=C2=A0 =C2=A0 class Point=
 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 has ($.x, $.y);</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 method Str () {<br></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 &quot;[$!x,$!y]&quot;<br></div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 }<br></div><div>=C2=A0 =C2=A0 }<br></div><div>=C2=A0 =C2=A0 put Poin=
t.new( x =3D&gt; 1, y =3D&gt; 2 ).Str<br></div><div>=C2=A0 =C2=A0 # [1,2]</=
div><div><br></div><div>=C2=A0 =C2=A0 put Point.new( x =3D&gt; 1, y =3D&gt;=
 2 ).gist<br></div><div>=C2=A0 =C2=A0 # Point.new(x =3D&gt; 1, y =3D&gt; 2)=
</div><br>=C2=A0 =C2=A0 put Point.new( x =3D&gt; 1, y =3D&gt; 2 ).raku<br>=
=C2=A0 =C2=A0 # Point.new(x =3D&gt; 1, y =3D&gt; 2)</div><div><br></div><di=
v>Note that the default of `.gist` is do the same thing as calling `.raku`.=
</div><div>(Many/Most built-in objects have a `.gist` method that returns s=
omething different.)</div><div><br></div><div>---</div><div><br></div><div>=
`s///` and `S///` are both intended as working on `Str` objects. So when yo=
u give them something that is not a `Str`, they turn it into a `Str` first.=
</div><div>Actually all operations that are `Str` operations will turn it i=
nto a `Str` first.</div><div>Like `.starts-with`, `.ends-with`, `.chars`, `=
..codes`, `.index`, `.substr`, `print`, and `put`</div><div><br></div><div>W=
hat `say` does, is that instead of calling `.Str` it calls `.gist`</div><di=
v><br></div><div>`.gist` is defined as giving enough information for a huma=
n to be able to figure out what object was printed.</div><div>(Which is why=
 the default is to return the same thing as `.raku` for defined objects)</d=
iv><div><br></div><div>Actually almost all operations are intended for one =
type of object, and will coerce to that type.</div><div><br></div><div>=C2=
=A0 =C2=A0 &gt; say [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]=C2=A0 =C2=A0+=
=C2=A0 =C2=A0%( d =3D&gt; 10, e =3D&gt; 20 )</div><div>=C2=A0 =C2=A0 5</div=
><div><br></div><div>---</div><div><br></div><div>Many objects will throw a=
n error if you call `.Str` on them when they are undefined.</div><div><br><=
/div><div>=C2=A0 =C2=A0 &gt; Bool.Str</div><div>=C2=A0 =C2=A0 Use of uninit=
ialized value of type Bool in string context.</div>=C2=A0 =C2=A0 Methods .^=
name, .raku, .gist, or .say can be used to stringify it to something meanin=
gful.<br>=C2=A0 =C2=A0 =C2=A0 in block &lt;unit&gt; at &lt;unknown file&gt;=
 line 1<br><div><br></div><div>=C2=A0 =C2=A0 &gt; Nil.Str</div><div>=C2=A0 =
=C2=A0 Use of Nil in string context<br>=C2=A0 =C2=A0 =C2=A0 in block &lt;un=
it&gt; at &lt;unknown file&gt; line 1<br><br></div><div>Which means they al=
so throw an error if you try to use one of=C2=A0the methods intended for `S=
tr` objects on them.</div><div><br></div><div>=C2=A0 =C2=A0 &gt; Bool.subst=
r(0,1)</div><div>=C2=A0 =C2=A0 Use of uninitialized value of type Bool in s=
tring context.</div>=C2=A0 =C2=A0 Methods .^name, .raku, .gist, or .say can=
 be used to stringify it to something meaningful.<br>=C2=A0 =C2=A0 =C2=A0 i=
n block &lt;unit&gt; at &lt;unknown file&gt; line 1<br><div><br></div><div>=
=C2=A0 =C2=A0 &gt; Bool.^name.substr(0,1)</div><div>=C2=A0 =C2=A0 B</div><d=
iv><br></div><div>The reason for it generating an error is that generally w=
hen you try to turn an undefined object into a Str, there is likely a bug s=
omewhere.</div><div><br></div><div>---</div><div><br></div><div>Since `.gis=
t` is for a human, it doesn&#39;t matter if the returned value is a little =
wrong, so it doesn&#39;t fail.</div><div>(A human can notice if something i=
s wrong. A program that only does what you told it to, generally doesn&#39;=
t.)</div><div><br></div><div>=C2=A0 =C2=A0 &gt; Bool.gist</div><div>=C2=A0 =
=C2=A0 (Bool)</div><div><br></div><div>Note that the reason it puts ( and )=
 around the name of the object is so that you know that you might have a pr=
oblem somewhere in your code.</div><div><br></div><div>---</div><div><br></=
div><div>Further, Nil is actually the most basic of the Failure objects.</d=
iv><div><br></div><div>=C2=A0 =C2=A0 &gt; for Failure.^mro { say .^name }</=
div><div>=C2=A0 =C2=A0 Failure<br>=C2=A0 =C2=A0 Nil<br>=C2=A0 =C2=A0 Cool<b=
r>=C2=A0 =C2=A0 Any<br>=C2=A0 =C2=A0 Mu<br></div><div><br></div><div>If you=
 get a Nil, there is probably some sort of failure somewhere.</div><div><br=
></div><div>=C2=A0 =C2=A0 &gt; say ( 1, 2, 3, 4 ).first( &#39;one&#39; )</d=
iv><div>=C2=A0 =C2=A0 Nil</div><div><br></div><div>Which means that if you =
try to use a Nil as a Str, there is definitely=C2=A0a bug in your code.</di=
v></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr=
">On Mon, May 18, 2020 at 2:00 AM William Michels via perl6-users &lt;<a hr=
ef=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br><=
/div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
I&#39;m interested in knowing the differences between the return values<br>
when &quot;say&quot; is used compared to &quot;put&quot;. My understanding =
is that &quot;put&quot;<br>
returns Raku&#39;s internal representation of a value held by a variable,<b=
r>
while &quot;say&quot; is merely &quot;put&quot; with the .gist method calle=
d on it (a<br>
&quot;human readable&quot;, often-abbreviated return value).<br>
<br>
Below I do &quot;S///&quot; (non-destructive) and &quot;s///&quot; (destruc=
tive) text<br>
replacement on a three line text file in bash line [1]. In bash line<br>
[2], the full substituted text file is correctly returned; in bash<br>
line [3] using &quot;say&quot; only the $/ match string is returned. So far=
 so<br>
good. However, a virtually-identical call in bash line [4] using &quot;put&=
quot;<br>
instead of &quot;say&quot; returns an error for the first line of the targe=
t<br>
text file: &quot;Use of Nil in string context in block=C2=A0 at -e line 1&q=
uot;.<br>
<br>
[1] homedir$ cat demo1.txt<br>
this is a test,<br>
I love Unix,<br>
I like Linux too,<br>
<br>
[2] homedir$ perl6 -ne &#39;say S/love|like/admire/;&#39; demo1.txt<br>
this is a test,<br>
I admire Unix,<br>
I admire Linux too,<br>
<br>
[3] homedir$ perl6 -ne &#39;say s/love|like/admire/;&#39; demo1.txt<br>
Nil<br>
=EF=BD=A2love=EF=BD=A3<br>
=EF=BD=A2like=EF=BD=A3<br>
<br>
[4] homedir$ perl6 -ne &#39;put s/love|like/admire/;&#39; demo1.txt<br>
Use of Nil in string context<br>
=C2=A0 in block=C2=A0 at -e line 1<br>
<br>
love<br>
like<br>
<br>
[5] homedir$<br>
<br>
I&#39;m really trying to understand this error message:=C2=A0 doesn&#39;t R=
aku know<br>
that this is a text replacement operation? How can a &#39;Nil&#39; be<br>
correctly represented when called by &quot;say&quot;, but throw an error wh=
en<br>
called by &quot;put&quot;? If the value is absent at the Raku representatio=
nal<br>
level and throws an error, wouldn&#39;t it be reasonable to assume that<br>
the same case would hold for &quot;say&quot;? And finally, does this &quot;=
say / put&quot;<br>
difference mean that some textual information will be lost from return<br>
values (because &quot;say&quot; will have to be used instead of &quot;put&q=
uot; to avoid<br>
errorring-out)?<br>
<br>
Any enlightenment appreciated,<br>
<br>
TIA, Bill.<br>
</blockquote></div>

--00000000000017040c05a5ef5b10--
0
b2gills
5/18/2020 5:18:35 PM
On Mon, May 18, 2020 at 4:03 AM Patrick R. Michaud <pmichaud@pobox.com> wro=
te:
>
> "say $x" is essentially equivalent to "put $x.gist".
>
> Since Nil is undefined (roughly equivalent to a type object), Nil.gist ha=
s a string value of "Nil" and can be printed.  However, attempting to conve=
rt Nil directly into a Str throws an error because that's attempting to str=
ingify 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 <unit> at <unknown file> line 1
>     > say Nil.Str
>     Use of Nil in string context
>       in block <unit> at <unknown file> 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<say> calls .gist on Nil which produ=
ces a printable string, while C<put> attempts to stringify the Nil object d=
irectly and that throws an error.
>
> Pm
>

Thank you very much, Patrick. --Bill.
0
perl6
5/18/2020 10:47:42 PM
On Mon, May 18, 2020 at 10:18 AM Brad Gilbert <b2gills@gmail.com> 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 <unit> at <unknown file> line 1
>
>     > Nil.Str
>     Use of Nil in string context
>       in block <unit> at <unknown file> 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 <unit> at <unknown file> 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.
0
perl6
5/18/2020 10:49:34 PM
Reply: