On 31 Mar 2005 14:48:00 -0800, "Kay Schluehr" <[EMAIL PROTECTED]> wrote:
>>From time to time I still use my old Mathematica system. The >Mathematica language has some nice properties. The one I like best is >the possibility to create symbols from nothing. Translated into the >Python realm following creations are possible: > >>>> a >a > >That's it. Just make an 'a' as a pure symbol. The reason for those >symbols is late evaluation. Most of the time an expression should be >transformed and simplified before it is finally evaluated using >concrete numbers or other stuff. I tried to mimic this in Python using >a Symbol() class: > >>>> a = Symbol() >>>> a >a > >So 'a' would be a Symbol object that is represented by the name "a" not >by the standard format information that tells us that a is some member >of class Symbol(). Starting with Symbol() subclsses of Symbol() e.g >Expr() could overload operators like __add__, __mul__ etc. in order to >create new symbolic objects: > >>>> a,b = Expr(),Expr() >>>> (a+b)/c >a+b >--- > c > >The availability of Symbol() would make it easy to create a Computer >Algebra System ( CAS ) in Python, just using standard Python operators. > >Unfortunately it is not possible to implement Symbol() in an elegant >way. Symbol() has to retrieve somehow it's own name from the >environment where the name is created, but no assignment/name binding >event is accessible to Python objects. If you let your symbols like a live in a CAS class instance attribute namespace, you can do what you like, pretty much. I.e., cas = CAS() cas.a # like your plain a, where you said "that's it" cas.a, cas.b = cas.Expr(), cas.Expr() (cas.a + cas.b)/cas.c Etc. > >I want to propose making name binding accessible by introducing an >__assign__ method which is called, whenever an object is bound to a >name. By default the __assign__ method does nothing at all but can be >implemented by custom classes. > >def __assign__(self,own_name): > # do somtehing with me and my name > >Instead of changing the behaviour of the current assignment operator >"=" one could think about introduction of a new assignment ":=" that is >connected to the __assign__ method of custom classes if available. > >What do You think? > I think Guido does not want bare names to work like properties, even though some of that could be interesting ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list