variable existence checking

Tony Balinski ajbj at free.fr
Tue May 29 21:02:23 CEST 2007


Quoting "A.V.Kuznetsov" <kuzn at umps.mephi.ru>:

> Hi,
>
> >
> > I would actually prefer an existence operator, but NOT !!. This has a
> definite
> > meaning: "is true" (in macro !!x is equivalent to x!=0). I have been
> thinking
> > along the lines of an "exists" operator "??" instead:
>
> You are right as always.
>
> >     ??var: return true (1) if var has a value, false (0) otherwise
> >     ??array[]: return true if array is an array
> >     ??array[key]: return (key in array)
> >     ??array[key1][key2]: return ((key1 in array) && (key2 in array))
> > (with my array.key language extension, also: array??.key)
> >
>
> ??array[key1][key2]: return ((key1 in array) && (key2 in array[key1]))

Oops, well spotted!

BTW I wanted to avoid the ? as the operator so that we could at some point
have C's ?: ternary operator, which I find very useful.

Another route would be to allow undefined as a pseudo-value in variables (an
actual value in simple variables, possibly just a sign of a missing index in
arrays) that you could pass to functions etc, test against and assign using.
This would move things a little closer to Perl, say, where undefined values do
more than cause failure.

As far as I'm concerned, this is an open issue.

Tony


More information about the Discuss mailing list