Scheme Double All List Values and Write Mapping Function -


i have question on homework assignment follows:

enter image description here

i have first part (double-list-elements) complete

(define (double-list-elements s)   (if (null? s)   '()   (cons (* 2 (car s))         (double-list-elements (cdr s))))) 

but have absolutely no idea how proceed double-list-elements-one. pointers appreciated.

close no cigar:

(define (double-list-elements s)   (if (null? s)       '()       (cons (* 2 (car s))             (double-list-elements (cdr s)))))  (define (custom-map proc lst)   (if (null? lst)       '()       (cons (proc lst)             (custom-map proc (cdr lst)))))  (define (double-list-elements-one func s)   (custom-map double-list-elements s))  (double-list-elements-one double-list-elements '(1 2 3 4 5 6)) 

output = (list (list 2 4 6 8 10 12) (list 4 6 8 10 12) (list 6 8 10 12) (list 8 10 12) (list 10 12) (list 12))

i need pass double-list-elements double-list-elements-one parameter list.

you have write own map, it's very similar have, pass part changes procedure parameter, , invoke on right place:

(define (mymap proc lst)   (if (null? lst)       '()       (cons <invoke proc on current element>             (mymap proc (cdr lst)))))  (define (double-list-elements-one s)   (mymap <pass proper lambda> s))  (double-list-elements-one '(1 2 3 4 5)) => '(2 4 6 8 10) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -