Akuli / jou

Yet another programming language
MIT License
11 stars 4 forks source link

Global constants #369

Open Akuli opened 1 year ago

Akuli commented 1 year ago

In C you would use #define to create constants. What should be the recommended way in Jou? Should we add new syntax, something like globalconstant FOO = 1?

I think currently the best you can do is a function that returns the value, because global variables cannot have an initial value yet. This is actually what config.jou does (see the Makefiles).

littlewhitecloud commented 1 year ago

Maybe constant global variable = x But I think we can use static keyword to mean this is a global constant or create a new one? (I think it is not a good idea to use a long keyword

Akuli commented 1 year ago

Why is it not a good idea to use a long keyword? An advantage with globalconstant is that it's unlikely someone wants to make a variable named globalconstant. But I could imagine someone making a variable named constant.

We could also try const, which would be good because it's consistent with many other languages.

littlewhitecloud commented 1 year ago

Just think long keyword will make people feel annoying. As you say, jou is a simple programming language, why don’t you use a shorter keyword? :)

Akuli commented 1 year ago

I think const foo = 123 is pretty good.

littlewhitecloud commented 1 year ago

I think so.