Class Loading
Klyn resolves classes through a deterministic search order. The rule is deliberately strict:
standard library classes are always resolved before application classes, so local files cannot
impersonate or shadow core klyn.* types.
When the runtime looks for a class source file, it checks these roots in order:
$KLYN_HOME/lib, the standard library root.- The directory containing the startup
.knfile passed toklyn. - Each directory listed in
$KLASSPATH, from left to right. - The current working directory, if it was not already added as the startup directory.
This order prevents an application or launch directory from replacing standard library
classes. For example, a local klyn/String.kn will not override the real
klyn.String implementation.
The startup directory is the folder that contains the script you launch, not necessarily the shell current directory.
cd ~/Klyn
klyn tools/deepcodia/DeepCodiaApp.kn
In this example, Klyn searches ~/Klyn/tools/deepcodia before $KLASSPATH
and before ~/Klyn. This keeps applications relocatable without making the current
directory more powerful than the application root.
Use KLASSPATH when an application depends on additional source roots outside its
startup directory. On Linux, entries are separated with :. On Windows, entries are
separated with ;.
export KLASSPATH="/opt/klyn-libs:/home/me/shared-klyn"
klyn app/Main.kn
Klyn also accepts the historical KLYNPATH variable when KLASSPATH is not
defined, but new projects should use KLASSPATH.
Class lookup and object caching are separate concerns. Once a source file has been resolved,
the compiler reuses its cached .o file when that object is newer than the
corresponding .kn source. If the source changes, Klyn recompiles it automatically.
Continue with Coding Conventions before moving to the core syntax chapters.