implement a full adder

Discussion of Scheme and Racket

implement a full adder

Postby comput » Thu Feb 02, 2012 3:04 pm

Hi :) ,

I'm trying to implement a full adder. But it does not work. Sb an idea????
Code: Select all
(define a (make-wire))
(define b (make-wire))
(define cin (make-wire))
(define s (make-wire))
(define cout (make-wire))


; XOR is not implemented till now
(define xor
  (lambda (x y xor)
    (letrec ((a (make-wire))
             (b (make-wire)))

      (or-gate x y a)
      (inverter (and-gate x y b) b)

     
     
(: full-adder (wire wire wire wire wire -> unspecific))

(define full-adder
  (lambda (a b cin s cout)
    (letrec((d (make-wire))
             (e (make-wire))
             (f (make-wire))
             (g (make-wire))
           (h (make-wire))
           (i (make-wire)) )
   
      (begin
        (or-gate   (and-gate b cin d) (and-gate a cin e) f)       
        (or-gate    f   (and-gate a b g)  cout )
       
     (xor (xor a b g) cin  s)
    ; or instead of XOR above, folloing code
     ;   (or-gate a b g)
     ;   (inverter (and-gate a b h) h)
     ;  (and a b i)
   
      ; (or-gate i cin g)
      ;  (inverter (and-gate i cin h) h)
      ; (and i cin s)))))
   
     
        "ok"))))




comput
 
Posts: 1
Joined: Thu Feb 02, 2012 2:50 pm

Re: implement a full adder

Postby saulgoode » Fri Feb 03, 2012 10:34 pm

Your code appears to have been corrupted when you pasted it (for example, your 'xor' procedure seems to have been cut off mid-stream).
saulgoode
 
Posts: 45
Joined: Tue Dec 14, 2010 1:39 am


Return to Scheme

Who is online

Users browsing this forum: No registered users and 2 guests

cron