Question

In Scheme language Create a second function "vecfn" that allows one to pass the function to...

In Scheme language

Create a second function "vecfn" that allows one to pass the function to perform on the input lists as the first argument. Below are the test cases that should work when you type them in.

(display (vecfn - '(1 2 3) '(4 5 6))) (newline)
(display (vecfn + '(4) (list (sqrt -1)))) (newline)
(display (vecfn / '(1 2 3) '(1 4 5))) (newline)

Finally, add a "vecfun" to the syntax of Scheme. Submit a single text file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

List values are given as input,
If two list's are of same length then the List values are added correspondingly.
If they are of different length then the length of list with lesser length is made equal with the list with greater length. Then the values are added correspondingly.

Function - append-zeroes is used to append extra zero's to get make the length equal.


Code for Adding to List .

(define (append-zeroes lst n)
(append lst (make-list (abs n) 0)))

(define (vecadd lst1 lst2)
(let ((diff (- (length lst1) (length lst2))))
(cond [(< diff 0)
(map + (append-zeroes lst1 diff) lst2)]
[(> diff 0)
(map + lst1 (append-zeroes lst2 diff))]
[else (map + lst1 lst2)])))

Add a comment
Know the answer?
Add Answer to:
In Scheme language Create a second function "vecfn" that allows one to pass the function to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT