What is the difference between Perl 6 DEFINITE and specific methods?

Type objects are always undefined, but I saw some tests that use .defined and some that use .DEFINITE . Are there any cases when they can be different? I tend to think that any method in which all uppercase letters are not intended for everyday work prefers .defined for this task.

 my $class = IntStr; put '-' x 20; # False put $class.DEFINITE; put $class.defined; put '-' x 20; # False $class = Nil; put $class.DEFINITE; put $class.defined; put '-' x 20; # True $class = ''; put $class.DEFINITE; put $class.defined; 

As a result, I look for any case where the answers to the two methods are different:

 -------------------- False False -------------------- False False -------------------- True True 
+8
perl6
source share
1 answer

.DEFINITE should be considered a macro (just like .WHAT , .HOW , etc.). It is directly processed in Actions and converted to nqp::p6definite() op.

.defined is a method that lives in Mu and that can be overridden by your class. It is actually overridden for Failure , so the Failure instance can act as an undefined value, for example. a if (and "handle" failure).

 my $a = Failure.new("foo"); say "bar" if $a; # no output say $a; # outputs "(HANDLED) foo", but no longer throws 

So, to answer your question:

 my $a = Failure.new("foo"); say $a.DEFINITE; # True say $a.defined; # False 
+11
source share

All Articles