[plt-scheme] Lazy Evaluation

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Feb 10 00:05:00 EST 2010

Did you mean something like this: 

> (define (make-getter pattern url-string)
>  (lambda (keyword)
>    (regexp-match* pattern (get-html-page (url-string keyword)))))
> 
> (define get 
>   (make-getter #rx"<h2 class=r>([0-9]+)\"" 
>                (lambda (keyword) (string-append "http://www.google.com/custom?hl=en&sitesearchq=" keyword "&btnG=Search"))))
> 
> (get "cat")




On Feb 9, 2010, at 12:23 PM, james pack wrote:

> Hi,
> 
> I'm trying to create a function that returns a function, here's the
> code
> 
> (define (make-getter pattern url-string)
>  (lambda (keyword)
>    (regexp-match* pattern
>                    (get-html-page (force url-string)))))
> 
> (define get (make-getter
>                                        #rx"<h2 class=r>([0-9]+)\""
>                                         (delay (string-append "http://
> www.google.com/custom?hl=en&sitesearchq=" keyword "&btnG=Search"))))
> 
> (get "cat")
> 
> 
> What I want the make-getter function to do is return a function that
> will take an argument but since the returned function itself is
> dependent on the argument (keyword), i'm getting an error saying that
> the keyword is undefined. I thought using delayed evaluation would
> make the code work but it didn't.
> 
> This is actually an abstraction i'm trying to build, the code works
> normally if i don't try to return a function(ie, if i try the thing
> step by step imperatively).
> 
> I know i haven't explained my problem clearly, sorry for that (I'm
> quite confused how to because my vocabulary is limited). But if
> someone did get what my problem is, I would appreciate pointers on why
> this isn't working.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.