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 BulletwxlocnK 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?\??????F :;;; Course Name: Practical Functional Programming (CS6960) !;;; Student Name: Park, Jong Chun ;;; Student ID #: 00259446   ; Load the required library (require (lib "url.ss" "net")) (require (lib  "pregexp.ss"))   ,; Web site URL to grab weather forecast info (define web-site 5"http://www.wrh.noaa.gov/Saltlake/forecast/SFT.shtml") (define url:web-site-url ( string->url web-site))   \; Regular expressions to match patterns will be used in extracting proper data from raw data (define REST-AFTER-SLC "SALT LAKE CITY.*") (define REST-AFTER-FCST "FCST.*") (define  HERE-TO-OGDEN "(FCST).*OGDEN+?") (define HERE-TO-NORTHERN "(FCST).*NORTHERN+?") (define  REST-AFTER-LF "\n.*") (define  HERE-TO-LF  "(\n).*\n+?") (define REST-AFTER-SUN "SUN.*") (define  HERE-TO-EOF "^.*")   #; read-html: port -> list-of-string B; read-html reads a port which receives a HTML file from a website 0; and then extracts some useful part from it. ; (define (read-html port) ; ...) (define ( read-html port)  ( regexp-match  HERE-TO-OGDEN (first   ( regexp-match REST-AFTER-FCST (first  > ( regexp-match REST-AFTER-SLC port))))))   $; get-html: string -> list-of-string @; get-html opens a connection to the server and gets a HTML file ; (define (get-html url) ; ...) (define (get-html url)  (call/input-url url  get-pure-port  read-html))    ; raw-html is ; - list-of-string (define raw-html (get-html url:web-site-url))    ; day-part is ; - list-of-string (define day-part ( regexp-match  HERE-TO-LF (first  . ( regexp-match  REST-AFTER-LF (first  K ( regexp-match HERE-TO-NORTHERN  Y (first raw-html)))))))  ; date-part is ; - list-of-string (define  date-part ( regexp-match  HERE-TO-LF (first  / (reg exp-match  REST-AFTER-LF (first  L ( regexp-match REST-AFTER-SUN (first  j ( regexp-match HERE-TO-NORTHERN  x (first  raw-html )))))))))   ; forecast-part is ; - list-of-string (define  forecast-part ( regexp-match REST-AFTER-SLC (first raw-html)))   ; TEST PURPOSE using display ;(display day-part) ;(display "\n\n") ;(display date-part) ;(display "\n\n") ;(display forecast-part)  ; TEST PURPOSE using print ;(print day-part) ;(print date-part) ;(print forecast-part)  ;  a p p e n d - s t r i n g - t o - f i l e :  s t r i n g  s t r i n g  - >  v o i d ;  a p p e n d - s t r i n g - t o - f i l e  a p p e n d s  a  s t r i n g  t o  t h e  e n d  o f  a n  e x i s t i n g  f i l e ;  ( d e f i n e  (app end - s t r i n g - t o - f i l e  f  w ) ;    . . . ) (define (append-string-to-file f w)  (with-output-to-file f  (lambda ()  (display w)) 'append))   E; extract-data: number number number list-of-string -> list-of-string Q; extract-data extracts proper portion from a list of string, a part of HTML file +; (define (extract-data base start limit l) ; ...) (define ( extract-data base start limit l)  (cond  [(< base start) ( extract-data (+ base 1) start limit (rest l))]  [(= base start) ( extract-data (+ base 1) start limit (rest l))]  [(= base limit) empty]  [else  (cons (first l) ( extract-data (+ base 1) start limit (rest l)))]))   =; concat-data: number number list-of-string -> list-of-string Y; concat-data combines strings from a list of string starting at base and ending at limit C; (concat-data 0 2 '("Hello" "World" "?")) "should be" "HelloWorld" $; (define (concat-data base limit l) ; ...) (define ( concat-data base limit l)  (cond  [(= base limit) empty]  [else   (cons ( string-append   (first l)   " "   (first (rest l)))  ( concat-data (+ base 1) limit (rest (rest l))))]))   ; RAW-DATE is ; - list-of-string (define RAW-DATE ( extract-data 0 0 15  ( pregexp-split " +" (first  date-part))))  ; DATE is ; - list-of-string (define DATE ( concat-data 0 7 RAW-DATE))  ;(print DATE)   ; DAY is ; - list-of-string (define DAY ( extract-data 0 0 8  ( pregexp-split " +" (first day-part))))  ;(print DAY)    ; PHEN is ; - list-of-string (define PHEN ( extract-data 0 2 10  ( pregexp-split " +" (first  forecast-part))))  ;(print PHEN)    ; LOW-HIGH is ; - list-of-string (define LOW-HIGH ( extract-data 0 10 18  ( pregexp-split " +" (first  forecast-part)))) ;(print LOW-HIGH)    ; RAW-POP is ; - list-of-string (define RAW-POP ( extract-data 0 18 33  ( pregexp-split " +" (first  forecast-part)))) ; POP is ; - list-of-string (define POP ( concat-data 0 7 RAW-POP))  ;(print POP)   ; output port to write data (define  FORECAST  "forecast.txt")    i; build-list-of-string: number list-of-string list-of-string list-of-string list-of-string list-of-string ; -> list-of-string J; build-list-of-string makes a list of string from given 6 list-of-strings =; (build-list-of-string 1 '("H") '("G") '("K") '("L") '("O")) '; "should be" '("H" "G" "K" "L" "O") 3; (define (build-list-of-string num dt dy ph lh pp) ; (cond ; [(= num 0) ...] ; [else...])) (define (build-list-of-string num dt dy ph lh pp)  (cond  [(= num 0) empty]  [else  (cons  ( string-append   (first dt) " " (first dy) " " (first ph) " " (first lh) " "(first pp))  (build-list-of-string (- num 1) (rest dt) (rest dy) (rest ph) (rest lh) (rest pp)))]))   g d; record-forecast: number list-of-string list-of-string list-of-string list-of-string list-of-string  ; -> void F; record-forecast records the next 7-day weather forecast on to a file /; (define (record-forecast base dt dy ph lh pp) !; ...(append-string-to-file...) !; ...(record-forecast ...) ...) (define (record-forecast base dt dy ph lh pp)  (cond  [(= base 0) (record-forecast (+ base 1) (rest dt) (rest dy) (rest ph) (rest lh) (rest pp))]  [(< base 6)  (begin  (append-string-to-file FORECAST   ( string-append   (first dt) " " (first dy) " " (first ph) " " (first lh) " "(first pp) " "))   (record-forecast (+ base 1) (rest dt) ( rest dy) (rest ph) (rest lh) (rest pp)))])) (record-forecast 0 DATE DAY PHEN LOW-HIGH POP)  d; record-forecast: number list-of-string list-of-string list-of-string list-of-string list-of-string  ; -> void F; record-forecast records the next 7-day weather forecast on to a file ); (define (record-forecast base dt dy ph) ; . . . ( a pp e n d - s t ring - t o - f i l e . . . ) ;    . . . ( r ec o r d - f o r e c a s t  . . . )  ... ) (define (record-forecast base dt dy ph)  (cond  [(= base 0) (record-forecast (+ base 1) (rest dt) (rest dy) (rest ph))]  [(< base 6)  (begin  (append-string-to-file FORECAST   ( string-append   (first dt) " " (first dy) " " (first ph) " "))    (record-forecast  (+  base  1)  (rest  dt)  (  rest  dy)  (rest  ph)))]))  (record-forecast  0  DATE  DAY  PHEN)   *; **************************************** 4***************************************************;  &; DISPLAY WELCOMING MESSAGES FOR USERS  (display  ( string-append  "5-day weather  forecast is  recorded in  the  file ,  " FORECAST  ".\n"))  (display  ( string-append  " < D A T E  i n  M M - D D >  < D A Y >  < w e a t h e r >  f o r m a t  u s e d.\n\n "))