[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bitwise operators in IDL?

> It would be really nice if IDL had any logical operators, other than
> implied in the ambiguous usage of bitwise op's for different types.
> Specifically, having a "short-circuiting" AND and OR operator set would
> be exceptionally useful.
> How often do you find yourself doing something like:
> if ptr_valid(a) AND *a ge 0 then...
> only to find that it can't work, because AND always evaluates everything
> it operates on.  Most decent languages offer short circuiting AND's (and
> OR's etc.), that stop as soon as the true solution is known.  Here, if
> ptr_valid(a) is not true, there would be no need to continue to try to
> dereference 'a' (which generates an error), and this snippet would be
> correct.
> I guess for now we're stuck with
> if ptr_valid(a) then begin
>   if *a ge 0 then begin...
> Oh the tedium.
> JD
To late for short circuitry.
Consider a case when the second function in the if case
has a side effect (e.g. modifying a global variable).
After once defining the language this way, to change it
would mean to introduce incopatibility.

But you can write:
if ptr_valid(a) then if *a eq b then begin

which looks a little bit nicer (IMHO).

:-) marc