Jump to page: 1 2
Thread overview
finding the class of an object
Sep 11, 2001
James Gilbert
Sep 12, 2001
Walter
Sep 12, 2001
James Gilbert
Sep 12, 2001
Erik Rounds
Sep 12, 2001
Erik Rounds
Sep 13, 2001
James Gilbert
Sep 13, 2001
Erik Rounds
Sep 19, 2001
Walter
Oct 23, 2001
Sean L. Palmer
Nov 23, 2001
Walter
Sep 12, 2001
Ben Cohen
Sep 13, 2001
James Gilbert
Sep 13, 2001
Ben Cohen
Sep 20, 2001
Walter
Sep 20, 2001
Charles Hixson
Sep 21, 2001
a
Sep 21, 2001
John Fletcher
Oct 10, 2001
Walter
Oct 10, 2001
Rajiv Bhagwat
September 11, 2001

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
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
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
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
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
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
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
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
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
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

« First   ‹ Prev
1 2