Dr. Racket programming (intro to programming)

Theology in Business Paper
June 21, 2017
Elementary Teaching PowerPoint
June 21, 2017

Dr. Racket programming (intro to programming)
Dr Racket
Language: Intermediate Student with Lambda.
Implement the following functions using foldr, with no explicit recursion or helper functions.
· cross, which consumes two lists of distinct values, and produces a list of two-element lists consisting of one value from the first list and one value from the second list. For example, (cross ‘(a b c) ‘(1 2))should evaluate to
‘((a 1) (a 2) (b 1) (b 2) (c 1) (c 2)).
The order here is important.
· my-filter, which does what the built-in filter function does.
procedure
(foldr proc init lst …+) ? any/c
proc : procedure?
init : any/c
lst : list?
Like foldl, but the lists are traversed from right to left. Unlike foldl, foldr processes the lsts in space proportional to the length of lsts (plus the space for each call to proc).
Examples:
> (foldr cons ‘() ‘(1 2 3 4))
‘(1 2 3 4)
> (foldr (lambda (v l) (cons (add1 v) l)) ‘() ‘(1 2 3 4))
‘(2 3 4 5)
4.9.4 List Filtering
procedure
(filter pred lst) ? list?
pred : procedure?
lst : list?
Returns a list with the elements of lst for which pred produces a true value. The predprocedure is applied to each element from first to last.
Example:
> (filter positive? ‘(1 -2 3 4 -5))
‘(1 3 4)