[plt-scheme] Re: Style question

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Wed Jun 3 15:05:17 EDT 2009

On Jun 3, 2009, at 6:44 AM, Eli Barzilay wrote:

> On Jun  3, Tomasz Skutnik wrote:
>> Thanks for clarification Eli. That expanded my understanding of the
>> naming problem. However, as I see it, the main issue is not with
>> error reporting during bug hunt (where "more correct" name is
>> desirable).  It's about signaling of missing keyword parameters on
>> function invocation - which IMHO is rather common programming
>> mistake.
> Well, if you do what I suggested:
>>>  #lang scheme
>>>  (provide make-foo)
>>>  (define-struct internal-foo (x y z))
>>>  (define (make-foo ...) ... make-internal-foo ...)
> then the error reports *will* talk about `make-foo'.
>> For me, the best option would be using procedure-rename, if it would
>> retain keyword parameters. [...]
> I think that the purpose of `procedure-rename' is unclear in this
> thread.  Its intention is as a tool where the name is determined at
> run-time -- if you want to use a different name for your function
> definition, then this was always possible.  Here's an easy way to do
> it:

It permits the new name to be determined at run time, and that makes  
it more useful, but that doesn't mean that it's a bad thing to use it  
when the name is statically known. It seems reasonable to prefer  
'procedure-rename' to some contortion of bindings designed to drop the  
right name on the right lambda form.

I think we should just make 'procedure-rename' (as exported from  
scheme/base, anyway) handle keyword procedures.

>  (define foo (let ([bar (lambda (x) x)]) bar))
> or a possibly more convenient form:
>  (define foo
>    (let ()
>      (define (bar x) x)
>      bar))

That's a bad idea if the procedure's body needs to refer to the outer  
binding of the name you want to give it.

   (define create-pool
     (let ([make-pool (lambda () (make-pool <stuff>))])

works, but

   (define create-pool
     (let ()
       (define (make-pool) (make-pool <stuff>))

doesn't, because the "real" make-pool is shadowed.

Only use let to do procedure renaming.


Posted on the users mailing list.