<div dir="ltr"><div><div><div><div>Hello. I've been trying to get a particular use case for module loading to work, and, while I have a mostly functional solution, I am unsure whether I am using the best infrastructure for the task. The explanation is a bit involved, but the basic question is what is the right way to update a running system using values generated by racket code (update as in feed new data to, not reload the module bindings of). <br>
<br></div>I have a text-based game client that needs to be able to dynamically load user-defined aliases while running. Ordinarily this could be solved by simply reading a file of alias definitions and updating the structure in memory. However, as the alias system may potentially be quite complex, I was hoping to use both the racket language and module system to define these aliases. Ie, I might have inventory-aliases.rkt, which requires item-aliases.rkt in order to reuse helper code defined in the latter in the former. <br>
<br>My current solution involves having all alias code as well as the main program require a common base.rkt that provides a single aliases #hash. Each alias file, when loaded, destructively sets all its aliases into the hash, which are in turn usable by the main program.<br>
<br></div>When a user updates an alias file, I dynamic-rerequire the file, which, since the hash set!s are idempotent, mostly works. The trouble is that if a user deletes an alias, I do not know to get rid of it in my hash structure. Moreover, I cannot throw out the hash because dynamic-rerequire only reruns changed modules. <br>
<br></div>Before I continue on down this rabbit hole and start adjusting timestamps to have dynamic-rerequire do what I need it to do, I wanted to ask whether there was a more canonical way to achieve my ends. I get the impression that I am somewhat hijacking the module system since I am mostly using it to structure the alias code, but then am trying to extract something that is not quite an exported set of values from it. Would it make sense perhaps to construct an evaluator out of the alias definitions and evaluate user inputs in that language? I am not intimately familiar with the module system, and so am doing a bit of a random walk around its infrastructure as I learn more about it.<br>
<br></div>I sense this question may be a bit obscure, so thank you in advance to anyone who has any insights to share on the matter.<br><br>Evan<br></div>