[plt-scheme] Local function definition

From: Dor Kleiman (dor at ntr.co.il)
Date: Mon Jan 12 04:29:13 EST 2004

Which brings me to something I've always wondered about: Why can't you
commingle definesand expressions?

-----Original Message-----
From: Robby Findler [mailto:robby at cs.uchicago.edu] 
Sent: Monday, January 12, 2004 4:31 AM
To: Guillaume Marceau
Cc: plt-scheme at list.cs.brown.edu
Subject: Re: [plt-scheme] Local function definition

  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

At Sun, 11 Jan 2004 20:18:57 -0500 (EST), Guillaume Marceau wrote:
> Does that means there is no define-like special form for local
definitions?

Oh, no. Just use internal definitions. Their syntax is a little wierd
-- unlike unit definitions and class definitions, you cannot comingle
definitions and expressions (all definitions must come first), but you
can certainly put definitions inside a lambda and a let (and inside a
definition that hides a lambda):

(define (find-short-path graph red-nodes blue-nodes)
  (define (get-siblings loci)
     (map (lambda (sibling) (make-loci sibling (loci-stack loci)))
          (graph-adjs graph (loci-node loci))))])
  ...)

Check out r5rs on internal definitions.

Robby


Posted on the users mailing list.