;; Ces programmes sont sous licence CeCILL-B V1. ;; Exécution en ligne de commande avec Bigloo : ;; $ bigloo -i Addition.scm (define (Init) (let ((n (make-vector 10 #f)) ; opérande (p (make-vector 10 #f))) ; opérande (vector-set! n 0 #t) (vector-set! n 1 #t) (vector-set! n 2 #t) (vector-set! p 1 #t) (Addition n p))) (define (Addition n p) (let* ((longueur (vector-length n)) (r (make-vector (+ longueur 1) #t)) ; résultat (c #f)) ; retenue (do ((i 0 (+ i 1))) ((= i longueur) (AfficheCalcul n p r c)) (let ((a (vector-ref n i)) (b (vector-ref p i))) (vector-set! r i (or (and a (not b) (not c)) (and (not a) b (not c)) (and (not a) (not b) c) (and a b c))) (set! c (or (and a b) (and b c) (and a c))) (vector-set! r longueur c))))) (define (AfficheCalcul n p r c) (display " ") (AfficheLigneCalcul n) (display " ") (AfficheLigneCalcul p) (AfficheLigneCalcul r) ) (define (AfficheLigneCalcul la-ligne) (let ((longueur (vector-length la-ligne))) (do ((i 0 (+ i 1))) ((= i longueur)) (if (vector-ref la-ligne (- longueur i 1)) (display "1") (display "0")))) (newline)) (Init)