I've found the 'hook' mechanism to be really useful. I use the same thing in an app I'm writing (in cljs) which auto creates web applications via data schematics.
When my app compiles a new app there's a little routine that adds/removes pre-defined function calls from within a table. So then when cljs compiles the client side code (which performs dead code elimination) the functions that are hooked into the table get added, but the others are eliminated. The cljs dead code elimination process couldn't do this alone; it required being able to hook/unhook code depending upon the app schematic.
Anyways, just wanted add to your point on how useful this feature can be.
The idea behind a 'hook' is that it is a place where code can be inserted without having to modify the original code. They're pretty common in emacs, for instance, where lots of packages provide hooks for easy extension in your .emacs file.
So, if there's a function bound to that name in the hooks table, it is run with the arguments. You only call 'defhook when you want to bind to that point in the code.
This is a rather interesting implementation to me, because I'm used to the emacs-lisp concept, where a hook is actually a list of functions that all get called on the arguments, so it can be added to multiple times. The corresponding names in elisp are 'run-hooks and 'add-hook. https://www.gnu.org/software/emacs/manual/html_node/elisp/Ho...
OK, I have a stupid question. How do I remove an item from a table?
Apparently it's (rem test table) but everything I've tried fails with "Can't take car of #hash(("foo" . (app-run "foo")))" I also thought I might have to assign nil to it but that returns an error as well. Here is my current code if it helps... it's just minor edits of prompt.arc, assignment and running an app in a hook all work:
(def app-unhook (user app)
(do ((rem !app hooks*)
(editor-page user "Hook removed from " app))))
(def app-hook (user app)
(if (file-exists (app-filepath app))
(do ((= (hooks* app) `(app-run ,app))
(editor-page user "Hook applied to " app)))
(editor-page user "Error: No application " app)))
I feel like I'm probably missing something obvious.