(defun app (x y) (if (endp x) y (cons (car x) (app (cdr x) y)))) (app '(a b c) '(d e f)) (assign evalable-ld-printingp nil) (app '(a b c) '(d e f)) (assign evalable-ld-printingp t) (assign evalable-printing-abstractions '(cons)) (app '(a b c) '(d e f)) (assign evalable-ld-printingp nil) (app '(a b c) '(d e f)) (defun bad-rev (x) (if (endp x) nil (cons (bad-rev (cdr x)) (car x)))) (bad-rev '(a b c)) (defun rev (x) (if (endp x) nil (app (rev (cdr x)) (cons (car x) nil)))) (rev '(a b c d)) (defun bad-rev2 (x) (if (endp x) nil (app (bad-rev2 (cdr x)) (car x)))) (bad-rev2'(a b c d)) (defun rev1 (x a) (if (endp x) a (rev1 (cdr x) (cons (car x) a)))) (rev1 '(a b c d) nil) (rev1 '(a b c d) '(1 2 3)) (defun last-element (x) (if (endp x) 'this-will-never-happen (if (endp (cdr x)) (car x) (last-element (cdr x))))) (last-element '(a b c d)) (last-element nil) (defun all-but-last-element (x) (if (endp x) 'this-will-never-happen (if (endp (cdr x)) nil (cons (car x) (all-but-last-element (cdr x)))))) (all-but-last-element '(a b c d)) (defun rev2 (x) (if (endp x) nil (cons (last-element x) (rev2 (all-but-last-element x))))) (rev2 '(a b c d)) (equal (rev '(a b c)) (rev1 '(a b c) nil)) (equal (rev '(a b c)) (rev2 '(a b c))) (quote (the end)) (include-book "wff" :load-compiled-file nil) *primitive-arities* (wff '(if a b c) *primitive-arities*) (wff '(integerp (car x)) *primitive-arities*) (wff '(cons 1 nil) *primitive-arities*) (wff '(cons '1 'nil) *primitive-arities*) (wff '(+ (car x) '1) *primitive-arities*) (wff '(if (integerp (car x)) (+ (car x) '1) '0) *primitive-arities*) (wff '(a b c) *primitive-arities*) (wff '(a b c) (cons '(a 2) *primitive-arities*)) (wff '(a b c) (cons '(a 3) *primitive-arities*)) (defun is-var (x) ; Assume x is a wff. When is it a variable? ; This function answers that question. (atom x)) (defun is-const (x) ; Assume x is a wff. When is it a constant? ; This function answers that question. (and (not (atom x)) (equal (car x) 'quote))) (mutual-recursion ; How many times is v used as a variable ; symbol in the term x? Assume v is a variable ; symbol and assume x is a wff. (defun hmv (v x) (cond ((is-var x) (if (equal v x) 1 0)) ((is-const x) 0) (t (hmv-args v (cdr x))))) (defun hmv-args (v args) (if (endp args) 0 (+ (hmv v (car args)) (hmv-args v (cdr args))))) ) (wff '(if (endp b) '(a b c) (cons (+ a (car b)) (cdr b))) *primitive-arities*) (hmv 'a '(if (endp b) '(a b c) (cons (+ a (car b)) (cdr b)))) (hmv 'b '(if (endp b) '(a b c) (cons (+ a (car b)) (cdr b)))) (hmv 'car '(if (endp b) '(a b c) (cons (+ car (car b)) (cdr b))))#|ACL2s-ToDo-Line|# (quote (the end)) (wff '(if (endp x) nil (cons (car x) (f (cdr x) y))) '((equal 2) (cons 2) (car 1) (cdr 1) (endp 1) (if 3) (f 2))) (wff '(if (endp x) 'nil (cons (car x) (f (cdr x) y))) '((equal 2) (cons 2) (car 1) (cdr 1) (endp 1) (if 3) (f 2)))