www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Can you do this in D?

reply "Wes" <ffhighwind hotmail.com> writes:
Can you do this in D? If not then what other language?

1. Can you get a list of all classes and variables in the current
scope e.g. __traits()?

2. Can you statically iterate over every field of a class?
It seems like the only returns are string lists from __traits().
I basically am interested in being able to generate a
PrettyPrint/Serializable/Hash template without passing in every
single field.

3. Is there any way of executing code or programs during compile
time?
I've seen an example of CTFE (Compile Time Function Evaluation),
although I'm unsure if this works for stuff like classes.
However, I am considering more advanced execution (not constants)
such as printing to a file during compiling for stuff like how
long compiling a certain function/template takes.

4. Is there anything like Go/Erlang channels? (synchronous queues)
I assume that synchronized blocks with a shared global dynamic
array would be the solution without the special syntax sugar?


This is more of a rhetorical... as I know the language doesn't
need them, nor would I know if they would be binary/unary
prefix/etc or the precedence... although they would be nice to
have. Specifically I'd like $prefix to be stringification.
Jul 26 2012
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Wes:

 Can you do this in D? If not then what other language?
Maybe CommonLisp and Scheme (and maybe Clojure) are able to do what you ask for (but normally they don't have the stringification with $).
 1. Can you get a list of all classes and variables in the 
 current scope e.g. __traits()?
I think it's a missing feature. But what are the use cases? In Python it's easy to do, but it's not a common need.
 2. Can you statically iterate over every field of a class?
 It seems like the only returns are string lists from __traits().
 I basically am interested in being able to generate a
 PrettyPrint/Serializable/Hash template without passing in every
 single field.
With their names and mixin() then maybe you able to do what you look for.
 3. Is there any way of executing code or programs during compile
 time?
Only CTFE.
 I've seen an example of CTFE (Compile Time Function Evaluation),
 although I'm unsure if this works for stuff like classes.
CTFE now works with classes too.
 However, I am considering more advanced execution (not 
 constants)
 such as printing to a file during compiling for stuff like how
 long compiling a certain function/template takes.
With the proposed __ctWrtiteln you are able to print things at compile time to standard output. But there is no enough introspection to know how much time it takes to compile part of a program.

 This is more of a rhetorical... as I know the language doesn't
 need them, nor would I know if they would be binary/unary
 prefix/etc or the precedence... although they would be nice to
 have. Specifically I'd like $prefix to be stringification.
The operator overloading syntax is string-based, so adding new operators is not too much hard. But I don't know what are the advantages and disadvantages. The $ operator is used (in a certain context) to denote the length of collections. Bye, bearophile
Jul 26 2012
next sibling parent reply "Wes" <ffhighwind hotmail.com> writes:
 I think it's a missing feature. But what are the use cases? In 
 Python it's easy to do, but it's not a common need.
True, I suppose. It just seems like the programmer could have access to some sort of associative array, where you could have multiple stored values per key sorted by scope.
 With their names and mixin() then maybe you able to do what you 
 look for.
So basically there's no easy way to make a prettyprint like: foreach(field;__traits(allFields, myClass)) { str ~= field; }
 With the proposed __ctWrtiteln you are able to print things at 
 compile time to standard output. But there is no enough 
 introspection to know how much time it takes to compile part of 
 a program.
Assuming this is the same as #pragma (msg, ""). I just meant actually calling code that runs at compile time that isn't a static-ly defined constant.
 The operator overloading syntax is string-based, so adding new 
 operators is not too much hard. But I don't know what are the 
 advantages and disadvantages. The $ operator is used (in a 
 certain context) to denote the length of collections.
I'm not sure what you mean. Do you mean I can go edit the open source compiler and add in my own language feature? Or does the ability to add a $/ operator already exist?
Jul 26 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Wes:

 So basically there's no easy way to make a prettyprint like:
 foreach(field;__traits(allFields, myClass)) { str ~= field; }
I am saying that probably there is a way, using mixins.
 Assuming this is the same as #pragma (msg, "").
It's not the same. It's usable just like a writeln, but in CTFE too. pragma(msg) has a different behavour, and happens in a different compilation stage.
 I'm not sure what you mean. Do you mean I can go edit the open 
 source compiler and add in my own language feature? Or does the 
 ability to add a $/  operator already exist?
I mean that D compiler writers don't need to introduce new syntax to add that feature. But I don't see lot of people asking for it. Bye, bearophile
Jul 26 2012
parent travert phare.normalesup.org (Christophe Travert) writes:
"bearophile" , dans le message (digitalmars.D:173297), a écrit :
 I'm not sure what you mean. Do you mean I can go edit the open 
 source compiler and add in my own language feature? Or does the 
 ability to add a $/  operator already exist?
I mean that D compiler writers don't need to introduce new syntax to add that feature. But I don't see lot of people asking for it.
The $ prefix operator *is* a new syntax. It impacts the lexer and parser and they would have to create new precedence rules. The only think that already exists is the syntax to overload such operator, if it existed. I don't see anything like new operators comming in the langage before long. -- Christophe
Jul 26 2012
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 7/26/12 7:44 AM, bearophile wrote:
 Wes:

 Can you do this in D? If not then what other language?
Maybe CommonLisp and Scheme (and maybe Clojure) are able to do what you ask for (but normally they don't have the stringification with $).
 1. Can you get a list of all classes and variables in the current
 scope e.g. __traits()?
I think it's a missing feature. But what are the use cases? In Python it's easy to do, but it's not a common need.
What happened to __traits(allMembers, module_name)? It doesn't list the contents of the current scope, but instead that of a module (including the current one).
 2. Can you statically iterate over every field of a class?
 It seems like the only returns are string lists from __traits().
 I basically am interested in being able to generate a
 PrettyPrint/Serializable/Hash template without passing in every
 single field.
With their names and mixin() then maybe you able to do what you look for.
 3. Is there any way of executing code or programs during compile
 time?
Only CTFE.
The OP is likely new to the community, so throwing acronyms around may not be helpful. CTFE stands for Compile-Time Function Evaluation. In short you get to evaluate a subset of D during compilation if you force a function call in a static evaluation context, such as initializing an enum or a static. Andrei
Jul 26 2012
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 7/26/12, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:
 The OP is likely new to the community, so throwing acronyms around may
 not be helpful.
http://dlang.org/glossary.html Now if someone would stop fiddling with the damn javascript which keeps erroring out.. I'm beginning to join the Nick camp w.r.t. JS. :p
Jul 26 2012
parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Thu, 26 Jul 2012 17:17:39 +0200
Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:

 On 7/26/12, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:
 The OP is likely new to the community, so throwing acronyms around
 may not be helpful.
http://dlang.org/glossary.html Now if someone would stop fiddling with the damn javascript which keeps erroring out.. I'm beginning to join the Nick camp w.r.t. JS. :p
JavaScript is a technology (from the makers of clearly the greatest web browser of all time - Netscape) whose primary usage, and indeed killer feature, is to enable people to develop new and exciting ways to make the web slower, more broken, and more obnoxious than could ever be achieved with mere HTML/CSS alone. This, of course, is a major win for humanity in general, and is something we can all be proud of. http://semitwist.com/articles/article/view/my-awesome-web-development-game
Jul 26 2012
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Jul 26, 2012 at 05:59:08PM -0400, Nick Sabalausky wrote:
 On Thu, 26 Jul 2012 17:17:39 +0200
 Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:
[...]
 Now if someone would stop fiddling with the damn javascript which
 keeps erroring out.. I'm beginning to join the Nick camp w.r.t. JS.
 :p
JavaScript is a technology (from the makers of clearly the greatest web browser of all time - Netscape) whose primary usage, and indeed killer feature, is to enable people to develop new and exciting ways to make the web slower, more broken, and more obnoxious than could ever be achieved with mere HTML/CSS alone. This, of course, is a major win for humanity in general, and is something we can all be proud of. http://semitwist.com/articles/article/view/my-awesome-web-development-game
I'm guilty of turning <i> into <em>, actually. You may shoot me now. (Actually, I resisted many attempts at introducing bold and italics buttons on my web-based editing page. I even introduced a way of indicating which table cells are headers, so that styling will work properly instead of half-assed manual bolding. But no, the users clamored for bold and italics until they threatened to mob me (ok, that last part may be an exaggeration), and so the horrible bold/italics buttons appeared. So far, I've resisted adding a "red" button (apparently, bold and italics aren't enough, sometimes you want something in RED too). I managed to evade that one by having a select box for the status field of the items, one option of which is styled red, and insisting that's the only place red is allowed. We'll see how long I hold out on that one.) T -- Those who don't understand Unix are condemned to reinvent it, poorly.
Jul 26 2012
parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Thu, 26 Jul 2012 16:06:47 -0700
"H. S. Teoh" <hsteoh quickfur.ath.cx> wrote:

 On Thu, Jul 26, 2012 at 05:59:08PM -0400, Nick Sabalausky wrote:
 On Thu, 26 Jul 2012 17:17:39 +0200
 Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:
[...]
 Now if someone would stop fiddling with the damn javascript which
 keeps erroring out.. I'm beginning to join the Nick camp w.r.t.
 JS. :p
JavaScript is a technology (from the makers of clearly the greatest web browser of all time - Netscape) whose primary usage, and indeed killer feature, is to enable people to develop new and exciting ways to make the web slower, more broken, and more obnoxious than could ever be achieved with mere HTML/CSS alone. This, of course, is a major win for humanity in general, and is something we can all be proud of. http://semitwist.com/articles/article/view/my-awesome-web-development-game
I'm guilty of turning <i> into <em>, actually. You may shoot me now.
Heh, yea, I've actually done it too (in hand-written HTML though, not mechanically). You know, just following standard recommended practices. Then it hit me: "WTF am I doing this for? My whole *intent* is for this to be bold/italic, why am I beating around the bush? Just use <b>/<i> and be done with it, Nick!" Now my posts are filled with <b> and <i> tags, and maybe it's just my hunger for rebelling, but I've never had a problem with it and I couldn't be happier :)
 (Actually, I resisted many attempts at introducing bold and italics
 buttons on my web-based editing page. I even introduced a way of
 indicating which table cells are headers, so that styling will work
 properly instead of half-assed manual bolding. But no, the users
 clamored for bold and italics until they threatened to mob me (ok,
 that last part may be an exaggeration), and so the horrible
 bold/italics buttons appeared. So far, I've resisted adding a "red"
 button (apparently, bold and italics aren't enough, sometimes you want
 something in RED too). I managed to evade that one by having a select
 box for the status field of the items, one option of which is styled
 red, and insisting that's the only place red is allowed. We'll see how
 long I hold out on that one.)
 
Yea, there's certainly benefits to semantic tagging, but I think it's become too religious and under-pragmatic. I would draw the line at "I want blinking/scrolling text" though ;)
Jul 26 2012
prev sibling next sibling parent Brad Anderson <eco gnuk.net> writes:
On Thu, Jul 26, 2012 at 9:17 AM, Andrej Mitrovic <andrej.mitrovich gmail.com
 wrote:
 On 7/26/12, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:
 The OP is likely new to the community, so throwing acronyms around may
 not be helpful.
http://dlang.org/glossary.html Now if someone would stop fiddling with the damn javascript which keeps erroring out.. I'm beginning to join the Nick camp w.r.t. JS. :p
What are the errors and what browser (with version) are you using? There were errors in the Chrome Beta release until recently (they stopped after we updated hyphenator.js). I just tested in: - Chrome 21.0.1180.55 - Firefox 8.0.1 - Firefox 12.0 - Firefox 14.0.1 - Opera 10.63 - Opera 12.00 - IE 9.0.8112.16421 and saw nothing wrong.
Jul 26 2012
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-07-26 16:53, Andrei Alexandrescu wrote:

 What happened to __traits(allMembers, module_name)? It doesn't list the
 contents of the current scope, but instead that of a module (including
 the current one).
It can be used on classes and structs (I assume) as well, -- /Jacob Carlborg
Jul 26 2012
prev sibling parent reply captaindet <2krnk gmx.net> writes:
 What happened to __traits(allMembers, module_name)? It doesn't list
 the contents of the current scope, but instead that of a module
 (including the current one).
that could have saved me too ... now i tried getting it working, but to no avail. i mean, __traits(allMembers, X) works for class X fine, but fails on modules. using dmd 2.059 for win and some 2.060-ish phobos from some weeks ago. could anyone provide a working code example pls? cheers, det
Jul 29 2012
parent captaindet <2krnk gmx.net> writes:
On 2012-07-30 00:11, captaindet wrote:
 What happened to __traits(allMembers, module_name)? It doesn't list
 the contents of the current scope, but instead that of a module
 (including the current one).
that could have saved me too ... now i tried getting it working, but to no avail. i mean, __traits(allMembers, X) works for class X fine, but fails on modules. using dmd 2.059 for win and some 2.060-ish phobos from some weeks ago. could anyone provide a working code example pls? cheers, det
my bad, figured it out
Jul 30 2012
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-07-26 13:20, Wes wrote:
 Can you do this in D? If not then what other language?
I'm pretty sure you can do all this using Ruby.
 1. Can you get a list of all classes and variables in the current
 scope e.g. __traits()?
In general, no. But you can get a list of all members in a module or class scope. Just use __traits(allMembers, ...);
 2. Can you statically iterate over every field of a class?
 It seems like the only returns are string lists from __traits().
 I basically am interested in being able to generate a
 PrettyPrint/Serializable/Hash template without passing in every
 single field.
Yes, if __traits doesn't work it works with .tupleof. For serialization Orange is available: https://github.com/jacob-carlborg/orange
 3. Is there any way of executing code or programs during compile
 time?
 I've seen an example of CTFE (Compile Time Function Evaluation),
 although I'm unsure if this works for stuff like classes.
 However, I am considering more advanced execution (not constants)
 such as printing to a file during compiling for stuff like how
 long compiling a certain function/template takes.
Classes should work. It's not possible to print to a file.
 4. Is there anything like Go/Erlang channels? (synchronous queues)
 I assume that synchronized blocks with a shared global dynamic
 array would be the solution without the special syntax sugar?
I'm not sure. but you could have a look at std.concurrency. std.parallelism might be of interest as well. This seems to good to read as well: http://www.informit.com/articles/article.aspx?p=1609144 -- /Jacob Carlborg
Jul 26 2012
parent reply "Wes" <ffhighwind hotmail.com> writes:
 In general, no. But you can get a list of all members in a 
 module or class scope. Just use __traits(allMembers, ...);
The allMembers example was lacking fields. It only showed methods, so I wasn't really sure. The problem with it was that it returned strings. I suppose I can still use them in a mixin.
 Yes, if __traits doesn't work it works with .tupleof. For 
 serialization Orange is available:

 https://github.com/jacob-carlborg/orange
Awesome. Definitely sounds like what I'm looking for.
Jul 26 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-07-26 14:17, Wes wrote:
 In general, no. But you can get a list of all members in a module or
 class scope. Just use __traits(allMembers, ...);
The allMembers example was lacking fields. It only showed methods, so I wasn't really sure. The problem with it was that it returned strings. I suppose I can still use them in a mixin.
If you want to access the fields of a class or struct you can use .tupleof: class Foo { int a; } Foo.tupleof; You can have a look how this is used in my serialization library Orange: https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L188 Interesting templates/functions would be: * hasField * fieldsOf * TypeOfField * nameOfFieldAt * setValueOfField * getValueOfField -- /Jacob Carlborg
Jul 26 2012
prev sibling parent "David Nadlinger" <see klickverbot.at> writes:
On Thursday, 26 July 2012 at 12:17:23 UTC, Wes wrote:
 In general, no. But you can get a list of all members in a 
 module or class scope. Just use __traits(allMembers, ...);
The allMembers example was lacking fields. It only showed methods, so I wasn't really sure. The problem with it was that it returned strings. I suppose I can still use them in a mixin.
If you don't want to use mixins, you can also use __traits(getMember, instance, name). mixin("instance." ~ name) is shorter, though. David
Jul 27 2012
prev sibling next sibling parent reply "David Piepgrass" <qwertie256 gmail.com> writes:
 3. Is there any way of executing code or programs during compile
 time?
 I've seen an example of CTFE (Compile Time Function Evaluation),
 although I'm unsure if this works for stuff like classes.
 However, I am considering more advanced execution (not 
 constants)
 such as printing to a file during compiling for stuff like how
 long compiling a certain function/template takes.
You can call any safe and pure D code at compile time (none of the code has to be marked pure explicitly, but it cannot access any static or global variables, call C code, access files, etc.) This is called CTFE=Compile-Time Function Evaluation. The "pure" limitation isn't a huge restriction, since you can still edit member variables (fields) and the compiler can memoize the results of CTFE... although I don't know if it memoizes automatically, or if you have to use a template to accomplish it. For example if I do enum twoPi = computePi() + computePi(); I don't know if the compiler computes PI once or twice. Does someone know? But if I define this template: property auto memoize(T, T code)() { return code; } enum twoPi = memoize!(double,computePi()) + memoize!(double,computePi()); Then computePi is surely called only once, and thus you can cache the result of any computation for repeated use. (I don't know how to get the type 'double' to be inferred automatically, though.) You can also, of course, use enums for this purpose: enum pi = computePi(); // computed only once enum twoPi = pi + pi; I don't think you can run "programs" at compile-time, but since you can call ordinary functions and use arbitrarily large structs, you can accomplish a lot. I believe the current released build, 2.059, can't use classes at compile time, but bearophile just implied that 2.060 can.

 This is more of a rhetorical... as I know the language doesn't
 need them, nor would I know if they would be binary/unary
 prefix/etc or the precedence... although they would be nice to
 have. Specifically I'd like $prefix to be stringification.
