[plt-scheme] Re: Style question

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Jun 3 06:44:48 EDT 2009

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:

  (define foo (let ([bar (lambda (x) x)]) bar))

or a possibly more convenient form:

  (define foo
    (let ()
      (define (bar x) x)
      bar))

and it's easy to make a macro out of all of this:

  (define-syntax-rule (define/renamed external-name (internal-name . args)
                        body ...)
    (define internal-name
      (let ()
        (define (external-name . args) body ...)
        external-name)))

or even directly provide the renamed version, and skip the internal
name completely (making it inaccessible within the defining module):

  (define-syntax-rule (define/provide (external-name . args)
                        body ...)
    (begin
      (define hidden-name
        (let ()
          (define (external-name . args) body ...)
          external-name))
      (provide (rename-out [hidden-name external-name]))))

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


Posted on the users mailing list.