Alıntı ("comp.lang.c/The D Programming Language (Chris Torek)"):
>-In article 24996@cca.CCA.COM g-rh@cca.CCA.COM (Richard Harter) writes:
-}As a side point, I like the suggestion that someone made that there be
-}a fallthrough statement rather than automatic fallthrough.
In article 222965b9@ralf.home Ralf.Brown@B.GP.CS.CMU.EDU writes:
-So, you would like to have to write
-
switch(var)
-
{
-
case foo: fallthrough;
-
case bar: fallthrough;
-
case baz: fallthrough;
-
case mung: /* code to do something for all four cases */
-
}
While this would work, if we assume D has aggregate constructors,
there is a handsomer way:
switch (e) {
case [1, 2, 3, 5, 7, 13, 19, 23]: ...
}
/* syntax above is only for demonstration */
--
In-Real-Life: Chris Torek, Univ of MD Computer Science, +1 301 454 7163
(still on trantor.umd.edu because mimsy is not yet re-news-networked)
Kaynak: https://groups.google.com/d/msg/comp.lang.c/y0uGj6tHe2E/R3gJ4buDV9QJ
İlk önce bu yukarıdaki dikkatimi çekti ve D'de var...:)
Gerçi final takısını kullanmak gerekiyor ama çok daha iyisi var ki ardışık gidenler için şöyle bir örnek verilebilir:
enum Rakamlar { Sıfır, Bir, İki, Üç, Dört, Beş, Altı, Yedi, Sekiz, Dokuz }
switch (1) {
case 0: writeln(Rakamlar.Sıfır);
break;
case 1: .. case 9: for(auto rakam = Rakamlar.min;
rakam < Rakamlar.max;
rakam++, rakam.writeln) {}
break;
case 10: writeln("On");
break;
default: writeln("Bu sayıyı bilmiyorum!");
}
Ancak şunun gibi 'şeyle'r yok ve eksikliğini çekiyorum. Çünkü GoLang (http://golang.org) gibi genç dillerde vardı...
Alıntı ("comp.lang.c/The D Programming Language (Dave Sill)"):
> >Some years ago I invented the hypothetical notation "e1 ,, e2", which would be
like the comma operator in that it evaluates its left operand before its
right operand, but (unlike comma) the result would be the value of the left
operand. Look what this buys us:
'> a,, a=b /* displacement operator, like a :=:= b /
a=(b,, b=a) / a simple swap /'
x,, ++x / same as x++; but generalizable /
free(stack,, stack=stack->next) / pop stack /
stack->value,, pop(stack) / pop and return stacked value */
I like it. Nice and general, fills a gap missing in C. It's not C,
but it could be D (it should be D, not P (pee?)).
Maybe we should start a new newsgroup/mailing-list for the discussion
of such things. It seems like a lot of the current discussion here is
about things that will never make it into ANSI C such as a power
operator, `noalias' :-) et cetera. Sure would improve the S/N ratio
for those interested only in C.
=========
The opinions expressed above are mine.
"The limits of my language mean the limits of my world."
-- Ludwig Wittgenstein
Kaynak: https://groups.google.com/d/msg/comp.lang.c/y0uGj6tHe2E/FhRthsdC9R0J
--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]