Thread overview | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 11, 2001 finding the class of an object | ||||
---|---|---|---|---|
| ||||
Is there a way to find out which class an object belongs to? If not, how about obj.class? BTW, I think there is a buglet in the doc: D does not have a Java style instanceof operator, because the cast operator performs the same function: Java: if (a instanceof B) D: if ((B) a) should be: if (cast(B) a) |
September 12, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Gilbert | 1) Yes, there will be a .class or some such. -Walter 2) I am undecided if the cast syntax should be like C or like cast(B) a. "James Gilbert" <jgrg@sanger.ac.uk> wrote in message news:3B9DF36F.81584272@sanger.ac.uk... > > > Is there a way to find out which class an object belongs to? If not, how about obj.class? > > BTW, I think there is a buglet in the doc: > > D does not have a Java style instanceof operator, > because the cast operator performs the same function: > > Java: > if (a instanceof B) > D: > if ((B) a) > > should be: if (cast(B) a) |
September 12, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote: > > 1) Yes, there will be a .class or some such. -Walter Great. > 2) I am undecided if the cast syntax should be like C or like cast(B) a. I like the explicit "cast". I thought you were sold on it from the doc, where you say it removes context- sensitive parsing of "()". James > "James Gilbert" <jgrg@sanger.ac.uk> wrote in message news:3B9DF36F.81584272@sanger.ac.uk... > > > > > > Is there a way to find out which class an object belongs to? If not, how about obj.class? > > > > BTW, I think there is a buglet in the doc: > > > > D does not have a Java style instanceof operator, > > because the cast operator performs the same function: > > > > Java: > > if (a instanceof B) > > D: > > if ((B) a) > > > > should be: if (cast(B) a) |
September 12, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Gilbert | In article <3B9DF36F.81584272@sanger.ac.uk>, "James Gilbert" <jgrg@sanger.ac.uk> wrote: > Is there a way to find out which class an object belongs to? If not, how about obj.class? > > BTW, I think there is a buglet in the doc: > > D does not have a Java style instanceof operator, because the cast > operator performs the same function: > > Java: > if (a instanceof B) > D: > if ((B) a) > > should be: if (cast(B) a) Doesn't this have an ambiguity if B is a boolean type variable (or int if there is no boolean)? I.e., we could be asking "Is a of type B?" or "Is a true when cast to type B?" Incidentally, I noted elsewhere that C's -> notation might not be needed in D. If you don't mind using it for something else, then casts would be a possible use: foo->long You could even introduce a new operator, =>, for instanceof so that the following are different: if (a->int)... if (a=>int)... (Properties would be another possible use: myvar->size) |
September 12, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | type? Like Foo'class or Array'length. This would provide the distinction between class members and primitive type information. There could be a Foo.class without there being any confusion. Just thought I'd offer my two cents.
Walter wrote:
> 1) Yes, there will be a .class or some such. -Walter
>
> 2) I am undecided if the cast syntax should be like C or like cast(B) a.
>
> "James Gilbert" <jgrg@sanger.ac.uk> wrote in message news:3B9DF36F.81584272@sanger.ac.uk...
> >
> >
> > Is there a way to find out which class an object belongs to? If not, how about obj.class?
> >
> > BTW, I think there is a buglet in the doc:
> >
> > D does not have a Java style instanceof operator,
> > because the cast operator performs the same function:
> >
> > Java:
> > if (a instanceof B)
> > D:
> > if ((B) a)
> >
> > should be: if (cast(B) a)
|
September 12, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to Erik Rounds | oops, sorry I guess I lost the first line. Here it is again:
Why don't we use a tick operator ' to retrieve data from a primitive
type? Like Foo'class or Array'length. This would provide the distinction
between class members and primitive type information. There could be a
Foo.class without there being any confusion. Just thought I'd offer my two
cents.
Erik Rounds wrote:
> type? Like Foo'class or Array'length. This would provide the distinction between class members and primitive type information. There could be a Foo.class without there being any confusion. Just thought I'd offer my two cents.
>
> Walter wrote:
>
> > 1) Yes, there will be a .class or some such. -Walter
> >
> > 2) I am undecided if the cast syntax should be like C or like cast(B) a.
> >
> > "James Gilbert" <jgrg@sanger.ac.uk> wrote in message news:3B9DF36F.81584272@sanger.ac.uk...
> > >
> > >
> > > Is there a way to find out which class an object belongs to? If not, how about obj.class?
> > >
> > > BTW, I think there is a buglet in the doc:
> > >
> > > D does not have a Java style instanceof operator,
> > > because the cast operator performs the same function:
> > >
> > > Java:
> > > if (a instanceof B)
> > > D:
> > > if ((B) a)
> > >
> > > should be: if (cast(B) a)
|
September 13, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to Erik Rounds | Erik Rounds wrote:
>
> oops, sorry I guess I lost the first line. Here it is again:
>
> Why don't we use a tick operator ' to retrieve data from a primitive
> type? Like Foo'class or Array'length. This would provide the distinction
> between class members and primitive type information. There could be a
> Foo.class without there being any confusion. Just thought I'd offer my two
> cents.
My $0.02 is that the tick operator plays merry hell
with syntax highlighting in editors.
James
|
September 13, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Cohen | Ben Cohen wrote: > > In article <3B9DF36F.81584272@sanger.ac.uk>, "James Gilbert" <jgrg@sanger.ac.uk> wrote: > > > Is there a way to find out which class an object belongs to? If not, how about obj.class? > > > > BTW, I think there is a buglet in the doc: > > > > D does not have a Java style instanceof operator, because the cast > > operator performs the same function: > > > > Java: > > if (a instanceof B) > > D: > > if ((B) a) > > > > should be: if (cast(B) a) > > Doesn't this have an ambiguity if B is a boolean type variable (or int if there is no boolean)? I.e., we could be asking "Is a of type B?" or "Is a true when cast to type B?" Good point. I was also thinking that an "instanceof" operator might be able to do less work than a cast to get you the answer. I suppose the compiler could work out that the cast was being used in boolean context, but this would be surpising to the programmer, and deviate from Walter's idea of a context-free compiler. > Incidentally, I noted elsewhere that C's -> notation might not be needed > in D. If you don't mind using it for something else, then casts > would be a possible use: > > foo->long > > You could even introduce a new operator, =>, for instanceof so that the following are different: > > if (a->int)... > if (a=>int)... > > (Properties would be another possible use: myvar->size) I would try to avoid operators that are used for different things in similar languages! |
September 13, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Gilbert | In article <3BA08FBC.158C9162@sanger.ac.uk>, "James Gilbert" <jgrg@sanger.ac.uk> wrote: >> Incidentally, I noted elsewhere that C's -> notation might not be needed in D. If you don't mind using it for something else, then casts would be a possible use: >> >> foo->long >> ... > I would try to avoid operators that are used for different things in similar languages! That is sensible ... but a pity to leave the notation unused! |
September 13, 2001 Re: finding the class of an object | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Gilbert | I'm sure that editors can be made to accomidate. Anyway, the point is having an operator which won't be confused with the . or -> operator. I know that the -> operator won't be used in D, but I think we should avoid using it in order to avoid confusing C++ programmers new to the language.
James Gilbert wrote:
> Erik Rounds wrote:
> >
> > oops, sorry I guess I lost the first line. Here it is again:
> >
> > Why don't we use a tick operator ' to retrieve data from a primitive
> > type? Like Foo'class or Array'length. This would provide the distinction
> > between class members and primitive type information. There could be a
> > Foo.class without there being any confusion. Just thought I'd offer my two
> > cents.
>
> My $0.02 is that the tick operator plays merry hell
> with syntax highlighting in editors.
>
> James
|
Copyright © 1999-2021 by the D Language Foundation