Just to clarify, because other people are making it sound like D could do this... no, D does not offer user-defined operators, only overloading of predefined operators. User-defined ops would certainly be a nice feature that I would like to have, but the D developers have too much to do already. Personally I think the D syntax and rules feel too ad-hoc and unintuitive right now; it should be simplified slightly, formalized more clearly, and debugged further before yet more features are piled on.
Jul 26 2012
parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Thu, 26 Jul 2012 19:35:56 +0200
"David Piepgrass" <qwertie256 gmail.com> wrote:
 For example if I do
 
 enum twoPi = computePi() + computePi();
 
 I don't know if the compiler computes PI once or twice. Does 
 someone know? But if I define this template:
 
You could toss a ctfeWriteln (or whatever it's named) into 'computePi' and find out. It shouldn't NEED to evaluate it twice since CTFE isn't allowed to have any global mutable state.
Jul 26 2012
prev sibling next sibling parent reply "Araq" <rumpf_a web.de> writes:
On Thursday, 26 July 2012 at 11:20:35 UTC, Wes wrote:
 Can you do this in D? If not then what other language?
Nimrod (http://nimrod-code.org/) can do 2, 3, 4, 5 of your list. (1 is planned.) 2 can be done very efficiently directly for tuples; for classes it can currently only be done with RTTI. And Nimrod uses $ for stringification. ;-)
Jul 26 2012
parent reply "David Nadlinger" <see klickverbot.at> writes:
On Thursday, 26 July 2012 at 19:02:15 UTC, Araq wrote:
 ;-)
Further context: Araq is the guy behind Nimrod. Man, we should totally infiltrate their forums as well. David, serious as ever
Jul 26 2012
parent reply "Araq" <rumpf_a web.de> writes:
On Thursday, 26 July 2012 at 19:38:41 UTC, David Nadlinger wrote:
 On Thursday, 26 July 2012 at 19:02:15 UTC, Araq wrote:
 ;-)
