four "levels" deep, or to put it another way, has four dimensions.
My method uses multiple calls to 'setf. I would welcome any comments
or advices as to how to optimize this function - if possible.
The preconditions are this:
I have a list that has as members (level 1) that may be either
strings or lists. Any list at level 1 may have as members either
lists or strings. (level 2)
Any list at level 2 may be nested 2 more levels deep.
What follows is
List at level 2 before modification
Code: Select all
("form0" ;; before
("type" "form")
("attrs" (
("ID" "form0")
("method" "POST")
("name" "form0")
("onsubmit" "return checkLoginForm(this);")
("action" "[[action]]")))) ;; Value referenced by "action"
Code: Select all
("form0" ;; after
("type" "form")
("attrs" (
("ID" "form0")
("method" "POST")
("name" "form0")
("onsubmit" "return checkLoginForm(this);")
("action" "http://localhost/cgi-bin/test.lsp")))) ;; value changed
Code: Select all
(define (set-form-action newaction (f 0)) ;; 'get-form sets 'current-formname
(letn ((form-list(get-form f)) ;; level 1 referenced from 'DS by 'current-formname
(form-tag (form-list 1)) ;; level 2
(attrs(lookup "attrs" form-tag)) ;; level 3
(action))
(if (set 'action (assoc "action" attrs)) ;; level 4
(begin
(setf (action 1) newaction ;; 'rewrite' at level 4
(assoc "action" attrs) action)) ;; 'rewrite' at level 3
(push (list "action" newaction) attrs -1)) ;; no pair. Add a pair
(setf (form-tag 2 1) attrs ;; 'rewrite' at level 2
(form-list 1) form-tag ;; 'rewrite' at level 1
(assoc current-formname DS) form-list))) ;; 'rewrite' at level 0
newlispers will go a long ways to further educate me.
Thanks
tim