ceylon / ceylon.ast

Apache License 2.0
18 stars 3 forks source link

Sugaring: Reflexive -Ish aliases? #64

Closed lucaswerkmeister closed 10 years ago

lucaswerkmeister commented 10 years ago

At the moment, we define the -Ish aliases like this:

shared alias BodyIsh => Body|{Declaration|Statement*};

I. e., BodyIsh includes Body. The rationale behind this is that if you already have a Body object from somewhere, you should be able to use it in the create functions.

However, that prevents the use of the following syntax:

block {
    Statement(…),
    Statement(…),
    …
}

Because this is only supported “if the parameter list has an unassigned parameter of type exactly Iterable<T,N> for some types T and N”, i. e., if BodyIsh was just {Declaration|Statement*}.

Should we make the aliases “non-reflexive”? I think the named arguments syntax would be a pretty big advantage…

lucaswerkmeister commented 10 years ago

Okay, I think I’ve got a good solution. I’ll explain it on the example of CaseTypes:

This allows

value cd = classDefinition {
    // ...
    caseTypes = { "true", "false" };
    // ...
}

as well as

value cd = classDefinition {
    // ...
    caseTypes = selfCaseTypes;
    // ...
}

and

value ct = caseTypes {
    for (i in 1:nStates)
        "S``i``"
}

In general, however, it must be noted that in ceylon.ast.create, the idea of “one pattern fits all” must be abandoned, and other kinds of nodes will require different treatment.

lucaswerkmeister commented 10 years ago

Actually… let’s make the caseTypes etc. functions variadic.

lucaswerkmeister commented 10 years ago

…that will require us to remove the Absent trick, at least from the shared function. Which is okay – it’s more used for internals, I think.