r/ProgrammingLanguages • u/Phie_Ash • Apr 05 '26
How I Accidentally Reinvented Kernel (Programming Language)
https://fayash.me/posts/how-i-accidentally-reinvented-kernel
28
Upvotes
r/ProgrammingLanguages • u/Phie_Ash • Apr 05 '26
View all comments
Show parent comment
2
u/WittyStick Apr 06 '26 edited Apr 06 '26
They can be, but you have to assume an initial environment, such as a Kernel standard environment.
There is no specific requirement that Kernel code be evaluated in a standard environment. If we have some code file
foo.knl, we could evaluate it in any environment - perhaps one we've just created before we attempt toevalit.get-moduletakes an optional environment as a parameter.In the case we evaluate in a non-standard environment, attempting partial application may cause a significant delay before starting evaluation, and may be slower than plain interpretation.
In the case where we're evaluating in a standard environment, some partial application can be done and can be optimized (to a limited extent).
However, the amount of optimization we can perform really is limited - we can't really make many assumptions - even assuming
+means addition is not a valid assumption. We can shadow any ground symbol in any environment, and the presence ofstring->symbolmeans those symbols may not be known until evaluation.Consider the following operative:
If
($foo)is called, then it is not safe to assume+means addition afterwards.A naive thought would be: let's track uses of
string->symbolin the code, but the parameter tostring->symboldoes not need to be a string literal. It could be a string downloaded from the internet or elsewhere, which we clearly don't know until we run it.Since
strhere could potentially shadow any binding, it is therefore not safe at some "compile time" to assume any existing binding in our current environment has any meaning - since the meaning it had before we called($foo)may be invalidated by the call.Kernel does have a feature to try and get around the shadowing issue -
(make-keyed-static-variable)- but it's slightly flawed and can be broken. It returns a pair of functions, a binder and accessor. The binder takes a key and an environment, and returns a new environment with its second parameter as the parent. The accessor takes no parameters. When the accessor is called in an environment which has the environment created by the binder as a proper ancestor, it will return whatever key was bound by the binder.The flaw is that we can shadow the name we give to the binder or accessor in any other environment, because they're subject to normal binding rules.