Scheme operation on a function -
is possible operation on previous function, have list of values (1,2,3,4,5), first function needs multiply them 2, while 2nd function adds 1 result of previous function, first (2,4,6,8,10), , (3,5,7,9,11) got this, function g work, possible nstead of doing operations on element on function f or results function f
#lang racket (define test (list 1 1 2 3 5)) (define (f) (map (lambda (element) (* 2 element)) test)) (define (g) (map (lambda (element) (+ 1 (* 2 element))) test))
first need correctly define procedures take list parameter (called lst in case):
(define (f lst) (map (lambda (e) (* 2 e)) lst)) (define (g lst) (map add1 lst)) then
> (f '(1 2 3 4 5)) '(2 4 6 8 10) > (g '(2 4 6 8 10)) '(3 5 7 9 11) or, if need combine both procedures:
> (g (f '(1 2 3 4 5))) '(3 5 7 9 11)
Comments
Post a Comment