Finding greatest product of two lists, but keep getting #unspecific

Posted by user1787030 on Stack Overflow See other posts from Stack Overflow or by user1787030
Published on 2012-10-30T22:57:42Z Indexed on 2012/10/30 23:00 UTC
Read the original article Hit count: 206

Filed under:
|
|
|
(define (greatest-product lst1 lst2)
(define (helper lst addtimes total toacc)
    (cond ((null? lst) '())
    ((= (countatoms lst) 1)  (display total))
    ((= addtimes (cadr lst)) (helper (cdr lst) 1 total total))
    (else (helper lst (+ 1 addtimes) (+ toacc total) toacc))))
(cond ((> (helper lst1 0 0 (car lst1)) (helper lst2 0 0 (car lst2))) (helper lst1 0 0 (car lst1)))
    ((< (helper lst1 0 0 (car lst1)) (helper lst2 0 0 (car lst2))) (helper lst2 0 0 (car lst2)))
    ((= (helper lst1 0 0 (car lst1)) (helper lst2 0 0 (car lst2))) (display 'equal))))

Scheme keeps returning back that it cannot perform the procedure with #unspecific

Im running it with

(display (greatest-product '(1 2 3) '(4 5 6)))
(display (greatest-product '(1 2 3) '(1 2 3)))
(display (greatest-product '(1 2 3) '()))

what is wrong with it? the problem seems to be occurring

© Stack Overflow or respective owner

Related posts about lisp

Related posts about Scheme