<div dir="ltr">Hello, can anyone offer an idiom/thinking process/approach critique on my code below? I'm new to racket and trying to program in racket, not program python in racket syntax ;)<br><br>#lang racket<br>(require json)<br>
(require net/url)<br><br>(define data-set<br> (let* (<br> ;; Turn url into a net/url-struct so you can allow a different search query as well as other customizations<br> ;; easily.<br> [api-url (string->url "<a href="http://gdata.youtube.com/feeds/api/videos/?alt=json&v=2&category=Movies&q=Inception">http://gdata.youtube.com/feeds/api/videos/?alt=json&v=2&category=Movies&q=Inception</a>")]<br>
;; figure out how to use call/input url<br> [in (get-pure-port api-url #:redirections 2)]<br> [json-blob (read-json in)])<br> (close-input-port in)<br> json-blob))<br><br>(struct movie (title price link))<br>
(define movies (hash-ref (hash-ref data-set 'feed) 'entry))<br><br>(define (make-movie movie-result)<br> (let* (<br> [title (hash-ref (hash-ref movie-result 'title) '$t)]<br> [price (with-handlers ([exn:fail? (lambda (exn) 0)])<br>
(hash-ref (car (hash-ref (hash-ref movie-result 'media$group) 'media$price)) 'price))]<br> [link (hash-ref (car (hash-ref movie-result 'link)) 'href)]<br> [movie-to-return (movie title price link)])<br>
movie-to-return))<br><br>(define (make-movie-listing movie)<br> (list (movie-title movie) (movie-price movie) (movie-link movie)))<br><br>(define (show-all-movie-listings)<br>(map make-movie-listing (map make-movie movies)))<br>
<br>(define (get-relevant-movie-listings movie)<br> ;; TODO: Figure out how to pass paramters into a function with map. Maybe lambda?<br> (cond<br> [(string=? (movie-title movie) "Inception") movie]))<br><br>
;; TODO: Make this into a function after figuring out how to pass parameters into a function with map.<br>(define find-movie <br> (car(map get-relevant-movie-listings (map make-movie movies))))<br><br>(define inception-movie find-movie)<br>
(movie-title inception-movie)<br></div>