I have written a function that modifies a list
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
("form0"  ;; before
  ("type" "form") 
  ("attrs" (
    ("ID" "form0") 
    ("method" "POST") 
    ("name" "form0") 
    ("onsubmit" "return checkLoginForm(this);") 
    ("action" "[[action]]")))) ;; Value referenced by "action"
List at level 2 after modification
("form0"   ;; after
  ("type" "form") 
  ("attrs" (
    ("ID" "form0") 
    ("method" "POST") 
    ("name" "form0") 
    ("onsubmit" "return checkLoginForm(this);") 
    ("action" "http://localhost/cgi-bin/test.lsp"))))  ;; value changed
Now here we have the function
(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
Can this code be optimized or condensed? Insights from senior
newlispers will go a long ways to further educate me.
Thanks
tim
			
			
			
				Hi Tim,
I would probably try to simplify the code which 
Download Dragonfly and take a look at the request.lsp
Here's what it works like: //http://www.rundragonfly.com/dragonfly_getpost
Cheers
Marc
			
			
			
				How about:
			
			
				Quote from: "hilti"
I would probably try to simplify the code which 
Download Dragonfly and take a look at the request.lsp
Here's what it works like: //http://www.rundragonfly.com/dragonfly_getpost
Cheers
Marc
Hi Marc, this has nothing to do with posting. It's about creating a form with data loaded
into it from a database.
thanks
tim
			 
			
			
				Quote from: "cormullion"
Gotta try this. I will get back to you folks on it.
Thanks very much.
tim
			 
			
			
				cormullion does it again. Here were have cut the LOC in half:
(unless(set-ref '("action" ?) attrs (list "action" newaction) match)
  (push (list "action" newaction) attrs -1))
But this raises a couple of more questions. Obviously the functor argument
and not getting the results I want: 
> (set 'attrs '(("ID" "form0") ("method" "POST") ("name" "form0")))
(("ID" "form0") ("method" "POST") ("name" "form0"))
> (match '("ID" ?) attrs)
nil
What am I doing wrong?
thanks
tim
			
			
			
				I don't think you're reflecting the pattern of the target list precisely enough.  This might work:
			
			
				Quote from: "cormullion"
That's correct. Thanks.