Yes, the way I do it is to override the default functor.
Code: Select all
(context 'ctx)
;; override default functor
(define (ctx:ctx a)
(let (b (sym (string "_" a)))
(if (args)
(set b (first (args))) ; set the value
(if (eval b) (eval b) (set b 0))))) ; retrieve the value
(context MAIN)
Now references to an unbound symbol will be automatically set to 0, and setf-able. With this default functor, now your original code, (++ (hm "foo")) will properly return "1", as you expected.
This seems like it might be a useful design pattern, perhaps suitable for the CodePatterns document if it isn't in there already; I similarly changed the default functor to use a database as a backing store, if a symbol is unbound, it looks it up with SQL and stores it client-side, references thereafter are very speedy.
The way contexts work in newlisp, with this idiom, you still get all the speed advantages of redblack trees that contexts have. Right Lutz?
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.