digitalmars.D.learn - Keywords: How to trick the compiler?
- Chris (10/10) Jan 28 2014 Is there a simple way to trick the compiler (e.g. with alias), if
- Stanislav Blinov (2/2) Jan 28 2014 On Tuesday, 28 January 2014 at 11:22:10 UTC, Chris wrote:
- Chris (3/5) Jan 28 2014 Cripes! There goes my API ...
- Stanislav Blinov (2/8) Jan 28 2014 Aww, a bit of underscoring hasn't hurt anyone yet. :)
- Namespace (3/13) Jan 28 2014 Write in with an uppercase. ;)
- simendsjo (2/18) Jan 28 2014 I've also seen some people append _: body_, int_ etc.
- Andrej Mitrovic (4/8) Jan 28 2014 "body" is probably the most frequent issue I run into when porting
- Stanislav Blinov (3/7) Jan 28 2014 o_O How?
- "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= (4/6) Jan 28 2014 If "body" never appears after a ".", and is only before a "{"
- Ary Borenszweig (11/17) Jan 28 2014 Exactly: body is only a conflict when appearing alone. But after a "."
- bearophile (5/12) Jan 28 2014 Ruby is a different language from D, they define "code safety" in
- "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= (7/9) Jan 28 2014 In D I think "body" actually is redundant since in/out always
- Ary Borenszweig (2/16) Jan 28 2014 Having a method named "end" doesn't make the language less safe.
- Chris (3/23) Jan 28 2014 End is cumbersome and looks awkward. Sure there are other ways ;)
- Ary Borenszweig (3/25) Jan 29 2014 Yes, as there are other ways for body: _body, _body, Body, HtmlBody,
- Stanislav Blinov (3/5) Jan 29 2014 torso? ;)
- Chris (4/9) Jan 30 2014 offspring = document.createElement("div");
- Stanislav Blinov (2/4) Jan 30 2014 Looks great! :D
- Martin Cejp (3/11) Jan 28 2014 Not being a keyword except in places where it is used as such.
- Stanislav Blinov (7/12) Jan 28 2014 Only if it's not a keyword at all, lest you complicate parsing.
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (9/22) Feb 01 2014 It's surprisingly easy to implement, see here:
- "Casper =?UTF-8?B?RsOmcmdlbWFuZCI=?= <shorttail gmail.com> (4/8) Jan 28 2014 All my input and output streams in Java are called in and out. x.x
- Chris (7/17) Jan 28 2014 Some kind of aliasing mechanism would be nice to escape keyword
- Piotrek (4/15) Jan 28 2014 http://d.puremagic.com/issues/show_bug.cgi?id=5775
- Adam D. Ruppe (9/12) Jan 28 2014 alas, no. In my dom.d, I called that method "mainBody" instead...
Is there a simple way to trick the compiler (e.g. with alias), if a keyword conflicts with a function/method, e.g. as in a HTML document: auto docBody = document.body; // corresponding method (will not compile due to body being a keyword) property auto body() { // simplified code return this.getElementByTagName("body"); }
Jan 28 2014
On Tuesday, 28 January 2014 at 11:22:10 UTC, Chris wrote: Nope, just choose a different name.
Jan 28 2014
On Tuesday, 28 January 2014 at 11:24:33 UTC, Stanislav Blinov wrote:On Tuesday, 28 January 2014 at 11:22:10 UTC, Chris wrote: Nope, just choose a different name.Cripes! There goes my API ...
Jan 28 2014
On Tuesday, 28 January 2014 at 11:38:16 UTC, Chris wrote:On Tuesday, 28 January 2014 at 11:24:33 UTC, Stanislav Blinov wrote:Aww, a bit of underscoring hasn't hurt anyone yet. :)On Tuesday, 28 January 2014 at 11:22:10 UTC, Chris wrote: Nope, just choose a different name.Cripes! There goes my API ...
Jan 28 2014
On Tuesday, 28 January 2014 at 11:22:10 UTC, Chris wrote:Is there a simple way to trick the compiler (e.g. with alias), if a keyword conflicts with a function/method, e.g. as in a HTML document: auto docBody = document.body; // corresponding method (will not compile due to body being a keyword) property auto body() { // simplified code return this.getElementByTagName("body"); }Write in with an uppercase. ;) Int, If, Template...
Jan 28 2014
On Tuesday, 28 January 2014 at 12:25:19 UTC, Namespace wrote:On Tuesday, 28 January 2014 at 11:22:10 UTC, Chris wrote:I've also seen some people append _: body_, int_ etc.Is there a simple way to trick the compiler (e.g. with alias), if a keyword conflicts with a function/method, e.g. as in a HTML document: auto docBody = document.body; // corresponding method (will not compile due to body being a keyword) property auto body() { // simplified code return this.getElementByTagName("body"); }Write in with an uppercase. ;) Int, If, Template...
Jan 28 2014
On Tuesday, 28 January 2014 at 12:43:59 UTC, simendsjo wrote:I've also seen some people append _: body_, int_ etc.It is what current Phobos style guide suggests.
Jan 28 2014
On Tuesday, 28 January 2014 at 12:45:37 UTC, Dicebot wrote:On Tuesday, 28 January 2014 at 12:43:59 UTC, simendsjo wrote:Yes, I've used it, but don't like it. Maybe I'll opt for the uppercase solution.I've also seen some people append _: body_, int_ etc.It is what current Phobos style guide suggests.
Jan 28 2014
On 1/28/14, Chris <wendlec tcd.ie> wrote:Is there a simple way to trick the compiler (e.g. with alias), if a keyword conflicts with a function/method, e.g. as in a HTML document: auto docBody = document.body;"body" is probably the most frequent issue I run into when porting C/C++ code to D. I really wonder whether the rule could be relaxed a little bit.
Jan 28 2014
On Tuesday, 28 January 2014 at 12:57:02 UTC, Andrej Mitrovic wrote:"body" is probably the most frequent issue I run into when porting C/C++ code to D. I really wonder whether the rule could be relaxed a little bit.o_O How?
Jan 28 2014
On Tuesday, 28 January 2014 at 12:58:29 UTC, Stanislav Blinov wrote:If "body" never appears after a ".", and is only before a "{" then there is no conflict?I really wonder whether the rule could be relaxed a little bit.o_O How?
Jan 28 2014
On 1/28/14, 10:00 AM, "Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang gmail.com>" wrote:On Tuesday, 28 January 2014 at 12:58:29 UTC, Stanislav Blinov wrote:Exactly: body is only a conflict when appearing alone. But after a "." it's perfectly fine. In Ruby you can do this: class Foo def end 1 end end Foo.new.endIf "body" never appears after a ".", and is only before a "{" then there is no conflict?I really wonder whether the rule could be relaxed a little bit.o_O How?
Jan 28 2014
Ary Borenszweig:In Ruby you can do this: class Foo def end 1 end end Foo.new.endRuby is a different language from D, they define "code safety" in quite different ways. Bye, bearophile
Jan 28 2014
On Tuesday, 28 January 2014 at 14:30:36 UTC, bearophile wrote:Ruby is a different language from D, they define "code safety" in quite different ways.In D I think "body" actually is redundant since in/out always should be followed by a function body? Maybe it has more to do with parsing strategies. If you use a separate and fully independent lexer then the symbol "body" might be lost and replaced by a keyword enumeration so by tradition you reserve all keywords?
Jan 28 2014
On 1/28/14, 11:30 AM, bearophile wrote:Ary Borenszweig:Having a method named "end" doesn't make the language less safe.In Ruby you can do this: class Foo def end 1 end end Foo.new.endRuby is a different language from D, they define "code safety" in quite different ways. Bye, bearophile
Jan 28 2014
On Tuesday, 28 January 2014 at 17:18:44 UTC, Ary Borenszweig wrote:On 1/28/14, 11:30 AM, bearophile wrote:End is cumbersome and looks awkward. Sure there are other ways ;)Ary Borenszweig:Having a method named "end" doesn't make the language less safe.In Ruby you can do this: class Foo def end 1 end end Foo.new.endRuby is a different language from D, they define "code safety" in quite different ways. Bye, bearophile
Jan 28 2014
On 1/28/14, 3:17 PM, Chris wrote:On Tuesday, 28 January 2014 at 17:18:44 UTC, Ary Borenszweig wrote:Yes, as there are other ways for body: _body, _body, Body, HtmlBody, etc. But "body" is the best one.On 1/28/14, 11:30 AM, bearophile wrote:End is cumbersome and looks awkward. Sure there are other ways ;)Ary Borenszweig:Having a method named "end" doesn't make the language less safe.In Ruby you can do this: class Foo def end 1 end end Foo.new.endRuby is a different language from D, they define "code safety" in quite different ways. Bye, bearophile
Jan 29 2014
On Wednesday, 29 January 2014 at 17:11:32 UTC, Ary Borenszweig wrote:Yes, as there are other ways for body: _body, _body, Body, HtmlBody, etc. But "body" is the best one.torso? ;)
Jan 29 2014
On Wednesday, 29 January 2014 at 17:12:57 UTC, Stanislav Blinov wrote:On Wednesday, 29 January 2014 at 17:11:32 UTC, Ary Borenszweig wrote:offspring = document.createElement("div"); document.torso.addOffspring(div);Yes, as there are other ways for body: _body, _body, Body, HtmlBody, etc. But "body" is the best one.torso? ;)
Jan 30 2014
On Thursday, 30 January 2014 at 10:15:10 UTC, Chris wrote:offspring = document.createElement("div"); document.torso.addOffspring(div);Looks great! :D
Jan 30 2014
On Tuesday, 28 January 2014 at 12:58:29 UTC, Stanislav Blinov wrote:On Tuesday, 28 January 2014 at 12:57:02 UTC, Andrej Mitrovic wrote:Not being a keyword except in places where it is used as such."body" is probably the most frequent issue I run into when porting C/C++ code to D. I really wonder whether the rule could be relaxed a little bit.o_O How?
Jan 28 2014
On Tuesday, 28 January 2014 at 22:35:31 UTC, Martin Cejp wrote:Only if it's not a keyword at all, lest you complicate parsing. You wouldn't want any other keyword (I dunno, int?) get a special treatment now, would you? Don't get me wrong, I'm all for allowing to use "body" as an identifier in user code, I just don't see any half-measures in that regard :)Not being a keyword except in places where it is used as such.I really wonder whether the rule could be relaxed a little bit.o_O How?
Jan 28 2014
On Tuesday, 28 January 2014 at 22:50:27 UTC, Stanislav Blinov wrote:On Tuesday, 28 January 2014 at 22:35:31 UTC, Martin Cejp wrote:It's surprisingly easy to implement, see here: https://github.com/schuetzm/dmd/commit/955be4ef9f26e92f7a0d5dedf86b64a03d903be8 It requires only a few trivial changes to the compiler, but I have to admit that it makes the code uglier. In particular, it doesn't scale; every keyword treated in this way requires additional special handling. I'm not sure whether I should make a PR from this...Only if it's not a keyword at all, lest you complicate parsing. You wouldn't want any other keyword (I dunno, int?) get a special treatment now, would you? Don't get me wrong, I'm all for allowing to use "body" as an identifier in user code, I just don't see any half-measures in that regard :)Not being a keyword except in places where it is used as such.I really wonder whether the rule could be relaxed a little bit.o_O How?
Feb 01 2014
On Tuesday, 28 January 2014 at 12:57:02 UTC, Andrej Mitrovic wrote:"body" is probably the most frequent issue I run into when porting C/C++ code to D. I really wonder whether the rule could be relaxed a little bit.All my input and output streams in Java are called in and out. x.x Reminds me of max and min in competitive programming in C++.
Jan 28 2014
On Tuesday, 28 January 2014 at 16:14:48 UTC, Casper Færgemand wrote:On Tuesday, 28 January 2014 at 12:57:02 UTC, Andrej Mitrovic wrote:Some kind of aliasing mechanism would be nice to escape keyword restrictions. It's a bit awkward to have document.body_ or document.Body or whatnot. But I guess it's not trivial to implement that without breaking code safety and parsing mechanisms."body" is probably the most frequent issue I run into when porting C/C++ code to D. I really wonder whether the rule could be relaxed a little bit.All my input and output streams in Java are called in and out. x.x Reminds me of max and min in competitive programming in C++.
Jan 28 2014
On Tuesday, 28 January 2014 at 12:57:02 UTC, Andrej Mitrovic wrote:On 1/28/14, Chris <wendlec tcd.ie> wrote:http://d.puremagic.com/issues/show_bug.cgi?id=5775 Actually I'm still wainting for body release ;)Is there a simple way to trick the compiler (e.g. with alias), if a keyword conflicts with a function/method, e.g. as in a HTML document: auto docBody = document.body;"body" is probably the most frequent issue I run into when porting C/C++ code to D. I really wonder whether the rule could be relaxed a little bit.
Jan 28 2014
On Tuesday, 28 January 2014 at 11:22:10 UTC, Chris wrote:Is there a simple way to trick the compiler (e.g. with alias), if a keyword conflicts with a function/method, e.g. as in a HTML document:alas, no. In my dom.d, I called that method "mainBody" instead... If you are accessing a C function called body, you can access it using pragma mangle: pragma(mangle, "body") void cBody() { } Still can't call it "body" in D, so have to add something, but the pragma mangle will make the name match up for the linker so it refers to the same C function.
Jan 28 2014