in reply to Re: Determining whether a value is zero.
in thread Determining whether a value is zero.

Give that man a cigar (or another vice to his liking). Not only did ikegami understood and solved the challenge, he didn't feel the need to argue the rules weren't to his liking.

If there's a way to do it without having to break encapsulation of value and peek at their internal flags, I don't know such a way - but I'd love to hear about it.

  • Comment on Re^2: Determining whether a value is zero.

Replies are listed 'Best First'.
Re^3: Determining whether a value is zero.
by ikegami (Patriarch) on Mar 11, 2011 at 21:17 UTC

    If there's a way to do it without having to break encapsulation of value and peek at their internal flags, I don't know such a way - but I'd love to hear about it.

    Tried and failed. Need to find something that can distinguish between absent IV and NV and zero IV or NV. This boils down to finding something that

    • favours IV and NV over PV, and
    • doesn't silently numify the PV if it looks_like_number.

    Lots of operations match the first requirement (arithmetic and bitwise ops) but I can't think of anything that matches both.

Re^3: Determining whether a value is zero.
by ikegami (Patriarch) on Mar 11, 2011 at 18:27 UTC
    To be fair, I would have mentioned something about the rules not being practical if it hadn't already been said. In case you were actually planning on using this and didn't realize the consequences.
Re^3: Determining whether a value is zero.
by Fox (Pilgrim) on Mar 11, 2011 at 13:17 UTC
    isn't dualvar's made by peeking at the internals ? I think it's unfair to try to detect something without the same techniques used to create that something, but hey it's your challenge.

    On a unrelated note, is dualvar(undef,"string") zero ?
      isn't dualvar's made by peeking at the internals ?
      Eventually, everything Perl is done by doing something with the internals. However, all dualvar exposes is that values can have both a numeric and a string value. One could change large parts of the internals without having to change the interface of dualvar. However, the solution presented queries internal bits of the SV structure.
      is dualvar(undef,"string") zero ?
      Yes. There's no way to store "undef" in the IV slot of an SV. AFAIK, the undef has been (auto)cast to 0 before the SV will be created.