

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CS 173 Programming Languages Shriram K.
C inclusive. This function uses the foldl function.
;; determines if all numbers in a list are between 5 and 95 ( define ( check-range1 temp-list )
General check-range function for determining whether a list of temperatures is between a min and a max value.
;; determines if all numbers in a list are between a specified max and min value ( define ( check-range temp-list min max )
;; converts a list of digits to the coresponding number ( define ( convert list-digits ) ( foldr ( lambda ( digit accum ) ( ( 10 accum ) digit )) 0 list-digits ))
( define ( count lotp ) ( foldl ( lambda ( elem accum ) ( 1 accum )) 0 lotp ))
( define ( sum lotp ) ( foldl ( lambda ( elem accum ) ( elem accum )) 0 lotp ))
CS 173 Scheme Tutorial Solutions Fall 2002
;; finds the average value of a list of numbers ( define ( average-price lotp ) ( / ( sum lotp ) ( count lotp )))
;; Purpose: To convert a list of Farenheit temps to a list of Celsius temps ( define ( tempFC list-Ftemps ) ( map ( lambda ( tempF ) ( ( / 5 9) ( tempF 32 ))) list-Ftemps ))
;; removes all values above a user specified value from a list ( define ( eliminate-exp lotp ua )
;; creates a function which is the composition of two other functions ( define ( compose-func a b ) ( lambda ( x ) ( a ( b x ))))
;; flattens a list of sublists of numbers into a list of numbers ( define ( flatten list-of-lists ) ( cond [( empty? list-of-lists ) empty ] [ else ( append ( first list-of-lists ) ( flatten ( rest list-of-lists )))]))
( define ( flatten-foldr list-of-lists ) ( foldr append empty list-of-lists ))