Question

***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes...

***************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

Homework Answers

Answer #1
(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 ...)
Know the answer?
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
Similar Questions
Write in Racket Language Write a recursive Racket function "sum" that takes two integers as parameters,...
Write in Racket Language Write a recursive Racket function "sum" that takes two integers as parameters, each greater or equal to zero, and evaluates to their sum. In this problem, you must use the built-in functions "add1" and "sub1" and may not use the built-in functions "+" or "-". For example, (sum 2 3) should evaluate to 5. Note: (add1 5) evaluates to 6 and (sub1 4) evaluates to 3. Hint: like you saw in the "append" lecture, treat one...
-RACKET LANGUAGE ONLY- Write a non-recursive Racket function "keep-short-norec" that takes an integer and a list...
-RACKET LANGUAGE ONLY- Write a non-recursive Racket function "keep-short-norec" that takes an integer and a list of strings as parameters and evaluates to a list of strings. The resulting list should be all strings on the original list, maintaining their relative order, whose string length is less than the integer parameter. For example, (keep-short-rec 3 '("abc" "ab" "a")) should evaluate to '("ab" "a") because these are the only strings shorter than 3. Your solution must not be recursive. You will...
Please write function in Racket language. Write a recursive Racket function "sum-diff" that takes two lists...
Please write function in Racket language. Write a recursive Racket function "sum-diff" that takes two lists of integers that are the same length and evaluates to an integer. The resulting integer should be the sum of the absolute value of the differences between each pair of integers with the same index in the two lists. For example (sum-diff '(-1+2+3)'(123)) should evaluate to 12 because the absolute value of the differences between (-1 and 1), (-2 and 2) and (-3 and...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The...
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The function should return the sum of all the integers x, x-2, x-4, x-6, etc. as long as the numbers are positive. For example, [sum-alternate 5] should evaluate to 5 + 3 + 1, and [sum-alternate 6] should evaluate to 6+4+2.
Write a Racket function named listlen that takes a list as a parameter and evaluates to...
Write a Racket function named listlen that takes a list as a parameter and evaluates to the number of elements in the list. For example (listlen empty) should evaluate to 0 and (listlen '(1 2 3)) should eveluate to 3.
Write an Oz program (having an Oz recursive function/procedure) which takes in the input a list,...
Write an Oz program (having an Oz recursive function/procedure) which takes in the input a list, say L, and two positive integers, M and N. The function should return another list L’, which represents the sub-list of L containing all the elements from index M to index N in reverse order. For example, if the input list is [a 2 g 5 4 k] and M is 2 and N is 5, then the output list should be [4 5...
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
Write C language code for a function that takes a doubly linked list as a parameter...
Write C language code for a function that takes a doubly linked list as a parameter and deletes all the nodes in even positions from the first to the last after displaying the content of each node to the console.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT