The D Scripting Language

Per Ångström d-news at autark.se
Mon Nov 15 04:15:50 PST 2010


On 2010-11-07 22:29, Tomek Sowiński wrote:
> This wraps up a thread from a few days ago. Pascal featured my D
> examples on his Scriptometer site.
>
> http://rigaux.org/language-study/scripting-language/
>
> D comes 17th out of 28, so it's so-so for scripting.
>
I'm wondering whether the issue of D's or-expression, compared to that 
of languages such as Perl and Ruby, has been discussed and dismissed.

Personally, I was a bit disappointed to learn that D had such a 
traditional or-expression, seeing how much it is willing to improve over 
C/C++ in other areas.

I think the following code summarizes the issue. I'm not a language 
lawyer, so maybe the rules could be described more succinctly, but I 
think you'll get my drift. I'm aware that with D being a typed and 
compiled language, there has to a be a restriction that both 
sub-expressions must be convertible to a common type, but I'm sure that 
can be worked out somehow.

string func(string s)
{
     /++
     // A handy feature of many scripting languages, but not in D
     // (in D, the type of the or-expression is bool):
     // The type of the or-expression is the type of the first
     // sub-expression that evaluates to true.
     return s || "default";
     +/
     // The D equivalent, arguably more readable but also more verbose:
     return s ? s : "default";
}

void main()
{
     assert(func("a") == "a");
     assert(func(null) == "default");
}
-- 
Per Å.


More information about the Digitalmars-d mailing list