comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » _overloadMinus: what to do with invalid input?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: _overloadMinus: what to do with invalid input? [message #89931 is a reply to message #89929] Mon, 29 December 2014 14:27 Go to previous messageGo to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Monday, December 29, 2014 5:41:49 PM UTC-2, Mike Galloy wrote:
> I would think an error and halting, like IDL would do if you tried to use
> an invalid operator with the native types. What happens if you try to add
> two pointers? (not in front of my computer right now)

To answer Mike's question:

IDL> a=ptr_new(1)
IDL> b=ptr_new(2)
IDL> c=a+b
% Operation illegal with pointer types.
% Execution halted at: $MAIN$

Regarding Paul's question, I would say that the answer depends on how one envisions the object's usage. If one decides it makes no sense to do the subtraction, like with pointers, it should throw an error. An error should also be raised, instead of returning a value, if such a return value could be confused with a valid result. For instance, taking IDL's list:

IDL> l=list(1,2)
IDL> l+3
% LIST::_OVERLOADPLUS: Arguments must both be lists.
% Execution halted at: $MAIN$
IDL> l-1
% Unable to convert variable to type object reference.
% Execution halted at: $MAIN$

It throws an error if I try to add or subtract an integer to a list. If it returned something, like !null, 0 or an empty list, such a return could be confused with something that is a valid result, obtained from different operations.

One could argue that adding/subtracting a scalar to a list should mean applying that operation to each element in the list, so that l-1 above should be equivalent to l.map(lambda(x:x-1)). But that is not what currently happens (as of IDL 8.4).
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: CGContour with and without cell_fill keyword
Next Topic: Create an array of color name

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:51:44 PDT 2025

Total time taken to generate the page: 0.00436 seconds