Skip to content
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

Global constants #369

Open
Akuli opened this issue Mar 26, 2023 · 6 comments
Open

Global constants #369

Akuli opened this issue Mar 26, 2023 · 6 comments

Comments

@Akuli
Copy link
Owner

Akuli commented Mar 26, 2023

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
Copy link
Contributor

littlewhitecloud commented Mar 26, 2023

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
Copy link
Owner Author

Akuli commented Mar 27, 2023

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
Copy link
Contributor

littlewhitecloud commented Mar 27, 2023

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
Copy link
Owner Author

Akuli commented Mar 27, 2023

I think const foo = 123 is pretty good.

@littlewhitecloud
Copy link
Contributor

I think so.

@Akuli
Copy link
Owner Author

Akuli commented Dec 25, 2024

Today I tried generating some Jou code with AI mostly for fun, and to see what it would do. (This usually doesn't work very well, see doc/ai-thoughts.md.) The AI guessed/used the following syntax:

# Constants
const RAND_MAX: int = 2147483647  # Maximum value for rand()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants