develooper Front page | perl.perl5.porters | Postings from April 2008

Re: [perl #53550] Overload and fallback binary or (|)

Thread Previous
David Nicol
April 30, 2008 13:54
Re: [perl #53550] Overload and fallback binary or (|)
Message ID:
On Wed, Apr 30, 2008 at 11:01 AM, Rafael Garcia-Suarez
<> wrote:

>  Well, binary logical operators work on strings and on numbers. Which
>  is a source of problems in perl. (and also why one should really not
>  rely on fallback for those) I suggest a little note in to
>  document the state with overload and logical ops as a potential
>  gotcha, but I don't think we can do better.

What if the part that forces the result of overload '""' to be a
string got struck?  There is nothing in the fallback code aside from
the convention of "" tending to be a string that indicates that
$_[0]->{n} should be a string, therefore overload must be doing the
conversion instead of making an accurate copy and letting the user of
the result convert it to a string if required.

Another possibility, heavier than identifying and deleting one line of code,
would be to create a bit-vector mode of expression besides string and number and
allow overload to directly allow access to "as-a-BV" perhaps with a '0|'
overload key, which would be defined to fallback to either '""' or '0+' instead
of punting to documenting a here-be-dragons warning.  Although without
complete refactoring of everything to support this new mode, currently
done with a heuristic (has PVOK flag? string : number (float or
integer)) AIUI that might become a lot of work

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About