DEV Community

Cover image for A new syntax for Gwion!
Jérémie Astor
Jérémie Astor

Posted on

5 2

A new syntax for Gwion!

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

  • var
  • ref
  • nonnull
  • const
  • nonnull ref
  • const ref
  • const nonnull
  • const 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;
Enter fullscreen mode Exit fullscreen mode

new syntax

class C {
  class D {}
}

#! with the new 'var' modifier
var C.D d;
Enter fullscreen mode Exit fullscreen mode

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 packed Ptr:[:[int]Ptr] (before: <~<~int~>Ptr ~>Ptr with 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       >>>;
Enter fullscreen mode Exit fullscreen mode

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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (2)

Collapse
 
pinei profile image
Pinei

Hi
What is Gwion?

Collapse
 
fennecdjay profile image
Jérémie Astor

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.

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay