***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY******************
Write a recursive Racket function "update-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output. The result of update-if should be a list of items such that if x is in xs and (f x) is true, then (g x) is in the list. The output list's elements should keep the input list's items in the same relative order.
For example (update-if even? add1 '(1 2 3 4)) should evaluate to '(3 5) because 2 and 4 make even? true and add1 turns 2 and 4 into 3 and 5.
#lang racket
(provide update-if)
; do not change any code above this line. Write your code below
it.
(define (update-if f g xs) ... )
FINISH THIS CODE IN RACKET ONLY
(define (split left? lst)
(let loop ((lst lst) (a '()) (b '()))
(if (null? lst)
;; you don't need to use values. `cons` or `list` are sometimes preferred
(values (reverse a) (reverse b))
(let ((e (car lst)))
(if (left? e)
(loop (cdr <???>) (cons <???> <???>) <???>)
(loop (cdr <???>) <???> (cons <???> <???>)))))))
(split odd? '(1 2 3 4 ...))
; ==>
; (1 3 ...)
; (2 4 ...)
Get Answers For Free
Most questions answered within 1 hours.