[plt-scheme] Lazy Evaluation

From: james pack (jamestidwellpack at gmail.com)
Date: Tue Feb 9 12:23:06 EST 2010

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.


Posted on the users mailing list.