[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Project 4 help



I have done part of Task 2 and came up with a varsubst function which looks 
like:

(defun varsubst (pattern binding)
(if (null pattern) nil
   (if (atom (car pattern))
    (if (eq '? (car pattern)) ;find matching and return var
        ;if pattern is (? var)
        (if (equal pattern (caar binding)) (list (cadar binding))
            ;if binding doesn't match, traverse through bindings
            (list (match-var pattern (rest binding))))
        ;else, atom in pattern isn't ?, so append car pattern to return list
        (append  (list (car pattern))
                       (varsubst (rest pattern) binding)))
    ;else, not an atom...pattern is a list
     (append (varsubst (car pattern) binding) (if (null (varsubst (rest 
pattern) binding)) nil (list(varsubst (rest pattern) binding)))))))

(defun match-var (pattern binding)
  (if (equal pattern (caar binding)) (cadar binding) (match-var pattern (rest 
binding))))

I'm not sure if it is supposed to look that customized, but it works.  

I am now on the rename function and understand that the same generated number 
suffix is appended to each variable.  I can generate a number such as "112" 
but it is in String format.  I've been looking around and can't figure out how 
to combine "112" and 'rao to produce a variable like 'rao112.

Thanks in advance.