Closed littlewhitecloud closed 1 year ago
Or let compiler use the last import same name function just like tkinter.ttk
from tkinter import Tk, Button
from tkinter.ttk import Button
xxx = Button(master, ...) # use tkinter.ttk's Button
This has nothing to do with Jou's syntax, and it is a limitation of how Jou works (and it behaves just like in C). Jou has always worked this way, even before the syntax was changed.
You are getting a linker error. When you compile a Jou file, it turns into a .o
file. So the compiler creates two .o
files, file1.o
and file2.o
, both containing a function named hello
. When the linker sees this, it complains because you can't have two functions with the same name, but the .exe
file can only have one function with a given name.
The Jou compiler could automatically prefix the function names: a hello
function in file1.o
could be actually called file1_hello
. This is what "better C" languages (Zig, Rust, C++, ...) do. But Jou isn't like those languages, instead Jou avoids doing anything significantly more magical than C.
You need to name the functions differently -- again, just like in C. This is why every class name in self_hosted/ast.jou
starts with Ast
, for example.
Static/private functions would help too, because you can have multiple static
functions with the same name in different files: #84
@Akuli And if I import a library with a random function substitute
that I don't want nor did I know it existed and have another file I need to import that has a function of the same name? I do think there should be some way to differentiate the two.
Private functions (#84) will solve this for the most part. You can still have two private functions with the same name.
Any reasonable C or Jou library does not have a public function named substitute
. Public functions tend to be prefixed with the name of the library.
For example, the Jou compiler uses LLVM's C api, and its functions are named starting with LLVM
, e.g. LLVMVerifyModule
or LLVMGetSourceFileName
. Similarly, Python's functions are prefixed with Py
(Python is implemented in C).
Jou could automatically add a prefix, e.g. def foo()
in file bar.jou
would create a function named bar_foo
. This is basically what languages like C++ do. But once again, I don't want to add more magic to Jou.
file1.jou
file2.jou
test.jou
output
The new import syntax failed to load the same name function, but we can use python's import syntax:
file.function(arg1, arg2, ...)
And revert the old syntax (Maybe)
from "{file}" import "{function}"