Archetype language
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sun Mar 20 11:53:18 PDT 2011
On 3/20/11, bearophile <bearophileHUGS at lycos.com> wrote:
> The idea of optional curly braces for functions with 1 expression inside
> (just a return):
> int foo(int x) return x * x;
> Instead of:
> int foo(int x) { return x * x; }
>
Cute. Nice reason to keep the semicolon.
> It is similar to a syntax like:
> foreach (x; 0 .. 10) y *= x;
> Instead of:
> foreach (x; 0 .. 10) { y *= x; }
Not so cute (to me). I'd prefer that syntax only in one-liner function
definitions.
> In Archetype (and maybe C# too) delegates support the + and += operators.
> When you add two delegates, they get chained. When you call the result of
> the sum, both get called, in sequence. Probably this is handy to attach
> chains of callbacks to GUI elements.
How is this different from an array of delegates?
void GUIDoSomething(int delegate(int, int) delegates[])
{
int _x, _y;
foreach (deleg; delegates)
{
deleg(_x, _y);
}
}
void main()
{
int delegate(int x, int y)[] delegates;
delegates ~= (int x, int y) { return x + y;};
delegates ~= (int x, int y) { return x - y;};
GUIDoSomething(delegates);
}
Granted you can't do `deleg1 ~ deleg2`. But a delegate should be a
single quantity, not a hidden sequence of multiple delegates. That's
what arrays are for (or even rages).
> Imports inside functions, etc.:
>
> void foo(int x) {
> import std.stdio;
> writeln(x * x);
> }
>
I think this would be a little cumbersome to maintain. Maybe it would
even complicate the linking stage, but I'm not sure.
>
> In Archetype, the exclamation point can be placed before the parentheses. It
> is the only part of the condition that can appear outside the parentheses.
>
> if !(expression)
> statement;
This is nice. Currently I have to add another pair of parenthesis, and
it doesn't look nice:
if (!(isFile(name) && getExt(name) == "d"))
continue; // not a file, or not a .d file
vs.
if !(isFile(name) && getExt(name) == "d")
continue; // not a file, or not a .d file
> There are tuples, used like this:
>
> (int, int) getMouseLocation() {
> return (100, 50);
> }
>
>
> Or with named fields too:
>
> (x int, y int) getMouseLocation() {
> return (100, 50);
> }
>
>
> At the call site:
>
> auto (x, y) = getMouseLocation();
>
Maybe D3 would have these, who knows..
Do you use tuple return values often, e.g. in Python?
More information about the Digitalmars-d
mailing list