Coding style best practices (was: Re: [plt-scheme] Scheme program to serve files over HTTP)

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Jul 28 12:59:16 EDT 2009

On Jul 28, Amit Saha wrote:
> > - In larger programs you'll want to record types in comments.  E.g.:
> > 
> > ;; serve : Integer -> (-> Void)
> > (define (serve port-no)
> >   (define listener (tcp-listen port-no 5 #t))
> >   (define (loop)
> >     (accept-and-handle listener)
> >     (loop))
> >   (define t (thread loop))
> >   (lambda ()
> >     (kill-thread t)
> >     (tcp-close listener)))
> > 
> 
> serve : Integer -> (-> Void)
> 
> So this indicates a procedure by the name 'serve' taking a Integer
> parameter and a 'Void' return type? However, here I am returning a
> procedure, right ?

It's a function by the name of `serve', that takes an integer and
returns a (-> Void) value.  This value that is returned is itself a
function too (it has an arrow), it takes the argument types on its
left (no arguments), and returns void.  And that's exactly what your
code is doing.


> Also, how would I specify more than one parameter? like serve : Integer, 
> Integer-> (-> Void)

Just like that, except that we don't use commas.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.