|
|
Subscribe / Log in / New account

Poor arguments against

Poor arguments against

Posted Feb 17, 2015 18:58 UTC (Tue) by marcH (subscriber, #57642)
In reply to: Poor arguments against by rgmoore
Parent article: Scalar typing in the PHP world

> say $a ^^ $b ^^ $c; #prints a blank line
> say ($a ^^ $b) ^^ $c; #prints "unknown"

I would expect both to return nil/blank line. Did you run these?


to post comments

Poor arguments against

Posted Feb 18, 2015 0:01 UTC (Wed) by rgmoore (✭ supporter ✭, #75) [Link] (2 responses)

I just tested, and the first does return Nil and the second "unknown". This makes perfect sense to me, because "true" ^^ "false" returns Nil, and Nil ^^ "unknown" returns "unknown".

Poor arguments against

Posted Feb 18, 2015 0:22 UTC (Wed) by marcH (subscriber, #57642) [Link] (1 responses)

I thought "false" was false (why did you use it?!)

Poor arguments against

Posted Feb 18, 2015 8:30 UTC (Wed) by mbunkus (subscriber, #87248) [Link]

In Perl 5 the following values are false in Boolean contexts: the number 0, an empty string, empty lists and arrays, undef and the string containing the single digit "0". All other values (including strings of any length > 0 no matter their content, e.g. "false") are true in Boolean contexts. The same is true in Perl 6 with Nil instead of undef.

Therefore in "true" ^^ "false" you have two trueish operands and therefore the result will be Nil.

Those strings are probably not the best and most self-explanatory when explaining Boolean concepts, though.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds