[kw-pm] what is "truth value" in perl 6?

Arguile arguile at lucentstudios.com
Thu Jul 10 00:48:47 CDT 2003


On Wed, 2003-07-09 at 17:10, Robert P. J. Day wrote:
> 
>   from what i'm reading, perl 6 *seems* to extend the notion of
> boolean values from perl 5 in defining a real "truth value" of 
> a variable.

P5 has real bools, they're just hidden within the internal variable
object. I'm sure you've heard of "zero but true" (OEO); the case where
the integer value of the object is "0", but the boolean value is "true".

Read about variable "Overload"ing.

> 
>   according to the book, "The unary ? operator ... forces boolean 
> context... With the ? operator, you can force boolean context and 
> assign the truth value of a variable instead of the numeric value."
> 
>   $value = $number ;		# standard assignment
>   $value = ?$number ;		# assign truth value of $number
> 
> but what exactly would be assigned?  a zero or one?  

No, "true" or "false" would be assigned. As to what the string
representation of a pure bool will be I'm not sure.

> is this referring to an inherent true or false value that i 
> haven't seen described yet?  

Read Apocalype 4 (I think that's the one). It describes the internal
types and a bit about their workings.

P6, like P5, will still be a dynamically weakly typed language, but
you'll be able to declare stuff like this:

	my $foo : bool; # Not sure if this is even remotely
                        # the correct syntax.

This means that you get some of the compile time type checking benefits
seen in other languages. Just as importantly though, you're also
declaring storage requirements to some extent; again like other (C/C++)
languages.

When you declare a variable of type 'foo' in P6, it will only keep the
parts of it's internal variable structures that relate to that type.
Thus using less memory and functioning faster than if the entire object
was always carried around (as P5d does). 



P.S. I'll try to find the threads/articles I read this in but don't hold
your breath.

P.P.S. My terminology when dealing with P5 and P6 internals is probably
way off, I apologize for that. I don't follow it closely enough to pick
up on their jargon. I was also trying to avoid explaining perlguts
in-depth as I have only a loose/working understanding myself.




More information about the kw-pm mailing list