www.digitalmars.com         C & C++   DMDScript  

D - finding the class of an object

reply James Gilbert <jgrg sanger.ac.uk> writes:
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)
Sep 11 2001
next sibling parent reply "Walter" <walter digitalmars.com> writes:
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)
Sep 11 2001
next sibling parent James Gilbert <jgrg sanger.ac.uk> writes:
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)
Sep 12 2001
prev sibling parent reply Erik Rounds <erikr aatrix.com> writes:
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)
Sep 12 2001
parent reply Erik Rounds <erikr aatrix.com> writes:
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)
Sep 12 2001
parent reply James Gilbert <jgrg sanger.ac.uk> writes:
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
Sep 13 2001
next sibling parent Erik Rounds <erikr aatrix.com> writes:
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
Sep 13 2001
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
James Gilbert wrote in message <3BA08D12.894CA875 sanger.ac.uk>...
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.
The ' operator would make it impossible to tokenize the language separately from syntax analysis. Perhaps the : would work better.
Sep 18 2001
parent reply "Sean L. Palmer" <spalmer iname.com> writes:


Sean

"Walter" <walter digitalmars.com> wrote in message
news:9o99bv$a8v$1 digitaldaemon.com...
 James Gilbert wrote in message <3BA08D12.894CA875 sanger.ac.uk>...
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.
The ' operator would make it impossible to tokenize the language
separately
 from syntax analysis. Perhaps the : would work better.
Oct 23 2001
parent "Walter" <walter digitalmars.com> writes:


"Sean L. Palmer" <spalmer iname.com> wrote in message
news:9r3dsr$a27$1 digitaldaemon.com...


 Sean

 "Walter" <walter digitalmars.com> wrote in message
 news:9o99bv$a8v$1 digitaldaemon.com...
 James Gilbert wrote in message <3BA08D12.894CA875 sanger.ac.uk>...
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.
The ' operator would make it impossible to tokenize the language
separately
 from syntax analysis. Perhaps the : would work better.
Nov 23 2001
prev sibling parent reply "Ben Cohen" <bc skygate.co.uk> writes:
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)
Sep 12 2001
parent reply James Gilbert <jgrg sanger.ac.uk> writes:
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!
Sep 13 2001
parent reply "Ben Cohen" <bc skygate.co.uk> writes:
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!
Sep 13 2001
parent reply Russell Bornschlegel <kaleja estarcion.com> writes:
Ben Cohen wrote:
 
 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!
Perhaps if the parser sees a "->" token, it could open a web browser to a page titled "D for C Programmers". -RB
Sep 13 2001
parent reply "Walter" <walter digitalmars.com> writes:
Russell Bornschlegel wrote in message <3BA0E8CF.5BFDE051 estarcion.com>...
Perhaps if the parser sees a "->" token, it could open a web browser to a
page
titled "D for C Programmers".
I'm still looking for a use for the error message: "fix card deck and resubmit job"
Sep 20 2001
next sibling parent Charles Hixson <charleshixsn earthlink.net> writes:
Walter wrote:

 ...
 I'm still looking for a use for the error message:
 
     "fix card deck and resubmit job"
 
You could have a sample that implements a deck editor for FreeCell.
Sep 20 2001
prev sibling next sibling parent a <a b.c> writes:
Walter wrote:
 
 Russell Bornschlegel wrote in message <3BA0E8CF.5BFDE051 estarcion.com>...
Perhaps if the parser sees a "->" token, it could open a web browser to a
page
titled "D for C Programmers".
I'm still looking for a use for the error message: "fix card deck and resubmit job"
Display it if any variable named foo, bar, baz or foobar is used incorrectly. Dan
Sep 20 2001
prev sibling parent reply John Fletcher <J.P.Fletcher aston.ac.uk> writes:
Walter wrote:

 Russell Bornschlegel wrote in message <3BA0E8CF.5BFDE051 estarcion.com>...
Perhaps if the parser sees a "->" token, it could open a web browser to a
page
titled "D for C Programmers".
I'm still looking for a use for the error message: "fix card deck and resubmit job"
I once had a job fail because the following job had been put onto the card reader upside down, and became data for my program. FORTRAN of course, about 1970. John
Sep 21 2001
parent reply "Walter" <walter digitalmars.com> writes:
John Fletcher wrote in message <3BAAFEB8.3E001B7 aston.ac.uk>...
Walter wrote:
 Russell Bornschlegel wrote in message
<3BA0E8CF.5BFDE051 estarcion.com>...
Perhaps if the parser sees a "->" token, it could open a web browser to
a
 page
titled "D for C Programmers".
I'm still looking for a use for the error message: "fix card deck and resubmit job"
I once had a job fail because the following job had been put onto the card reader upside down, and became data for my program. FORTRAN of course,
about
1970.
It's nice to know there are some people who have been programming longer than me <g>. And yes, my first programs were on punch cards.
Oct 10 2001
parent "Rajiv Bhagwat" <dataflow vsnl.com> writes:
Walter <walter digitalmars.com> wrote in message
news:9q14m0$12ed$1 digitaldaemon.com...
 John Fletcher wrote in message <3BAAFEB8.3E001B7 aston.ac.uk>...
Walter wrote:
 Russell Bornschlegel wrote in message
<3BA0E8CF.5BFDE051 estarcion.com>...
Perhaps if the parser sees a "->" token, it could open a web browser
to
 a
 page
titled "D for C Programmers".
I'm still looking for a use for the error message: "fix card deck and resubmit job"
I once had a job fail because the following job had been put onto the
card
reader upside down, and became data for my program.  FORTRAN of course,
about
1970.
It's nice to know there are some people who have been programming longer than me <g>. And yes, my first programs were on punch cards.
I used cards in 1975, but encountered a Russian computer (Model: Minsk-2) with very hard pushbuttons in '79. These buttons would light lamps and frequently were stuck. How about some use for the message: 'Push harder, then it might work!' Ps: Not to be behind, next to the Russian m/c was a Hewlett-Packard machine, using Buttons and Lights: HP-21! The buttons here were a lot smoother and had lights behind them, as the console was very small.
Oct 10 2001