in reply to Re: Re: Operation `bool': no method found, argument in overloaded package Vector2D at
in thread Operation `bool': no method found, argument in overloaded package Vector2D at

More or less. Careful, though, because bool, as written, is always true. Or rather, always undefines the object that you were trying to check for truth. Remember, references are always defined and true. You probably want to be true when either of the X and Y (or r and theta) is nonzero.

TACCTGTTTGAGTGTAACAATCATTCGCTCGGTGTATCCATCTTTG ACACAATGAATCTTTGACTCGAACAATCGTTCGGTCGCTCCGACGC
  • Comment on Re: Re: Re: Operation `bool': no method found, argument in overloaded package Vector2D at

Replies are listed 'Best First'.
Re: Re: Re: Re: Operation `bool': no method found, argument in overloaded package Vector2D at
by rbc (Curate) on Jan 24, 2002 at 09:25 UTC
    What was I thinking ...

    I meant ...
    sub bool { return defined (shift); }
    ... I think? Right?

    Why don't I just run it and find out!
    Thanks again

      Well, that does what you think it does, probably. If the object you're trying to determine the truth of is defined, then this will return a true value, and the Vector2D will thus be considered true.

      However, consider for a moment under what circumstances this will return false.

      defined() returns false only if it's argument is undef. However, undef isn't-a Vector2D, so your bool() function will never get called on undef.

      You method, in other words, is equivilent to sub bool {return 1;} (golfers note: in all of these examples, the return and semicolon are optional. I find that confusing, so don't use it.).

      Think about what the semantics of truth for a Vector2D are, then write your function.

      (BTW, I don't mean for this to sound snippy or anything, I'm just in a kind of off mood.)

      TACCTGTTTGAGTGTAACAATCATTCGCTCGGTGTATCCATCTTTG ACACAATGAATCTTTGACTCGAACAATCGTTCGGTCGCTCCGACGC