[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bitwise operators in IDL?
Marc Schellens wrote:
>
> > 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.
Not if you introduce another operator set all together for short
circuiting. People will use them increasingly, and AND,OR will go back
to being used primarily for their bitwise function, as they should be.
Sort of like C has "&&" and "&". I can't think of good replacement
names (I assume RSI won't allow the sensible && and ||). Ideas? (ANDS?
ORS?).
JD