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) because empty not 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 preceded else, maybe you're confusing if expression cond expression.
  • and last not least: don't forget call recursion!

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -