-
Notifications
You must be signed in to change notification settings - Fork 4
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
Compile time parameters: compile_time_getenv() function #455
Comments
Duplicate of #369 |
I wouldn't group this with constants... |
I see. This is basically what we discussed in #257. |
IMO the right solution is to allow accessing environment variables during compile time. Environment variables would be used to decide and configure what gets compiled ("parameters"), and command-line arguments would be passed when running the program ("arguments"). For example, let's say you want to make a hello world program where the greeting (e.g. import "stdlib/io.jou"
def main(argc: int, argv: byte**) -> int:
format = compile_time_getenv("FORMAT") # env var (compile-time parameter)
printf(format, argv[1]) # runtime argument
return 0 Then you would pass environment variables when compiling the program:
And run it like this:
This would print And once #257 is implemented, you could compile and run at once:
Here's one situation where accessing env vars during compile time is extremely useful. Let's say you have a project that for whatever reason invokes the Jou compiler through a script. The script is messy and you really don't want to edit it for whatever reason (e.g. it could be auto-generated by a stupid tool such as |
At compile time if I have a hard-coded integer, is that baked into the executable? |
Yes, and whatever |
No, |
Similar to how Mojo does it, what do you think of compile time variables and separating parameters (compile time) and arguments (runtime) (see here)?
The text was updated successfully, but these errors were encountered: