NULLs
Hans-Dieter.Dreier@materna.de
Hans-Dieter.Dreier@materna.de
Fri, 16 Jul 1999 17:56:48 +0200
--s0K7sYVmYGo9dY2m9fwxYBDXqtUOv7FY
Content-type: text/plain; charset="ISO-8859-1"
Content-transfer-encoding: quoted-printable
>> >I think that it'd be possible to offer a higher-level construct =
>for =3D
>> =
>> >this than checking to see if a pointer equaled NULL, though. Maybe =
>a =3D
>> =
>> >defined keyword? Would this fit with the static type system? Of =3D
>> =
>> >course, it would probably be implemented by checking to see if the =
>=3D
>> =
>> >reference was set to NULL but we don't need to know that.
>> =
>> Could you show an example?
>> =
>
>void Foo(Bar* pBar)
>{
> if(valid(pBar))
> {
> // pBar points to a valid Bar object.
> }
>}
>
>valid() could be keyword much like sizeof()in C++. The compiler would =
>require you check to make sure that a pointer was valid before =
>allowing you to use it unless of course you're going to support some =
>sort of precondition clauses like eiffel. If a precondition was that =
>the pointer had to be valid, then you wouldn't need to check it in =
>your function body.
I already thought it would like that. It can be done this way, of course; b=
ut I think it's not general enough - it covers just the case of NULL pointe=
rs and nothing else. IMO a construct should be as generally applicable as p=
ossible.
>I'm actually starting to like your idea of union types. They might =
>come in handy for functions that could possibly work on two disparate =
>types. Should it be possible to define a union of types and use that =
>union as the type?
Yes. It must be possible to use the union of types everywhere a type is all=
owed.
Example:
proc ((number | null) a) string OptionalNumberToString
{
if classOf a =3D=3D null then "" else NumberToString (a)
}
This could be the definition of a function which accepts a number or a null=
and returns a string. Of course, you would define a type
class optionalNumber : number | null
and use that in instead, for convenience. I chose the "|" symbol to denote =
a union in order to avoid confusion with the list-building symbol. ":" mean=
s "is derived from (like in C++).
>For example:
>
>union MyUnion : Foo, Bar, Baz;
>
>void doSomething(MyUnion* xxx)
>{
> // now you have to do some sort of switch on the type of xxx
>}
>
>Should you required that you declare all pointers as a union between =
>the type you want and the NULL type or should that be implied?
You would define a parameterized class from the predefined parameterized cl=
ass "ref" that does not allow NULL pointers:
class pointer <a> : ref <a> | null;
pointer <int> ptr1;
ref <int> ptr2;
ptr1 allows NULLs, ptr2 doesn't. =
BTW: I used C++ notation for the parameterized ("template") class here beca=
use I assume you are familiar with C++, but I would rather not use "<>" for=
a production syntax. My syntax could look like this:
class: pointer a =3D ref a | null
pointer int: ptr1
ref int: ptr2
On the left of the colon is the class of what you define, then comes the na=
me, then an eqal sign and the value. If something has only one parameter, y=
ou may omit the parentheses. So you could also write:
pointer (int): ptr1
I only mentioned this because you might see examples of mine using similar =
syntax. For now, every syntax is OK for discussion purposes as long as we u=
nderstand the meaning - I think we should not get involved into a discussio=
n about syntax here. =
>By the way, did you know that all of your equal ("=3D") signs are being =
>translated into "=3D3D" for some strange reason?
I suspect it must be the combination of your mail/news reader and mine, bec=
ause I never saw this before. I also notice that my line feeds seem to get =
a preceding equal sign.
>
>Bye,
>Jason.
>
>
>
>--
>Is your email secure? http://www.pop3now.com
>(c) 1998,1999 Cave Creations Corp. All rights reserved.
>
>
Do you mind if I cross-post our recent conversation to the Ultra mailing li=
st?
If we post to that list, we could let the others participate. They certainl=
y have interesting things to say.
--
Regards,
Hans-Dieter Dreier
(Hans-Dieter.Dreier@materna.de)=
--s0K7sYVmYGo9dY2m9fwxYBDXqtUOv7FY
Content-type: text/plain; charset="ISO-8859-1"
Content-transfer-encoding: quoted-printable
IDENTIFIKATIONSANGABEN:
a23805a.txt IA5 DX-MAIL X.400 User Agent=
--s0K7sYVmYGo9dY2m9fwxYBDXqtUOv7FY--