Re: Re: re-symboling an object

Mark Hahn <[email protected]> Sat, 31 Jul 2004 12:00:28 -0700
Newsgroups gmane.comp.lang.prothon.user
Organization Hahn Creative Applications
Message-ID <[email protected]>
On Sat, 31 Jul 2004 14:07:16 -0400, [email protected] wrote:

> Mark Hahn <[email protected]> wrote:
> 
>>On Sat, 31 Jul 2004 10:40:12 -0400, [email protected] wrote:
>>
>>> any comments on having a simple way of re-symboling an object?
>>> 
>>> examples;
>>> 
>>> #  to simplify reusing code in other languages
>>> 
>>> import foreign.library.chien as local.dog with sit as reposez-vous  
>>
>>I don't understand what that statement does.  Why can't you just do "from
>>foreign.library.chien import sit as reposez_vous" ?  (Hyphens are not
>>allowed in a variable name).
>>
> 
> that imports the "chien" object? but it doesn't rename it.
> i'd of thought it just imported "sit" and called it "reposez_vous"
> 
> what i had intended was to import chien, change its name, and any or all of its contents at once.

We don't allow that in Prothon.  We have made the decision that "from X
import *" is too dangerous.  It pollutes the name space and might shadow
something by accident.  You have to specify every name you are importing.
This is part of the principle "explicit is better than implicit".

If you disagree then you can start a thread stating your point and asking
other people to vote with you.

> 
>>> # or to help fit an interface, 
>>> 
>>> import file with readline as next_   # to make file an iterator
>>
>>You can do "from file import readline as File.next_".  That would do what
>>you want.
>>
> 
> yes, if file gets imported too.
> but wouldn't you have to repeat it for every symbol you wanted renaming?

Yes you would.  Can you show an example where this is a problem?  The worst
example we could think of was a math library and even that wasn't so bad.

You know you can say:

    from lib import a as b, c as d, e as f
                    g as h, i as j

You don't have to use a different statement for every name.

>>> ( of course file is now built-in, which i'm not sure is a good idea, but thats another story.)
>>
>>You can override File whether it is a built-in or not. Declaring a local
>>File object will shadow the built-in File.
>>
>     
> shaddowing isn't the point if you want a different name, file might mean something different in some language.
> 
>>  Being a built-in just means it is already loaded.  
> 
> does that mean you could stop it being loaded?

No, but you can just ignore it.  It does no harm if you don't use it.  You
could build Prothon without it easily but it isn't that large so it
wouldn't save you much.