Proposal for adding symbols within Python

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sun Nov 13 10:25:31 EST 2005


On Sun, 13 Nov 2005 12:33:48 +0100, Pierre Barbier de Reuille wrote:

> Steven D'Aprano a écrit :
>> On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote:
>> 
>> 
>>>The problem, IMHO, is that way you need to declare "symbols"
>>>beforehands, that's what I was trying to avoid by requiring a new syntax.
>> 
>> 
>> ???
>> 
>> If you don't declare your symbols, how will you get the ones that you want?
>> 
>> I don't understand why it is a problem to declare them first, and if it is
>> a problem, what your solution would be.
>> 
> 
> Well, just as Python do not need variable declaration, you can just
> *use* them ... in dynamic languages using symbols, they just get created
> when used (i.e. have a look at LISP or Ruby).

If you want to be technical, Python doesn't have variables. It has names
and objects.

If I want a name x to be bound to an object 1, I have to define it
(actually bind the name to the object):

x = 1

If I want a symbol $x$ (horrible syntax!!!) with a value 1, why shouldn't
I define it using:

$x$ = 1

instead of expecting Python to somehow magically know that I wanted it?
What if somebody else wanted the symbol $x$ to have the value 2 instead?


>> [snip]
>> 
>> 
>>>Well, I don't think enumarated objects ARE symbols. I can see two
>>>"problems" :
>>> 1 - in the implementation, trying to compare values from different
>>>groups raises an error instead of simply returning "False" (easy to fix ...)
>> 
>> 
>> As you say, that's easy to fix.
>> 
>> 
>>> 2 - You have to declare these enumerable variables, which is not
>>>pythonic IMO (impossible to fix ... needs complete redesign)
>> 
>> 
>> Are you suggesting that the Python language designers should somehow
>> predict every possible symbol that anyone in the world might ever need,
>> and build them into the language as predefined things?
>> 
>> If that is not what you mean, can you explain please, because I'm confused.
>> 
> 
> Well, the best I can propose is for you to read the discussion with Mike
> Meyer.
> He pointer out the flaws in my proposal and we're trying to precise things.

I've read the discussion, and I am no wiser.

You haven't explained why enums are not suitable to be used for symbols.
You gave two "problems", one of which was "easy to fix", as you said
yourself, and the other reason was that you don't want to define enums as
symbols. 

If you don't want to define something manually, that can only mean that
you expect them to be predefined. Or am I misunderstanding something?



-- 
Steven.




More information about the Python-list mailing list