473,473 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

assignments - want a PEP

>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.

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?

Regards,
Kay

Jul 18 '05 #1
3 1432
"Kay Schluehr" <ka**********@gmx.net> writes:
a = Symbol()
a

a


Use

a = Symbol('a')

instead and it should solve most of the problems you mention. What's
supposed to happen anyway, in your proposal, after

a = Symbol()
b = a
print b

?
Jul 18 '05 #2
On 31 Mar 2005 14:48:00 -0800, "Kay Schluehr" <ka**********@gmx.net> wrote:
From time to time I still use my old Mathematica system. TheMathematica 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:
aa

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()
aa

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
Jul 18 '05 #3

Bengt Richter wrote:
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.


Hmmm... feels like a good idea if extended to use properties as special
constructors:
expr = CAS(Expr)
expr.a a type(expr.a) <type 'Expr'>
expr.a+expr.b a+b

or a bit shorter if Expr becomes the "master algebra":
_ = CAS(Expr)
_.a + _.b

a+b

Regarding that an object oriented CAS will mix an arbitray number of
algebras/namespaces that use algebraic operators homogenously
referencing namespaces is a reasonable for providing clarity.

A helpfull suggestion. Thanks Bengt!

Regards,
Kay
Regards,
Kay

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: svilen | last post by:
hi. this was named but it is misleading. i want to have the order of setting items in intrinsic dicts (keyword args, or class attributes, etc). which is, a prdered dict trhat matches the...
15
by: Josef Meile | last post by:
Hi, Textually from the highlights of python 2.4: "Assigning to None - the compiler now treats assigning to None as a SyntaxError." I think in general assignments to built-in types,...
4
by: Jacek Generowicz | last post by:
I am dealing with an application which reads in configurations by calling (a wrapper around) execfile. Any configuration file may itself execfile other configuration files in the same manner. I...
3
by: bearophileHUGS | last post by:
The current version of ShedSkin (http://shedskin.sourceforge.net/ experimental Python to C++ compiler) is rather alpha, and the development work is focused on debugging and implementing some more...
21
by: Paul Steckler | last post by:
Here's some code that's giving me differing results, depending on the compiler. typedef foo { int A,B; } FOO; int main() {
7
by: dm | last post by:
Hi, I'd like to know if the C standard can guarantee that an assignment to/from a variable will be atomic, that is will occur in a single indivisible instruction. For example, if I have the...
8
by: Fredrik Tolf | last post by:
Hi list! I'm relatively new to Python, and one thing I can't seem to get over is the lack of in-expression assignments, as present in many other languages. I'd really like to know how Python...
0
by: Simon Burton | last post by:
I've been doing a little c programming again (ouch!) and it's just hit me why python does not allow assignment inside expressions (as in c): because it is absolutely essential that all assignments...
6
by: Erik | last post by:
Hello, For many years ago I implemented my own string buffer class, which works fine except assignments - it copies the char* buffer instead of the pointer. Therefore in function calls I pass...
17
by: Brian Blais | last post by:
Hello, I have a couple of classes where I teach introductory programming using Python. What I would love to have is for the students to go through a lot of very small programs, to learn the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.