www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D for Suneido

reply Pragma Tix <pragmatix orange.fr> writes:
Andrew McKinlay author of Sundeido[1] is playing around with D.
On his blog[2] he talks about problems in porting Java to D and D in 
general. A fair article, though.

1) http://www.suneido.com/
2) http://thesoftwarelife.blogspot.fr/2012/08/d-tours.html
Aug 12 2012
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 8/12/2012 10:47 AM, Pragma Tix wrote:
 Andrew McKinlay author of Sundeido[1] is playing around with D.
 On his blog[2] he talks about problems in porting Java to D and D in general. A
 fair article, though.

 1) http://www.suneido.com/
 2) http://thesoftwarelife.blogspot.fr/2012/08/d-tours.html
I suspect his problems come mostly from trying to write Java code in D.
Aug 12 2012
parent reply Pragma Tix <pragmatix orange.fr> writes:
Am 12.08.2012 20:51, schrieb Walter Bright:
 I suspect his problems come mostly from trying to write Java code in D.
Sure, but atm I have no idea what is a good D solution for the following problem. Quote Andrew : The first thing I ran into was that the lexer returns "tokens", which in the Java code are not just integer enums, but actual enum classes with fields and methods. ...... In typical new user fashion, I tried to reproduce the Java style token enum in D. (It's hard not to avoid "cutting against the grain" when learning a new language.) D does allow you to use structs for enums so it seemed this would work. But if you use structs then you lose the automatic assignment of consecutive integer values, and D struct's are value types so they aren't necessarily unique. end quote What is the D way here ?
Aug 12 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 8/12/2012 12:27 PM, Pragma Tix wrote:
 Am 12.08.2012 20:51, schrieb Walter Bright:
 I suspect his problems come mostly from trying to write Java code in D.
Sure, but atm I have no idea what is a good D solution for the following problem. Quote Andrew : The first thing I ran into was that the lexer returns "tokens", which in the Java code are not just integer enums, but actual enum classes with fields and methods. ...... In typical new user fashion, I tried to reproduce the Java style token enum in D. (It's hard not to avoid "cutting against the grain" when learning a new language.) D does allow you to use structs for enums so it seemed this would work. But if you use structs then you lose the automatic assignment of consecutive integer values, and D struct's are value types so they aren't necessarily unique. end quote What is the D way here ?
There's a whole thread here about building a lexer in D entitled "std.d.lexer requirements" and another entitled "D Lexer" which should be most helpful.
Aug 12 2012
prev sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Pragma Tix:

 2) http://thesoftwarelife.blogspot.fr/2012/08/d-tours.html
From the blog post: -----------------------
 Another minor annoyance was the lack of an equivalent to Java's 
 static import. If I want to refer to the tokens as just IF or 
 ELSE I could make them "anonymous". But then they don't have a 
 specific type. Or I can give the enum a named type, but then I 
 have to always reference them with Token.IF . In Java I could 
 say import static Token.* and then just use the bare names.<
This helps: with(Token) { // lot and lot of code here } ---------------------
One of them being that you can't store immutable objects in a 
map! Hopefully this is something they'll figure out. I 
eventually gave up on immutable and managed to get const to 
work, although even that was a struggle.<
Maybe rebindable helps: import std.typecons; immutable class A { this() immutable {} } void main() { Rebindable!(immutable(A))[int] values; values[0] = new A; } Or maybe he refers to what Object ref was trying to do. Bye, bearophile
Aug 12 2012
parent "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Sunday, 12 August 2012 at 23:35:39 UTC, bearophile wrote:
 Pragma Tix:

 2) http://thesoftwarelife.blogspot.fr/2012/08/d-tours.html
From the blog post: -----------------------
 Another minor annoyance was the lack of an equivalent to 
 Java's static import. If I want to refer to the tokens as just 
 IF or ELSE I could make them "anonymous". But then they don't 
 have a specific type. Or I can give the enum a named type, but 
 then I have to always reference them with Token.IF . In Java I 
 could say import static Token.* and then just use the bare 
 names.
 This helps:

 with(Token) {
     // lot and lot of code here
 }
Done that before :) Quite heavily in one of my sources. Glancing at the code for his lexer I wonder if the approach is right. I've only written a couple half lexers for minor projects, but he's duplicating what's in std.range & std.ascii; Also his structure and methods go twoards suggesting he's making a range but not working with D on it (next, nextAll vs front, popFront). Wouldn't an actual range for his tokens/lexer be better (which then creates/calculates and returns the current token)? I've done this once in one of my projects and it actually turned out to work very well.
Aug 12 2012