How do i pass a number from a list as a parameter in scheme?

Posted by wyatt on Stack Overflow See other posts from Stack Overflow or by wyatt
Published on 2012-04-06T06:20:02Z Indexed on 2012/04/06 17:28 UTC
Read the original article Hit count: 190

Filed under:
|
|

I need to take a number from a list and convert it to a number so that i can pass it as a parameter.

im trying to make a 1-bit adder in scheme. i've written the code for the or gate and the xor gate and also the half adder and now im trying to combine them all to make a full adder. im not sure if im going about it the right way. any input will be appreciated thank you.

(define or-gate
 (lambda (a b)
  (if (= a 1)
    1
    (if (= b 1)
    1
    0))))
(define xor-gate
 (lambda (a b)
  (if (= a b)
    0
    1)))

(define ha
 (lambda (a b)
  (list (xor-gate a b)(and-gate a b))))

(define fa
 (lambda (a b cin)
  (or-gate (cdr(ha cin (car (ha a b))))(cdr(ha a b)))))

the issue i get when i run the program is that the half adder (ha) function outputs a list as a value and that makes the values incompatible with my other procedures because they require numbers and not lists. i feel like there is a simple solution but i dont know it.

© Stack Overflow or respective owner

Related posts about list

Related posts about parameters