suggested improvements to D
Daniel Keep
daniel.keep+lists at gmail.com
Tue Jan 9 00:55:57 PST 2007
Warren D Smith wrote:
> Here are some suggested improvements for D.
>
> a <--> b;
> swaps a and b, same as making a tempvar t and then t=a; a=b; b=t;
> As was pointed out by Robert W. Floyd ages ago, in his Turing award
> lecture (but nobody listened) this comes up so
> often it is worth having special syntax for it.
As has been pointed out, you can write a swap function for this.
Actually, what I'd really like to see is this being made possible:
a,b = b,a;
Yet another cool thing we could steal from Python :3
> labeled break and continue statements:
> that was a fine idea to eliminate a lot of gotos.
> HOWEVER, the most common way in which gotos happen that's not covered by D's
> break and continue is this:
>
> for(some loop condition){
> if(something){ goto A; }
> }
> fallthru_code;
> A:
> break_out_code;
>
> is there a nice way to handle these without gotos? One possibility
> is to add a "default"
> block at ends of loops:
> for(some loop condition){
> if(something){ break; }
> }default{
> fallthru_code;
> }
> break_out_code;
What I've always wanted was this:
for( blah ) { ... }
else { ... }
The same thing for all loops, actually.
And while I'm here, these would be nice, too:
foreach( foo ; bar )
{
first { // Do something with first element };
else { // Do something with non-first elements };
}
> popcount and first1:
> ...
I'm sure every architecture could point to a cool opcode that isn't
directly supported in any language and go "why not?"
I won't say anything either way except: I don't really see the need.
> [Aside:
> Another excellent hardware instruction that as far as I know was never
> implemented is
> the "dovetail" and "undovetail" instructions
> which place the even-indexed bits of a word into a halfword, and the
> odd-index ones
> into another (undovetail) and dovetail is the reverse.]
I think there's some similar stuff in MMX/SSE, might be worth checking out.
> Undenying access to arithmetic:
I do agree that this is a cardinal sin of high level languages these
days, but I wouldn't say they "deny" us access. It's more a case of
"haven't worked out a good way of doing it". I mean, I'm not sure how
to take
> c = a + b;
and come up with any half-decent syntax for adding the carry bit into
the mix. Actually, I think the way most languages deal with numbers is
a bit strange: "+" in D isn't *really* addition: it just looks like it
999 times out of 1000.
So I *do* think we should be given access to things like the carry bits,
and other features like it without having to resort to assembler, but
I'm yet to see a good proposal on how to actually do so.
(Libraries aren't a great solution since one of the reasons to use the
carry bit is speed: and you just know that all those function calls
aren't helping. That reminds me: can we have expression templates? ;P)
-- Daniel
More information about the Digitalmars-d
mailing list