Im writing two scheme , but i run into some problems.. im using Dr.Schme.. and im limited only to use use the following pre-defined Scheme procedures : define, lambda, cond (including the else notation), if, cons, car, cdr, null?, =, equal?, list?, odd?, and, or, not, +, -, *, /, <, <=, >, >=
(calc-running-sums L)
The calc-running-sums function takes a simple list L of numbers and returns a list containing the running sums from L. The nth element in the returned list is the sum of the first n elements in L.
Examples:
(calc-running-sums '(1)) => (list 1)
(calc-running-sums '(2 2 2 2 2)) => (list 2 4 6 8 10)
(calc-running-sums '(2 5 8)) => (list 2 7 15)
(filter-items F L)
The filter-items function takes a function F (which takes one argument and returns a boolean result) and a list L. The job of filter-items is to call F on each of the elements of L, returning a list of all the elements in L for which F returned true, while leaving out all the elements in L for which F returned false. This is a pretty powerful function that can solve a wide variety of problems. (In general, we say that higher-order functions are those that take other functions as arguments. Why they're called "higher-order," and why they're so powerful, is because you can send an arbitrary function to configure them, so that they can solve problems that you haven't even conceived of yet.)
The examples below make use of a few predefined Scheme functions, to show how versatile filter-items will be when you're done with it. Feel free to use these functions in your tests for filter-items, even though they're not on the list of functions you can use in your solutions:
(filter-items positive? '(1 -3 2 -4 3 -5 4 -6)) => (list 1 2 3 4) (filter-items odd? '(1 2 3 4 5 6)) => (list 1 3 5) (filter-items is-increasing? '((1 4) (4 3 2) (5 6)) => (list (list 1 4) (list 5 6)) (filter-items (lambda (s) (<= (string-length s) 4)) '("Alex" "is" "happy" "today")) => (list "Alex" "is") im totally lost and i tried so many different combo and it still doesn't work .. any help would be appricated ;]
(calc-running-sums L)
The calc-running-sums function takes a simple list L of numbers and returns a list containing the running sums from L. The nth element in the returned list is the sum of the first n elements in L.
Examples:
(calc-running-sums '(1)) => (list 1)
(calc-running-sums '(2 2 2 2 2)) => (list 2 4 6 8 10)
(calc-running-sums '(2 5 8)) => (list 2 7 15)
(filter-items F L)
The filter-items function takes a function F (which takes one argument and returns a boolean result) and a list L. The job of filter-items is to call F on each of the elements of L, returning a list of all the elements in L for which F returned true, while leaving out all the elements in L for which F returned false. This is a pretty powerful function that can solve a wide variety of problems. (In general, we say that higher-order functions are those that take other functions as arguments. Why they're called "higher-order," and why they're so powerful, is because you can send an arbitrary function to configure them, so that they can solve problems that you haven't even conceived of yet.)
The examples below make use of a few predefined Scheme functions, to show how versatile filter-items will be when you're done with it. Feel free to use these functions in your tests for filter-items, even though they're not on the list of functions you can use in your solutions:
- positive?, which returns true if its argument is a positive number and false if not
- odd?, which returns true if its argument is an odd number and false if not
- string-length, which takes a string as an argument and returns the number of characters in the string
(filter-items positive? '(1 -3 2 -4 3 -5 4 -6)) => (list 1 2 3 4) (filter-items odd? '(1 2 3 4 5 6)) => (list 1 3 5) (filter-items is-increasing? '((1 4) (4 3 2) (5 6)) => (list (list 1 4) (list 5 6)) (filter-items (lambda (s) (<= (string-length s) 4)) '("Alex" "is" "happy" "today")) => (list "Alex" "is") im totally lost and i tried so many different combo and it still doesn't work .. any help would be appricated ;]
