#lang racket ;; CSE 413 16au ;; Lecture 7 sample code ;; Hal Perkins (define nums '(1 2 3 4 5)) (define rnums '(17 3 -2 42 15 3 12)) (define alist '(a (b c) d e)) (define (incr n) (+ 1 n)) (define (dbl n) (* 2 n)) ;; review: curried functions ;; ordinary add function (define add (lambda (x y) (+ x y))) ;; curried add - result is a function that has an ;; integer parameter and returns the sum of that ;; parameter plus the (frozen) value of x (define cadd (lambda (x) (lambda (y) (+ x y)))) (define plus2 (cadd 2)) ;; (add 2 3) ;; ((cadd 2) 3) ;; (define plus2 (cadd 2)) ;; (plus2 3) ;; copy of list where lo <= x <= hi (define (filter-in-range lo hi lst) (filter (lambda (n) (and (>= n lo) (<= n hi))) lst)) ;; return function that will filter a list for values lo <= x <= hi (define (cfilter-in-range lo hi) (lambda (lst) (filter (lambda (n) (and (>= n lo) (<= n hi))) lst))) ;; (filter-in-range 5 20 rnums) ;; ((cfilter-in-range 5 20) rnums) (define filter520 (cfilter-in-range 5 20)) ;; (filter520 rnums)