<br><br><div class="gmail_quote">On Tue, Feb 9, 2010 at 12:23 PM, james pack <span dir="ltr"><<a href="mailto:jamestidwellpack@gmail.com" target="_blank">jamestidwellpack@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I'm trying to create a function that returns a function, here's the<br>
code<br>
<br>
(define (make-getter pattern url-string)<br>
(lambda (keyword)<br>
(regexp-match* pattern<br>
(get-html-page (force url-string)))))<br>
<br>
(define get (make-getter<br>
#rx"<h2 class=r>([0-9]+)\""<br>
(delay (string-append "http://<br>
<a href="http://www.google.com/custom?hl=en&sitesearchq=" target="_blank">www.google.com/custom?hl=en&sitesearchq=</a>" keyword "&btnG=Search"))))<br>
<br>
(get "cat")<br>
<br>
<br>
What I want the make-getter function to do is return a function that<br>
will take an argument but since the returned function itself is<br>
dependent on the argument (keyword), i'm getting an error saying that<br>
the keyword is undefined. </blockquote><div><br></div><div>Actually, the returned function, as you've written it, isn't dependent on the argument. make-getter is returning a lambda expression that binds, but doesn't use, the keyword argument. Instead, you're trying to use keyword in a place where it isn't bound.</div>
<div><br></div><div>You probably want something like:</div><div><br></div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">(define (make-getter pattern make-url-string)<br>
(lambda (keyword)<br> (regexp-match* pattern<br> (get-html-page (make-url-string keyword)))))</span></div><div><font face="arial, sans-serif"><span style="border-collapse:collapse"><br>
</span></font></div><div><font face="arial, sans-serif"><span style="border-collapse:collapse"><span style="font-size:13px">(define get (make-getter<br>
#rx"<h2 class=r>([0-9]+)\""<br> (lambda (keyword) (string-append "http://<br><a href="http://www.google.com/custom?hl=en&sitesearchq=" style="color:rgb(64, 100, 128)" target="_blank">www.google.com/custom?hl=en&sitesearchq=</a>" keyword "&btnG=Search"))))</span></span></font></div>
<div><font face="arial, sans-serif"><span style="border-collapse:collapse"><br></span></font></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I thought using delayed evaluation would<br>
make the code work but it didn't.<br><br></blockquote><div><br></div><div>Lazy evaluation doesn't violate lexical scope (and that's a good thing). In other words, *when* the expression is evaluated has nothing to do with the binding environment in which it's evaluated. The latter is determined by inspecting the syntax of the program, rather than by trying to trace its run-time behavior.</div>
<div><br></div><div> -Jon</div><div><br></div></div>