New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sugaring #19
Comments
I now think that they can definitely increase readability, because we now have wrapping nodes for every collection of nodes. This is useful for consuming and operating on ASTs, but horrible for readability: compare classDefinition {
name = "MyClass";
satisfiedTypes = { baseType("Obtainable"), iterableType("Element") };
typeParameters = { "Element" };
hashDefinition,
equalsDefinition
} with ClassDefinition {
name = UIdentifier("MyClass");
satisfiedTypes = SatisfiedTypes([baseType("Obtainable"), iterableType("Element")]);
typeParameters = TypeParameters([typeParameter("Element")]);
body = ClassBody([
hashDefinition,
equalsDefinition
);
} and keep in mind that the latter still has lots of sugar! This is just making the point about allowing |
I think conceptually we can justify this by saying that we have something like alias ClassDefinitionIsh => IdentifierIsh, ParametersIsh, BodyIsh, ...; which would mean something like a “spread tuple type”. Then it’s reasonable that the |
I wonder if perhaps we should have all the utilities for creating ASTs in a separate module… |
Moving it into a separate module would also allow me to release it independently of |
So what do we call that module?
My current favorite, if nothing better turns up, is |
I’m leaning more towards |
Two new modules: ceylon.ast.create and test.ceylon.ast.create. All existing “sugaring” moves to ceylon.ast.create, and the tests (xFunction in test.ceylon.ast.core) move to test.ceylon.ast.create.
Two new modules: ceylon.ast.create and test.ceylon.ast.create. All existing “sugaring” moves to ceylon.ast.create, and the tests (xFunction in test.ceylon.ast.core) move to test.ceylon.ast.create. For #19.
(And ClassInstantiation, but I might unshare that, it’s really just auxiliary for the other two – I don’t see why you’d want to use it directly.) For #19.
(Moving the discussion here from #1.)
Being able to pass
String
instead of anIdentifier
Integer
instead of aNaturalLiteral
is useful.
However, I don’t think there’s a good way to accommodate the sugar in the class. Since the type of the original attribute is invariant, we can’t change
Identifier
toIdentifier|String
. We could declare some sort ofIdentifier|String identifier_
orsugarIdentifier
or something like that, but that doesn’t really appeal to me. Instead, I would rather create functions with the same name, like this:Or maybe I’m wrong, and there is some syntax that allows something like this?
(Constructors – ceylon/ceylon-spec#796 – might also be a solution to that problem, but I don’t think there’s a consensus on these yet.)
Later:
I just noticed that my proposed solution for the “sugar” part is quite inconsistent: the
identifier
function turns anIdentifierIsh
into anIdentifier
, but the\ivariable
function takes a whole bunch of arguments (instead of aVariableIsh
) and turns them into aVariable
. That’s actually two different things – but I can’t think of an example where they would collide.And:
It’s a lot of work, and the gain isn’t clear – the sugared variants are easier to type, but do they increase or decrease readability?
The text was updated successfully, but these errors were encountered: