WXME0106 ## wxtextwxtabwxmediawximage$(lib "comment-snip.ss" "framework")+(lib "collapsed-snipclass.ss" "framework")drscheme:sexp-snipdrscheme:syntax-snipclass%drscheme:number,(lib "number-snip.ss" "drscheme" "private")drscheme:bindings-snipclass%drscheme:lambda-snip%drscheme:define-snip%java-comment-box%java-interactions-box%"drscheme:vertical-separator-snip%wxbaddrscheme:xml-snip(lib "xml-snipclass.ss" "xml")drscheme:scheme-snip"(lib "scheme-snipclass.ss" "xml")test-case-box% HTML BulletwxlocqK ZZ StandardK-adobe-courier ZZ?\???""Matching Parenthesis Style?\???""????&&(framework:syntax-coloring:scheme:symbol????&&)framework:syntax-coloring:scheme:keyword????&&????t)framework:syntax-coloring:scheme:comment????t????)&(framework:syntax-coloring:scheme:string????)&*framework:syntax-coloring:scheme:constant????)&????>&-framework:syntax-coloring:scheme:parenthesis????>&????@'framework:syntax-coloring:scheme:error????@????'framework:syntax-coloring:scheme:other????????Qp1drscheme:check-syntax:lexically-bound-identifier????Qp????D*drscheme:check-syntax:imported-identifier????D%profj:syntax-coloring:scheme:keyword????????""$profj:syntax-coloring:scheme:string????""%profj:syntax-coloring:scheme:literal????""%profj:syntax-coloring:scheme:comment????t#profj:syntax-coloring:scheme:error????@(profj:syntax-coloring:scheme:identifier????&&%profj:syntax-coloring:scheme:default????F???????XMLF???????K-adobe-courier ZZG???????????QQG????QQG????d?????^???F@\??????F?\??????F?\???F???????F????F?\???22F?]??????F???????F????QQF?\???QQF????K????K?\???F?]???@F?]???F@\???F?\??????F?\???K????>&K????$#K???????K????""K?\???K????K?\???F?33@\??????F?33@\??????????F???????F???????K?]??????K?陙]??????F?陙]??????F?陙??????K?陙??????F?陙??????K?陙??????F?陙??????K?陙??????F?]??????K???????F????F???????K?]??????K?陙]??????F?陙??????F?陙]??????F?z`??????K?陙??????F?陙]??????F?33@\??????F?33@\???F?\??????F?\??????????K?\???F?陙???F?33@???K????CBoK@\???K?33@\???>&F???????K???? ?????????\F?\???@F?陙]??????K?陙???>&K?\??????K????@K?\???@K?\]???@ :;;; Course Name: Practical Functional Programming (CS6960) !;;; Student Name: Park, Jong Chun ;;; Student ID #: 00259446   ;  L i b r a r a y  t o  u s e  p r e e x p (require (lib  "pregexp.ss"))   ; File accumulating forecast data (define FORECAST "forecast.txt")   ;  Fi l e  a c cu m u l a t i n g  d a i l y  w e a t h er  i n f o (define  DAILY-REPORT "daily-report.txt")   ; O p e n  t h e  f i l e s  t o  r e a d (define f (open-input-file FORECAST)) (define d (open-input-file DAILY-REPORT))   ;  R e a d  t h e  d a t a  f r o m  t h e  f i l e s  a l r e a d y  o p e n e d (define READ-FORECAST (pregexp-split "  + " ( read-line  f)))  (define READ-DAILY-REPORT  (pregexp-split "  + " ( read-line d)))   (; Close the files after reading the data (close-input-port f) (close-input-port d)   ; ;  T E S T  P UR P O S E ;( display  READ-FO R E C A S T ) ;( display  "\n" ) ;( d i s p l a y  R E A D - D A I L Y - R E P O R T ) ;( display  "\n" )   ;  d a t e - m m :  l i s t - o f - s t r i n g  - >  st r i n g ; d a t e - m m  r e t u r n s  t h e  m o n t h  i n M M  f o r m a t  f r o m  a  l i s t  o f  s t r i n g ,  w e a t h e r  f o r e c a s t  i n f o . ;  (d a t e - m m  ' ( F E B  0 4  S U N  R A I N )  " s h o u l d  b e "  F E B . ;  ( de f i n e  ( d a t e - m m  l ) ;    ...(fir s t  l ) . . . ;    . . . ( r e st  l)...) (define (date-mm l)  (first l))   ; date- d d: list-of-string -> string ; date- d d returns the d a y in 7DD format from a list of string, weather forecast info. *; (date-mm '(FEB 04 SUN RAIN) "should be" 0 4. ; (define (date- d d l) ; ...(first l)... ; ...(rest l)...) (define (date-dd l)  (first (rest l)))   ; da y: list-of-string -> string ; da y returns the day o f  a  w e 0ek from a list of string, weather forecast info. *; (date-mm '(FEB 04 SUN RAIN) "should be" S U N.  ; (define (da y l) ; ...(first l)... ; ...(rest l)...) (define (day l)  (first (rest (rest l))))   ; w e a t h e r: list-of-string -> string ; w e a t h e  r returns t h e A daily weather info from a list of string, weather forecast info. *; (date-mm '(FEB 04 SUN RAIN) "should be" R A I N.  ; (define ( w e a t h e r l) ; ...(first l)... ; ...(rest l)...) (define (weather l)  (first (rest (rest (rest l)))))   ; n e x t - d a y: list-of-string -> l i s t - o f -string ; n e x t - d a  y returns t h e  w e a t h e r i n f o  f o r  t h e  r e s t  o f  d a y s  e x c e p t  t o d a y   ;                   from  a  list of  string ,  weather  forecast  info. ; ( n e x t - d a y '(FEB 04 SUN RAIN  F E B  0 5  M O N  S N O W) "should be" ' ( F E B  0 5  M O N  S N O W ).  ; (define ( n e x t - d a y l) ; ...(first l)... ; ...(rest l)...) (define (next-day l)  (rest (rest (rest (rest l)))))   ;  s a m e - d a y ?  :  l i s t - o f - s t r i n g  li s t - o f - s t r i n g  - >  b o o l ;  s a m e - d a y ?  r e t u r n s  t r u e  i f  t he  d a y s  t o  c o m p a r e  a r e  t h e  s a m e ,  o th e r w i e  r e t u r n s  f a l s e . ;  ( s a m e - d a y ?  ' ( F E B  0 5  M O N  R A I N)  ' ( F E B  0 6  T U E  S U N N Y ) )  " s h o u l d  b e "  f a l s e . ;  ( d e f i n e  ( s a m e - d a y ?  f  d ) ;   . . . ( d a t e - m m  f )  ( d a t e - m m  d ) .. . ;   . . . ( d a t e - d d  f )  ( d a t e - d d  d ) .. . ;   . . . ( d a y  f )  ( d a y  d ) . . . ) (define (same-day? f d)  (and (string=? (date-mm f) (date-mm d))  (and (= (string->number (date-dd f)) (string->number (date-dd d)))  (string=? (day f) (day d)))))   ; d i s p l a y - m m - d d - d a y :  l i s t - o f - st r i n g  - >  v o i d ;  disp l a y - m m - d d - d a y  d i s p l a y s  th e  d a t e  i n f o  o n  t h e  s c r e e n . ;  ( d isp l a y - m m - d d - d a y  ' ( F E B  0 5  M O N  R A I N ) )  " s h o u l d  b e "  F E B  05 M O N . ;  ( d e fin e  ( d i s p l a y - m m - d d - d a y  f) ;   . . . ( dat e - m m  f ) . . . ;   . . . ( d a te-dd  f ) . . . ;   . . . ( d a y  f )...) . . . ) (define (display-mm-dd-day f)  (begin  (display (date-mm f))  (display " / ")  (display (date-dd f))  (display " ,  ")  (display (day f))  (display " : : ")))   ; display- w e a t h e r: list-of-string -> void  ; display- w e a t h e r displays the w e a t h e r info on the screen.  ; (display- w e a t h e "r '(FEB 05 MON RAIN)) "should be" R A I N. ; (define (display- w e a t h e r f) ; ...(date-mm f)... ; ...(date-dd f)... ; ...(day f)...) . . . ;   . . . ( w e at h er  f ). . .) (define (display-weather s f)  (begin  (display s)  (display " < ")   (display  (weather  f))   (display  " >  ")))     ; display- e v a l: l i s t - o f - s t r i n g list-of-string -> void  ; display- e v a  l displays t h e  e va l u a t i o n  r e s u l t  f o r  c o m p a r i n g  w e a t h e r  f o r e c a s t  a n d  r e a l  w e a t h e r .  ; (display- e v a l '(FEB 05 MON RAIN)  ' ( F E B  0 5  M O N  S N O W )) "should be" m i s p r e d i c t. ; (define (display- e v a l f  d) ; ...(date-mm f)... ( d a t e - m m  d) . . . ; ...(date-dd f)... ( d a t e - d d  d) . . . ; ...(day f)...)... (d a y  d ) . . . #; ...(weather f)...(weatehr d)...)  (define  (display-eval  f  d)   (cond   [(string=?  (weather  f)  (weather  d))   (display  " \ t->  c o r r e c t l y  p r e d i c t e d!!!\n ")]   [else   (display  " \ t->  m i s p r e d i c te d! ! ! \ n ")]))      ; display- f i n a  l-result: n u m  n  um -> void  ; display- f i n a  l displays t h e  fi n a l  r e s u l t  o f  e v a l u a t i o n .  ; (display- f i n a l - r e s u l 5t '(FEB 05 MON RAIN) '(FEB 05 MON SNOW)) "should be" 0 / 1 %  c o r r e c t. ; (define (display- f i n a l - r e s u lt  b a s e  c o r r e c t) ;   . . . )  (define  (display-final-result  base  correct)   (begin   (display  (string-append   " T o t a l  "   (number->string  correct)   " d a y s  ou t  o f  "   (number->string  base)   " d a y s  are   correctly   predicted  b y  N O A A ."))))  . (display ( string-append  ,"the percentage of forecast correctness is "  (number->string (/ correct base))  "%.\n\n"))))    ; d o - e v a l - w e a t h e r: n u m  n u m  n u 'm list-of-string list-of-string -> void ; d o - e v a l - w e a t h e r  e v a l u a t e s  t he  c o r r e c t n e s s  o f  t h e  w e a t h e r  f o r e c a s t . ; ( d o - e v a l - w e a t h e r 1  1  0 4 '(FEB 05 MON RAIN) '(FEB 05 MON SNOW)) "should be" 0 %  c o r r e c t.  ; (define ( d o - e v a l - w e a t h e r  b a se  t  c f d) "; ...(date-mm f)...(date-mm d)... "; ...(date-dd f)...(date-dd d)... ; ...(day f)...)...(day d)... #; ...(weather f)...(weatehr d)...)  (define  (do -eval-weather  base  t  c  f  d)   (cond   [(>  base  0)   (cond   [( same-day?  f  d)   (begin   (display-mm-dd-day  f)   (display-weather  " F or ec a st e d " f)   (display-weather  " R ea l " d)   (display-eval  f  d)   (cond   [(string=?  (weather  f)  (weather  d))   (do-eval-weather  (-  base  1)  t  (+  c  1)  (next-day  f)  (next-day  d))]   [(do-eval-weather  (-  base  1)  t  c  (next-day  f)  (next-day  d))]))]   [else   ( display-error  " Error: you 're  trying  to  compare  the  weather  for  the   different  days.\n ")])]   [else   (begin   (display    ( string-append  " \  nComparison  between  the  weather  forecast  and  the  real  weather  i s  n o w  completed  for  "   (number->string  t)  " days.\n "))  (display-fin al-result t c))]))   ; eval-weather: s t r in g  n u m  num -> void ; eval-weather ,  t h e  m a i n  p rog ra m 4, evaluates the correctness of the weather forecast. ; (eval-weather 1  ) "should " c al l  d o - e v a l - w e a t h e r. ; (define (eval-weather m m  d d  num) ;   . . . ) (define ( eval-weather mm dd num f d)  (cond  [(and (string=? mm (date-mm f))  (= dd (string->number (date-dd f))))  (do-eval-weather num num 0 f d)]  [else  (eval-weather mm dd num (next-day f) (next-day d))]))    ;do-eva l - w e a t h e r  n u m n u m  0  R E A D - FO R E C A S T  R E A D - D A I L Y - R E P O R T )) ;  s t a r t - e v a l - w e a t h e r:  s t r i n g  n u m  n u m  - >  v o i d ;  s t a r t - e v a l - w e a t h e r,  t h e  m a i n  p r o g r a m ,  s t a r t  t h e  e v a l u t i o n  f o r  a  c e r t a i n  n u m b e r  o f  d a y s  g i v e n  f r o m   ;       a  c e r t a i n  d a y g i v e n . ;  ( d e f i n e  ( s t a r t - e v al - w e a t h e r  m m  d d  n u m ) ;    . . . ) (define (start-eval-weather mm dd num)  (begin  (display " \ n \ n "Weather evaluation starting from ")  (display mm)  (display " ")  (display (number->string dd))  (display " for ")  (display (number->string num))  (display " days started...\n \ n")    (eval-weather  mm  dd  num  READ-FORECAST  READ-DAILY-REPORT)))   ;  W E L C O MI N G  M E S S A G E  (display  " :  start-eval-weather  M O N  D D  D A Y S \n ")  (display  " \ t \ t \ t  *  M M  D D  i s  t h e  s t a r t i n g  d a y  t o  b e g i n  t h e  w e a t h e r  e v a l u t i o n . \ n ")  (display  " \ t \ t \ t  *  D A Y S  i s  t h e  n u m be r  o f  d a y s  t o  ev a l u a t e .  M a x  n u m b er  a l l o w d  t o  e n t e r  i s  5 . \ n \ n \ n ")   (start-eval-weather  " FEB " 4  5  )  (start-eval-weather  " FEB " 5  4  )  (start-eval-weather  " FEB " 6  3  )  (start-eval-weather  " FEB " 7  2  )  (start-eval-weather  " FEB " 8  1  )  (start-eval-weather  " FEB " 5 3 )