Further context: Araq is the guy behind Nimrod. Man, we should totally infiltrate their forums as well. David, serious as ever
He explicitely asked about other programming languages...
Jul 26 2012
next sibling parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Thu, 26 Jul 2012 21:44:24 +0200, Araq <rumpf_a web.de> wrote:

 On Thursday, 26 July 2012 at 19:38:41 UTC, David Nadlinger wrote:
 On Thursday, 26 July 2012 at 19:02:15 UTC, Araq wrote:
 ;-)
Further context: Araq is the guy behind Nimrod. Man, we should totally infiltrate their forums as well. David, serious as ever
He explicitely asked about other programming languages...
That's it! He's using logic against us! We're just pulling your leg, Araq. This reminds me, I should perhaps do more with Nimrod than just install it... -- Simen
Jul 26 2012
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/26/2012 12:44 PM, Araq wrote:
 He explicitely asked about other programming languages...
Araq, you are welcome here.
Jul 26 2012
parent reply "David Nadlinger" <see klickverbot.at> writes:
On Thursday, 26 July 2012 at 23:57:32 UTC, Walter Bright wrote:
 On 7/26/2012 12:44 PM, Araq wrote:
 He explicitely asked about other programming languages...
Araq, you are welcome here.
Yes, of course. If anything, I'd wish there was _more_ interaction between PL communities, not less. My post was just an attempt at a little humor – I hoped this was clear from the, uhm, style. David
Jul 26 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 7/26/2012 11:59 PM, David Nadlinger wrote:
 On Thursday, 26 July 2012 at 23:57:32 UTC, Walter Bright wrote:
 On 7/26/2012 12:44 PM, Araq wrote:
 He explicitely asked about other programming languages...
