On Fri, Aug 10, 2007 at 04:20:04PM -0700, Colin Kuskie wrote: > This patch adds a new tutorial file, 56_defined.pir, which talks > about the concept of definedness. >... > +=head1 defined > + > +The defined function tells you if the contents of a PMC register is defined > or not. Using > +defined on an temporary Integer, Number, or String register will generate an > error.
For consistency's sake I think we should stick with the term "opcode" or "operation" instead of "function". Also, it might help to surround the word "defined" with C<...>, as in: The C<defined> opcode tells you if the contents of a PMC register are defined... > +.sub main :main > + > + $I0 = defined $P0 > + if $I0 goto defined_PO > + say "$P0 is undefined before being used" > + goto end_defined_P0 > + defined_PO: > + say "$P0 is defined before being used" I'm not certain that uninitialized registers ($P0 in the above) are guaranteed to be null ... in particular, the PIR assembler might be free to map $P0 to a register that already has a value of some sort in it. So, someone might be very surprised to try a variation of the above code and get back a result that "$P0 is defined". > +PMCs are undefined before being typed. After they are typed, they > +are defined, and hold whatever default value PMCs of that type contain. > ... This is likely misleading. All PMCs have a type, so there aren't really states of "before being typed" or "after being typed". There is an Undef type, but it's just another type. Also, definedness is not necessarily tied only to the Undef type. Any PMC is able to have its own concept of definedness -- thus a HLL can create things that represent undefined integers, undefined strings, undefined files, etc. The C<defined> opcode simply queries a PMC to see if it believes it is defined or not, according to that PMC's criteria for "definedness". > + $P1 = new String Within the past few months we've standardized on always quoting type names in PIR, so the above needs to read $P1 = new 'String' Throughout Parrot you'll find lots of examples and code that use older deprecated syntaxes -- they should probably be changed to the new syntax as well (patches welcome!). $P1 = new .String # deprecated $P1 = new String # deprecated Thanks for the contributions! Pm