Thoughts about modules

Kirk McDonald kirklin.mcdonald at gmail.com
Fri Jun 30 00:47:50 PDT 2006


Derek Parnell wrote:
> On Thu, 29 Jun 2006 21:09:42 -0700, Kirk McDonald wrote:
> 
> 
>>from util.str import SetEnv, GetEnv, Expand, ExpandEnvVar, ends, begins, 
>>enquote, ustrip, ustripr, IsLike, YesNo, TranslateEscapes;
> 
> 
> Unfortunately this is not completely adequate because one can't always
> import the existing name verbatim, sometimes you need an alias to
> disambiguate it. Maybe something more like ...
> 
> import from util.str SetEnv, GetEnv, Expand, ExpandEnvVar, ends, begins, 
>      enquote, strip as ustrip, stripr as ustripr, IsLike, YesNo,
>      TranslateEscapes;

Except for the rearranging of "import" and "from", this is exactly 
Python's behavior.

> 
> The "from" key would tell D that only the listed names are to come into the
> namespace and all others are excluded, such that any attempt to reference
> them in the code would cause an error. The current semantics could still
> exists by not using the "from" keyword.
> 

This could work (for both "from" and "as"), though I can't help but 
wonder what the consequences of having a module named "from" would be. 
:-) (If it's not a keyword, then this must be allowed.)

import from from a, b, c as d;

> And notice the "strip as ustrip". This is because the real name is
> util.str.strip but this clashes with std.string.strip so we have to create
> an alias for one of them.
> 

-- 
Kirk McDonald



More information about the Digitalmars-d mailing list