Syntax changes for Gwion
Check it here
I tried to address the syntax problems in Gwion.
Here's what I changed:
Declaration
Declarations needs a prefix
varrefnonnullconstnonnull refconst refconst nonnullconst nonnull ref
This fixes the ambiguity of placement between const, nonnull and ref and makes it easy both for the reader and the parser to know when a variable is declared.
Also, there is no longer a need to use -> when declaring member types.
old syntax
class C {
class D {}
}
C->D d;
new syntax
class C {
class D {}
}
#! with the new 'var' modifier
var C.D d;
Acces Specifier
Attained consistency in placement.
Now it is always:
static or global or nothing
followed by
private or protect or nothing
Templates
- improve template placement consistency: now always on the right.
- change
<~xxx~>to:[xxx]. shorter and can be packedPtr:[:[int]Ptr](before:<~<~int~>Ptr ~>Ptrwith he space mandatory)
So now all template can be written xxx:[y,z]
new keyword: funcdef
to disambiguate with typedef used for type aliases.
Ability to fix functions
Inspired by a similar feature in haskell, you can now write
#! Automatic conversion to pointer for the first argument
#! default of value 1 for the second argument
fun int add(Ptr:[int] i, int j : 1) {
return j +=> *i;
}
#! declare a variable
var int i;
#! traditionnal
<<< add(i,1) >>>;
#! chuck style
<<< (i,1) => add >>>;
#! infix
<<< i @add 1 >>>;
#! prefix
<<< ($add) i >>>;
#! postfix
<<< i $add >>>;
Conclusion
I think that's all (well that and the usual bug fix here and there).
In my opinion, this is a huge improvement, but it's now up to you to tell me if there is something wrong, if you like it, whatever...
If nobody sees a problem with it, I'll merge next week.
Top comments (2)
Hi
What is Gwion?
Sorry I missed your reply.
Gwion is a programming language aimed at music making.
I started it because at some point the language I used for some of my shows/projects (chuck) was not performant enough. I also felt it like things like generics or function pointers so I added them.