Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

AraHW5

;; You need to write this one.
(defun my-assoc (v alist)
    (cond ((eq v (car (car alist))) (car alist) )
          ((null (cdr alist)) nil)
          (t(my-assoc v (cdr alist))))
)


;; This one is done
(defun my-eval (e alist)
    (cond ((atom e) (my-eval-atom e alist))
          (t (my-apply (car e) (cdr e) alist))
) )


;; You need to write this one.
(defun my-eval-atom (e alist)
;; how do you evaluate an atom???
;; Remember there are special cases: T, NIL, ASYMBOL, 10, "Hello"
    (cond ((null e) nil ) ; nil
          ((null (my-assoc e alist)) e) 
          (t(cdr (my-assoc e alist))))
)


;; This one is done, but you must write the functions it calls
(defun my-apply (fn args alist)
    (cond ((atom fn) (my-apply-atom fn args alist))
          ( t (my-apply-lambda fn args alist)))
)



;; You need to write this one.
;; Utility function for eval-cond and apply-lambda.  Evaluates each expression
;; in l and returns the value of the last expression
(defun my-eval-list (l alist)

    (cond   ((null (my-eval (car l) alist)) nil )
            (t(cond ((null (cdr l)) (my-eval (car l) alist) )
                    (t(my-eval-list (cdr l) alist)))))
                    
)

; test MY-EVAL-LIST
;(write (my-eval-list '(a b c) '((a . 10) (b . 11 ) (d . 12))))


;; You need to write this one.
(defun my-apply-lambda (fn args alist)
;; bind the formals to the evaluated actuals then evaluate the body in that
;; new scoping context (i.e., that becomes the new alist for recursive
;; evaluation of the function body.  Return the value of the last
;; expression in the body (using eval-list).



)



;; You need to write this one.
(defun my-bind-formals (formals actuals alist)
;; This takes a list of formals and unevaluated actuals.  It should evaluate
;; each actual and bind it to its corresponding formal placing them all on
;; the front of the alist.  It should return the alist with the new bindings
;; on the front.  This will be used to evaluate calls to functions defined
;; via defun.
;; e.g., (my-bind-formals '(a) '((add 1 b)) '((b . 10)))
;; will return ((a . 11) (b . 10))
;; Note there will be one actual parameter for each formal parameter.





)






























Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.