www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do i find a list of the methods Object implements, or maybe just

reply dan <dan.hitt gmail.com> writes:
I was writing some code and added a line like
      x.write;
expecting to fill it in later.

I forgot to actually write a function write, but it compiled 
anyway, and some testing shows that if you write
       auto o = new Object;
       o.write;
then this compiles just fine.  (The 'write' method, whatever it 
is, does not return a value, as 'auto y = o.write;' will not 
compile.)

So that presumably means that i'm about to override 'write' (when 
i finish up my class), but i have no idea what the original 
'write' does.

I looked in my distribution's object.d (debian stretch, gdc, in
/usr/lib/gcc/x86_64-linux-gnu/6/include/d/object.d) but i don't 
see anything that looks like a write method there.

I tried to do a net search, but 'write' is a very common word.

I then thought that i should just get an authoritative list of 
Object's methods, and hope something was documented there, but my 
searching for a list of for this also failed.

So i'd be grateful if somebody could tell me where i can find 
documentation on 'write' and/or what it means for an Object to 
write, and/or where i can see just what methods Object 
implements, and what those methods do.

Thanks in advance for any clues, or a pointer to page 1 of the 
manual if it's there and i'm just being dense.

dan
Nov 07 2017
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 7 November 2017 at 21:25:00 UTC, dan wrote:
 I looked in my distribution's object.d (debian stretch, gdc, in
Did you import std.stdio in the file? If so, it is calling the std.stdio.write on the object (this is called UFCS, uniform function call syntax, the language allows you to call any free function in scope with obj.foo by rewriting it to foo(obj))
 I then thought that i should just get an authoritative list of 
 Object's methods, and hope something was documented there, but 
 my searching for a list of for this also failed.
http://dpldocs.info/experimental-docs/object.Object.html
Nov 07 2017
next sibling parent dan <dan.hitt gmail.com> writes:
On Tuesday, 7 November 2017 at 21:32:26 UTC, Adam D. Ruppe wrote:
 On Tuesday, 7 November 2017 at 21:25:00 UTC, dan wrote:
 I looked in my distribution's object.d (debian stretch, gdc, in
Did you import std.stdio in the file? If so, it is calling the std.stdio.write on the object (this is called UFCS, uniform function call syntax, the language allows you to call any free function in scope with obj.foo by rewriting it to foo(obj))
 I then thought that i should just get an authoritative list of 
 Object's methods, and hope something was documented there, but 
 my searching for a list of for this also failed.
http://dpldocs.info/experimental-docs/object.Object.html
Awesome, great, thanks Adam!!! I certainly was, and that must have been what was in play. And thanks for the pointer to Object's methods (which are very few, as i thought). dan
Nov 07 2017
prev sibling parent reply codephantom <me noyb.com> writes:
On Tuesday, 7 November 2017 at 21:32:26 UTC, Adam D. Ruppe wrote:
 On Tuesday, 7 November 2017 at 21:25:00 UTC, dan wrote:
 I looked in my distribution's object.d (debian stretch, gdc, in
Did you import std.stdio in the file? If so, it is calling the std.stdio.write on the object (this is called UFCS, uniform function call syntax, the language allows you to call any free function in scope with obj.foo by rewriting it to foo(obj))
it's interesting how the compiler deals with scope. --------------------------------------------------------------------------- // save this in a file named: write.d import std.stdio; void main() { auto o = new Object; // One of statements below will prevent this code from compiling. // Which one do you think it is? // btw. If I instead use gdc on debian, then it will // compile both statements just fine, and will work as expected too. o.write; write(o); } --------------------------------------------------------------------------
Nov 07 2017
parent reply bauss <jj_1337 live.dk> writes:
On Wednesday, 8 November 2017 at 03:05:22 UTC, codephantom wrote:
 On Tuesday, 7 November 2017 at 21:32:26 UTC, Adam D. Ruppe 
 wrote:
[...]
it's interesting how the compiler deals with scope. --------------------------------------------------------------------------- // save this in a file named: write.d import std.stdio; void main() { auto o = new Object; // One of statements below will prevent this code from compiling. // Which one do you think it is? // btw. If I instead use gdc on debian, then it will // compile both statements just fine, and will work as expected too. o.write; write(o); } --------------------------------------------------------------------------
Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
Nov 07 2017
next sibling parent codephantom <me noyb.com> writes:
On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote:
 --------------------------------------------------------------------------
Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
you saved it as?: write.d you didn't add in a module statement? and it compiled??
Nov 07 2017
prev sibling parent reply codephantom <me noyb.com> writes:
On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote:
 --------------------------------------------------------------------------
Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
ahh.. that site saves it with some random temporary file name I assume. If it saved it as write.d, it likely would not compile, unless they were using gdc.
Nov 07 2017
parent reply bauss <jj_1337 live.dk> writes:
On Wednesday, 8 November 2017 at 03:48:58 UTC, codephantom wrote:
 On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote:
 --------------------------------------------------------------------------
Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
ahh.. that site saves it with some random temporary file name I assume. If it saved it as write.d, it likely would not compile, unless they were using gdc.
That's because the module name becomes `write` then. Generally you should be explicit about module names anyway, unless you have a single file for testing or something. You could get around the error using an alias: ``` module write; import std.stdio; alias write = std.stdio.write; // <<<<<< void main() { auto o = new Object; o.write; write(o); } ```
Nov 08 2017
parent reply codephantom <me noyb.com> writes:
On Wednesday, 8 November 2017 at 12:17:14 UTC, bauss wrote:
 That's because the module name becomes `write` then.
yeah I knew that. I was trying to demonstrate how (when the module name is 'write'), then the compiler is ok with: o.write; but not: write(o); even though semantically they are meant to mean the same thing. I also thought it was interesting the GDC doesn't seem to default the module namespace to the name of the file, or if it does, then it doesn't seem to have any conflict in resolving the correct namespace for the two statements(unlike DMD and LDC). Apparently its a bug in LDC (but personally, it's a bug I like). Since the original post mentioned using gdc on debian, I just wanted to point this out - because it caught be my surprise a few days ago (as I test my code across different compilers, on different platforms).
Nov 08 2017
parent codephantom <me noyb.com> writes:
On Wednesday, 8 November 2017 at 12:48:41 UTC, codephantom wrote:
 Apparently its a bug in LDC (but personally, it's a bug I like).
mistyped: I meant a bug in GDC, not LDC.
Nov 08 2017