## [clisp-list] Rather complicated problem

 [clisp-list] Rather complicated problem From: Daniel Swanson - 2013-10-31 17:37:05 ```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 15-20, 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? -- Daniel Swanson, Certified Geek http://www.proofthatgodexists.org ```

 [clisp-list] Rather complicated problem From: Daniel Swanson - 2013-10-31 17:37:05 ```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 15-20, 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? -- Daniel Swanson, Certified Geek http://www.proofthatgodexists.org ```
 Re: [clisp-list] Rather complicated problem From: Pascal J. Bourguignon - 2013-10-31 18:04:12 ```Daniel Swanson 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 15-20, 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 irrelevant-details) (defun val (env var) (gethash var env)) (defun bind-formula (env var formula) (setf (gethash var env) (make-val :formula formula))) (defparameter *env* (let ((env (make-hash-table))) (bind-formula env 'a '(b c d)) (bind-formula env 'b '(c e f)) (bind-formula env 'c '(g)) (bind-formula env 'd '(e h i)) (bind-formula env 'e '(1)) (bind-formula env 'f '(2)) (bind-formula env 'g '(3)) (bind-formula env 'h '(j)) (bind-formula env 'i '(k)) (bind-formula env 'j '(4)) (bind-formula env 'k '(5)) env)) (com.informatimago.common-lisp.cesarum.utility:print-hashtable *env*) ;; #.(HASHTABLE :TEST (FUNCTION eql) :SIZE 11 ;; :REHASH-SIZE 1.5 :REHASH-THRESHOLD 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 substitute-val-for-var (env var) (let ((val (val env var))) (if val (mapcar (lambda (var) (substitute-val-for-var env var)) (val-formula val)) var))) (substitute-val-for-var *env* 'a) ;; --> ((((3)) (1) (2)) ((3)) ((1) ((4)) ((5)))) -- __Pascal Bourguignon__ http://www.informatimago.com/ ```