- Code: Select all
`(define value`

(lambda (n)

(if (atom- n)

n

(if (eq? (car (cdr n)) '0+)

(0+ (car n)(value (car (cdr (cdr n)))))

(if (eq? (car (cdr n)) '0*)

(0* (car n)(value (car (cdr (cdr n)))))

(if (eq? (car (cdr n)) '0-)

(0- (car n)(value (car (cdr (cdr n)))))

(if (eq? (car (cdr n)) '0/)

(0/ (car n)(value (car (cdr (cdr n)))))

(if (eq? (car (cdr n)) '0^)

(0^ (car n)(value (car (cdr (cdr n)))))

#f))))))))

so I tried another method that does not work

- Code: Select all
`(define alist '((0+ 0+)(0* 0*)(0- 0-)(0/ 0/)(0^ 0^)))`

(define value

(lambda (n)

(if (atom- n)

n

(let ((f (assq (car (cdr n)) alist)))

(if (or (eq? (car (cdr n)) '0+)

(eq? (car (cdr n)) '0*)

(eq? (car (cdr n)) '0-)

(eq? (car (cdr n)) '0/)

(eq? (car (cdr n)) '0^))

(f (car n) (value (car (cdr (cdr n)))))

#f)))))

the error message for example (value '(3 0+ 4)) has ERROR: in procedure (#{0=}# ... wrong type to apply .. when I try (assoc '0+ alist) I get (#{0+}# . #{0+}#) so this is where my problem is .. but why?