Araq, you are welcome here.
Yes, of course. If anything, I'd wish there was _more_ interaction between PL communities, not less. My post was just an attempt at a little humor – I hoped this was clear from the, uhm, style.
No problem, I just wanted to make sure there was no misunderstanding.
Jul 27 2012
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/26/2012 4:20 AM, Wes wrote:

 This is more of a rhetorical... as I know the language doesn't
 need them, nor would I know if they would be binary/unary
 prefix/etc or the precedence... although they would be nice to
 have.
The question shouldn't be framed as "why not X?" but as "does the utility of having X justify placing in in the language?"
 Specifically I'd like $prefix to be stringification.
Can you please be more specific about what this might do?
Jul 26 2012
next sibling parent reply "Wes" <ffhighwind hotmail.com> writes:
On Thursday, 26 July 2012 at 23:55:29 UTC, Walter Bright wrote:
 On 7/26/2012 4:20 AM, Wes wrote:

 This is more of a rhetorical... as I know the language doesn't
 need them, nor would I know if they would be binary/unary
 prefix/etc or the precedence... although they would be nice to
 have.
The question shouldn't be framed as "why not X?" but as "does the utility of having X justify placing in in the language?"
 Specifically I'd like $prefix to be stringification.
Can you please be more specific about what this might do?
It's not for more functionality but more for programmer usability and terse coding. I just noticed the .stringof being used in some typing. I was starting development of my own language, and looked more at what I could do with D and saw that it included pretty much everything I wanted, except the stuff I've mentioned. I wanted my language to stretch the boundaries of language/compiler or metaprogramming. The following are potential features/lackings of the language (no offense to the language developers as I am very impressed overall): 1. It has *practically forces use of the GC, since turning it off means I can't use many features of the language. This isn't as big of a deal to me as it is to many C++ devs (my assumption). A GC gives the impression of slow managed, even if the language isn't scripted/bytecode. operators or different variable attributes like myconst). I don't see this as a major flaw as I don't know of any other language other than scheme/lisp/ratchet that allow this. 3. It can't run *all* forms of code at compile time. 4. It doesn't have a simple prettyprint operator. I think .stringof is a big step forward from .ToString() for simplicity, but obviously $variable would be more terse. 5. It doesn't have a way to iterate over every id in scope. I can't think of a good reason to do this anyway.
Jul 26 2012
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/26/2012 6:18 PM, Wes wrote:
 1. It has *practically forces use of the GC, since turning it off means I can't
 use many features of the language. This isn't as big of a deal to me as it is
