Open Akuli opened 1 year ago
I think on the contrary, you can use the "extern" keyword to decide which functions need to be exported. Then other variables, functions, structs of the current file will not be accessed.And then, they will be private
def internal_util_function() -> int:
return 123
static struct PrivateStruct:
x: int
y: int
extern def public_function() -> int:
return internal_util_function() * 2
extern struct PublicStruct:
message: byte*
line: int
I think on the contrary, you can use the "extern" keyword to decide which functions need to be exported. Then other variables, functions, structs of the current file will not be accessed.And then, they will be private
So basically, everything is private by default, and you can use a keyword like extern
to make public things. This seems like a good idea.
I think I will probably name the keyword public
instead of extern
, for two reasons:
extern
many people would think: "what does the extern
keyword do again? Ah now I remember, it makes the thing public."extern
keyword has a different meaning in C. Jou's declare
and C's extern
both correspond to the same idea: they tell the linker that something exists without defining it.More possible keywords to use for this:
export
, same as in JavaScriptpub
, same as in Rustexport
, because it would get confused with __declspec(DLLEXPORT)
in windows.pub
is a bit too short considering Jou's goals: we need readability.I think global
or public
will be the most clear
public
looks fine to me. I understood extern
just fine and would be a little disappointed if someone couldn't deduce its meaning.
It seems that everyone is happy with public
. I will use it when I eventually get around to implementing this :)
How about a decorator?
@public
def add(x: int, y: int) -> int:
return x + y
I like that, but if it isn't written in Jou that would feel a bit too automagic-y for a decorator.
Currently all functions and structs are made available for other files to import. There should be a way to make functions and structs be visible only within the current file.
Maybe
static
?