scheme - Multiply two lists in Racket -
i using racket multiply list same length. far have tried:
(define (multiply-list b)   (if ([(empty? a) (empty)])       else (cons(*car(a)car(b)))       cdr(a) cdr(b)))                     i having trouble understanding syntax of racket. want update list it's cdr. cannot right a , b lists.
i believe aiming this:
(define (multiply-list b)   (if (empty? a)       empty       (cons (* (car a) (car b))             (multiply-list (cdr a) (cdr b)))))   explanation:
- in scheme, have very, careful put pair of 
(). in code, parentheses unnecessary , others misplaced. ide put them in right place - for instance, pair of 
[]surrounding condition wrong, , this:(empty)becauseemptynot function, surround()when want call function - and don't call function this: 
car(a). correct way is:(car a) - when use 
if, alternative part of expression must not precededelse, maybe you're confusingifexpressioncondexpression. - and last not least: don't forget call recursion!
 
Comments
Post a Comment