to
 many C++ devs (my assumption). A GC gives the impression of slow managed, even
 if the language isn't scripted/bytecode.
C++ doesn't have features that would require a GC - not using the GC in D does not mean the language is crippled to be less than C++.

 different variable attributes like myconst).
 I don't see this as a major flaw as I don't know of any other language other
 than scheme/lisp/ratchet that allow this.
We've explicitly decided not to do user defined syntax.
 3. It can't run *all* forms of code at compile time.

 4. It doesn't have a simple prettyprint operator. I think .stringof is a big
 step forward from .ToString() for simplicity, but obviously $variable would be
 more terse.

 5. It doesn't have a way to iterate over every id in scope.
 I can't think of a good reason to do this anyway.
We try not to add features just because we can - we try to do ones only if they have compelling use cases.
Jul 26 2012
parent =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <alex lycus.org> writes:
On 27-07-2012 06:56, Walter Bright wrote:
 On 7/26/2012 6:18 PM, Wes wrote:
 1. It has *practically forces use of the GC, since turning it off
 means I can't
 use many features of the language. This isn't as big of a deal to me
 as it is to
 many C++ devs (my assumption). A GC gives the impression of slow
 managed, even
 if the language isn't scripted/bytecode.
C++ doesn't have features that would require a GC - not using the GC in D does not mean the language is crippled to be less than C++.
new and assert both result in GC allocation and are not easily replaced with functions that use manual memory management. You have to replace functions in druntime to get the desired effect. druntime isn't part of the language specification, so, strictly speaking, not using the GC in D /does/ make the language slightly more crippled than C++.

 operators or
 different variable attributes like myconst).
 I don't see this as a major flaw as I don't know of any other language
 other
 than scheme/lisp/ratchet that allow this.
