[racket-dev] What is handle in racket?

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Jan 21 08:12:29 EST 2011

2011/1/21 Insik Cho <iminsik at gmail.com>:
> hi guys,
>
> I have used 'call/input-url' function frequently, whose definition is:
>
> (call/input-url URL connect handle) → any
> URL : url?
> connect : (url? . -> . input-port?)
> handle : (input-port? . -> . any)
>
> I coded like:
>
> (define a-url (string->url "http://www.google.com"))
> (call/input-url a-url get-pure-port (lambda (p) (display (read-bytes 1024
> p))))
>
> Tired to type 'lambda' function, I extracted it like:
>
> (define a-url (string->url "http://www.google.com"))
> (define (read-1024 p) (display (read-bytes 1024 p)))
> (call/input-url a-url get-pure-port (read-1024 p))

You are calling "read-1024" with the argument "p" which appears to be
free in this program. You don't want to pass call/input-url the result
of read-1024, you want to call it with read-1024 itself:

(call/input-url a-url get-pure-port read-1024)

>
> But, it generates errors.
>
> What's wrong?
> The question is: what 'handle' means?

'handle' has no special meaning in Racket. This library just uses that name.

> Is it like a callback function in C?

You could imagine that it is a "callback" from call/input-url to your
code to do something to the port before it closes it.

Jay

>
> Thanks in advance.
>
> - Joe
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93


Posted on the dev mailing list.