This is a sample JAC application demonstrating how to separate the main entry point from object definitions.
greeter.jac
: Defines theGreeter
object.main.jac
: Contains the main entry point that imports and uses theGreeter
object.
In JAC, you can define objects (classes) in separate files and import them into your main file where the entry point is defined.
Define an object in a separate file (e.g., greeter.jac
):
obj Greeter {
def say_hello(name: str) {
print(f"Hello, {name}! Welcome to Jac.");
}
}
In the main file (e.g., main.jac
), import the object and use it in the entry block:
import from greeter { Greeter }
with entry {
let g = Greeter(); # create instance
g.say_hello("Sabore");
}
This separation promotes modularity and reusability.