;;; File: ;;; higher-order.scm ;;; Authors: ;;; Samuel A. Rebelsky ;;; The Students of CSC151.02 2003F ;;; Summary: ;;; A variety of higher-order procedures and related stuff. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Examples: Similar Procedures ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; All the values in a list greater than 100 (define big-numbers (lambda (lst) (cond ((null? lst) null) ((< 100 (car lst)) (cons (car lst) (big-numbers (cdr lst)))) (else (big-numbers (cdr lst)))))) (define all-numbers (lambda (lst) (cond ((null? lst) null) ((number? (car lst)) (cons (car lst) (all-numbers (cdr lst)))) (else (all-numbers (cdr lst)))))) (define safe-big-numbers (lambda (lst) (cond ((null? lst) null) ((not (real? (car lst))) (error 'big-numbers "Ugh!")) ((< 100 (car lst)) (cons (car lst) (big-numbers (cdr lst)))) (else (big-numbers (cdr lst)))))) (define select (lambda (good? lst) (cond ((null? lst) null) ((good? (car lst)) (cons (car lst) (select good? (cdr lst)))) (else (select good? (cdr lst)))))) (define get-numbers (lambda (lst) (select number? lst))) (define bigstuff (lambda (lst) (let ((big? (lambda (val) (> val 100)))) (select big? lst)))) (define all-real? (lambda (lst) (or (null? lst) (and (real? (car lst)) (all-real? (cdr lst)))))) (define all (lambda (good? lst) (or (null? lst) (and (good? (car lst)) (all good? (cdr lst)))))) (define all-small? (lambda (lst) (all (lambda (x) (< x 10)) lst)))