(cond ((null? l1) list-so-far)
(else
(+ (* (car l1) (car l2))
(iner-prod-aux (cdr l1) (cdr l2) list-so-far)))))
(define (iner-prod l1 l2) (iner-prod-aux l1 l2 0))
(define (ipaux l1 l2 sum) (if (or (null? l1) (null? l2)) sum ;one or both of the lists is empty, so rest of numbers are treated as 0 (if (and (number? (car l1)) (number? (car l2))) (ipaux (cdr l1) (cdr l2) (+ sum (* (car l1) (car l2)))) ;both heads are numbers (ipaux (cdr l1) (cdr l2) sum) ;one or the other is not a number ) ) ) (define (ip l1 l2) (ipaux l1 l2 0))
(if (or (null? L1) (null? L2)) innerProduct
(if (and (number? (car L1)) (number? (car L2)))
(ip-acc (cdr L1) (cdr L2) (+ innerProduct (* (car L1) (car L2)) ));
)
(define (ip L1 L2) (ip-acc L1 L2 0))
(define (ip L1 L2) (define result 0) (print (inner-product-helper L1 L2 result)))
(define inner-product-helper L1 L2 result (if (or(null? L1) (null? L2))) result (define a 0) (define b 0) (if (number? a) (let a (car L1)) (if (number? b) (let b L2)) (+ result (* a b)) (inner-product (cdr L1) (cdr L2) result)(Edited: 2021-11-10)
(define (ip a b) (iphelp a b 0))
(define (iphelp a b c)
(if (null? a) c
(if (null? b) c
(iphelp (cdr a) (cdr b) (+ c (* (car a) (car b)))))))
(if (or (null? l1) (null? l2))
(if (and (number? (car l1)) (number? (car l2)))
(ipaux (cdr l1) (cdr l2) (+ sum (* (car l1) (car l2))))
(ipaux (cdr l1) (cdr l2) sum)
)
)
) (define (ip l1 l2) (ipaux l1 l2 0))