We've explicitly decided not to do user defined syntax.
 3. It can't run *all* forms of code at compile time.

 4. It doesn't have a simple prettyprint operator. I think .stringof is
 a big
 step forward from .ToString() for simplicity, but obviously $variable
 would be
 more terse.

 5. It doesn't have a way to iterate over every id in scope.
 I can't think of a good reason to do this anyway.
We try not to add features just because we can - we try to do ones only if they have compelling use cases.
-- Alex Rønne Petersen alex lycus.org http://lycus.org
Jul 26 2012
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-07-27 03:18, Wes wrote:

 4. It doesn't have a simple prettyprint operator. I think .stringof is a
 big step forward from .ToString() for simplicity, but obviously
 $variable would be more terse.
.stringof is not the equivalent to .ToString(). .stringof is more of a compile time language feature. It turns an expression into a string: import std.stdio; void main () { string foo = "bar"; writeln(foo.stringof); writeln((3 + 4).stringof); } The above code will print: foo 3 + 4 The equivalent to .ToString() in D would be .toString() or to!(string)(variable).
 5. It doesn't have a way to iterate over every id in scope.
 I can't think of a good reason to do this anyway.
There could be a couple of reasons for doing this. For example creating a DSL. -- /Jacob Carlborg
Jul 26 2012
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-07-27 01:55, Walter Bright wrote:




  > Specifically I'd like $prefix to be stringification.

 Can you please be more specific about what this might do?
If I understand him correctly I think: $variable Would be the same as: to!(string)(variable) And/or: "foo $variable bar" Would be the same as: "foo " ~ to!(string)(variable) ~ " bar" The later would be string interpolation. -- /Jacob Carlborg
Jul 26 2012