digitalmars.D.learn - How do i find a list of the methods Object implements, or maybe just
- dan (27/27) Nov 07 2017 I was writing some code and added a line like
- Adam D. Ruppe (7/11) Nov 07 2017 Did you import std.stdio in the file?
- dan (6/17) Nov 07 2017 Awesome, great, thanks Adam!!!
- codephantom (18/25) Nov 07 2017 it's interesting how the compiler deals with scope.
- bauss (2/22) Nov 07 2017 Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
- codephantom (4/6) Nov 07 2017 you saved it as?: write.d
- codephantom (5/7) Nov 07 2017 ahh.. that site saves it with some random temporary file name I
- bauss (16/24) Nov 08 2017 That's because the module name becomes `write` then.
- codephantom (17/18) Nov 08 2017 yeah I knew that.
- codephantom (2/3) Nov 08 2017 mistyped: I meant a bug in GDC, not LDC.
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
On Tuesday, 7 November 2017 at 21:25:00 UTC, dan wrote:I looked in my distribution's object.d (debian stretch, gdc, inDid 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
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: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). danI looked in my distribution's object.d (debian stretch, gdc, inDid 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
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: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); } --------------------------------------------------------------------------I looked in my distribution's object.d (debian stretch, gdc, inDid 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))
Nov 07 2017
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:Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f[...]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
On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote:you saved it as?: write.d you didn't add in a module statement? and it compiled??--------------------------------------------------------------------------Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
Nov 07 2017
On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote: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.--------------------------------------------------------------------------Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
Nov 07 2017
On Wednesday, 8 November 2017 at 03:48:58 UTC, codephantom wrote:On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote: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); } ```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.--------------------------------------------------------------------------Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f
Nov 08 2017
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
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