=head1 TITLE Distinguish packed data from printable strings =head1 VERSION Maintainer: Tim Conrow Date: 18 Sept 2000 Last Modified: 28 Sep 2000 Mailing List: perl6-language@perl.org Number: 258 Version: 2 Status: Frozen =head1 NOTES ON THE FREEZE As expected, there was very little interest in this RFC, so with a few minor tweaks intended to reduce misunderstanding, I'm going to freeze it and let it recede into the background of lesser RFCs. =head1 CHANGES Added some text for clarity. A few rewordings. One or two minor tweaks to my current idea of DWIMish behavior for packed data. =head1 ABSTRACT Perl6 should be able to DWIMishly distinguish between strings which are likely to be meant to be human readable (called printable strings here-after) and packed data structures stored as strings. This would permit greater specificity in programming and thus better error checking. =head1 DESCRIPTION Although there is no way for perl6 to be sure whether a user intends a particular string to be human readable or not, it could DWIMishly get it right a large fraction of the time, analogous to how perl now differentiates between a string and a numeric. Doing so would permit some useful error checking and help users, especially new users, avoid some common mistakes made in perl5, such as the confusion between the two meanings of C<&>. If the DWIMery is tuned correctly there would be very little interference with common (and correct) coding idioms. A new scalar flag, which I'll call PkOK (for "Packed OK"), would be set in a scalar's flags by any builtin function or operator that produces a string which is likely to be a packed data structure of some sort rather than a printable string or a numeric value. These include C, C, C, C, the multi-argument form of C, exemplified above, builtin operators and functions which expect to operate on packed data structures (including bitwise ops) would behave thusly if C and C are in effect: NOK POK PkOK ------------- 0 0 1 not possible? 0 1 0 promote via C, issue warning 0 1 1 OK 1 0 0 error 1 0 1 not possible? 1 1 0 promote, issue warning 1 1 1 OK =item * With certain exceptions for C and C<"">, exemplified above, builtins expecting a "printable string" would issue a warning if given a scalar with the PkOK bit set. =item * By way of an imperfect analogy, note the similarity between packed strings having a PkOK flag via C (and others) and regexs having an ROK flag via C. =head1 MIGRATION When translating code with p526, put no warnings 'packed'; no strict 'packed'; at the start of each lexical structure. =head1 REFERENCES RFC 73: All Perl core functions should return objects RFC 89: Controllable Data Typing RFC 142: Enhanced Pack/Unpack RFC 159: True Polymorphic Objects RFC 161: Everything in Perl becomes an object. RFC 246: pack/unpack uncontrovercial enhancements RFC 247: pack/unpack C-like enhancements RFC 248: enhanced groups in pack/unpack RFC 249: Use pack/unpack for marshalling RFC 250: hooks in pack/unpack