[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: import suggestion

This page is part of the web mail archives of SRFI 83 from before July 7th, 2015. The new archives for SRFI 83 contain all messages, not just those from before July 7th, 2015.

Ray Blaak wrote:
> What happens if you need to do multiple actions for a library, e.g.
> (import (only "stack" push! pop!)
>            (add-prefix "stack" stack:)
>            (rename "stack" (clear! empty!))
> This could have a well-defined meaning (e.g. one gathers all "stack"
> related clauses to process them in aggregation), but it seems
> unnecessary, complex, and confusing to keep respecifying "stack"

I'm pretty sure the example above doesn't do what you intended. Based on
the spec, it would:

1. Import only push! and pop! from "stack," then
2. Import all identifiers from "stack" with the stack: prefix, then
3. Import all identifiers from "stack" again, except for clear!, which
   is renamed to empty!.

The net result would include push!, stack:push!, stack:clear!, empty!,
etc. -- almost certainly not what you meant. If I understand correctly,
that's not even legal, since it imports some identifiers more than once.

Instead of importing "stack" multiple times with different modifiers, I
think you're supposed to nest the modifiers, with "stack" at the
innermost point, i.e.:

    (import (add-prefix (rename (only "stack" push! pop! clear!)
                                (clear! empty!)

This version will:

1. Start with all identifiers from "stack."
2. Narrow the list to only push!, pop!, and clear!.
3. Rename clear! to empty!.
4. Apply the stack: prefix to all three names.

It avoids repetition of the "stack" and more precisely states how to
perform the namespace modifications. I think the result is a bit
obscure, although I would expect few programs to actually combine all
three modifiers like this.
Bradd W. Szonye