Daniel Swanson <popcorn.tomato.dude@...> writes:
> I have a hash table, where value is a list of a formula for computing
> the value and a few other details irrelevant to this question, the
> formula contians other keys in the hash table, what I'm trying to do
> is replace each of the keys with its value, which may or may not
> contain more keys that need replacing, the total number of keys is
> around 1520, and I have defended against infinite recursion.
> I have tried everything I can think of and nothing has worked, mostly
> due to either stack overflows or inherant limitations of macrolet, are
> there any other ways I should try?
(defstruct (val (:type list))
formula
irrelevantdetails)
(defun val (env var)
(gethash var env))
(defun bindformula (env var formula)
(setf (gethash var env) (makeval :formula formula)))
(defparameter *env* (let ((env (makehashtable)))
(bindformula env 'a '(b c d))
(bindformula env 'b '(c e f))
(bindformula env 'c '(g))
(bindformula env 'd '(e h i))
(bindformula env 'e '(1))
(bindformula env 'f '(2))
(bindformula env 'g '(3))
(bindformula env 'h '(j))
(bindformula env 'i '(k))
(bindformula env 'j '(4))
(bindformula env 'k '(5))
env))
(com.informatimago.commonlisp.cesarum.utility:printhashtable *env*)
;; #.(HASHTABLE :TEST (FUNCTION eql) :SIZE 11
;; :REHASHSIZE 1.5 :REHASHTHRESHOLD 0.85
;; :ELEMENTS '(
;; (b ((c e f) nil))
;; (h ((j) nil))
;; (e ((1) nil))
;; (j ((4) nil))
;; (k ((5) nil))
;; (i ((k) nil))
;; (f ((2) nil))
;; (d ((e h i) nil))
;; (c ((g) nil))
;; (g ((3) nil))
;; (a ((b c d) nil))))
(defun substitutevalforvar (env var)
(let ((val (val env var)))
(if val
(mapcar (lambda (var) (substitutevalforvar env var)) (valformula val))
var)))
(substitutevalforvar *env* 'a)
;; > ((((3)) (1) (2)) ((3)) ((1) ((4)) ((5))))

__Pascal Bourguignon__
http://www.informatimago.com/
