The old way to handle this situation was to have code that looked like this, as a top-level form in the
locals
vocab:"prettyprint" vocab [But this is problematic. What if locals is loaded first, and then prettyprint? Well, this actually happened, due to a change in some other code. Then locals don't prettyprint correctly! You could fix this by adding top-level statements in both vocabs, as mirrors and specialized arrays did, but then this single joint dependency is duplicated in two places. Maintenance is more difficult than it should be.
"locals.prettyprint" require
] when
To fix this problem, I added a new word,
require-when
. The code above, as a top-level form in the locals vocab, would be replaced with "prettyprint" "locals.prettyprint" require-whenThe logic is: if the
prettyprint
vocab is already loaded, then locals.prettyprint
will be loaded. Otherwise, the dependency is registered with the module system, so if prettyprint
is loaded later by something else, then locals.prettyprint
will be as well.I'm pretty satisfied with this solution to a somewhat long-standing problem in Factor. I wonder how other module systems solve the same problem. I have this implemented in a branch in my repository and it should be incorporated into mainline Factor soon.
1 comment:
In Common-Lisp, there is
http://common-lisp.net/project/asdf-system-connections/
The Pliant graph library used to do things much worse in terms of conditional metalevel code hacks, but I don't know if it counts:
http://fullpliant.org/
Post a Comment