473,802 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

new python syntax: concatenation of functions

Hi,

I know the python community is not very receptive towards extending the
python syntax. Nevertheless I'd like to make a suggestion and hear your pro
and cons.

I want so suggest a concatenation operator like in mathematics: °
such that:

a(b(c(d))) <=> a°b°c(d)

Now, why do you think such an extension would be completely useless? ;)

Ciao
Uwe
Jul 18 '05 #1
14 1711
Uwe Mayer <me*****@hadiko .de> wrote:
Hi,

I know the python community is not very receptive towards extending the
python syntax. Nevertheless I'd like to make a suggestion and hear your pro
and cons.

I want so suggest a concatenation operator like in mathematics: °
such that:

a(b(c(d))) <=> a°b°c(d)

Now, why do you think such an extension would be completely useless? ;)


because neither in mathematics people agree on the order:
a°b(x) == a(b(x)) or
a°b(x) == b(a(x)) ?

besides, we are running out of ASCII
and besides, it would make more sence to introduce definable operators,
Ã* la C++

def (x)°(y):
return lambda par: x(y(par))
print (a°b)(x)

or, without leaving ascii:

def (x)composition( y):
return lambda par: x(y(par))
print (a composition b)(x)


--
-----------------------------------------------------------
| Radovan GarabÃ*k http://melkor.dnp.fmph.uniba.sk/~garabik/ |
| __..--^^^--..__ garabik @ kassiopeia.juls .savba.sk |
-----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
Jul 18 '05 #2
Radovan Garabik wrote:
or, without leaving ascii:

def (x)composition( y):
return lambda par: x(y(par))
print (a composition b)(x)


or without leaving Python

class Composition:
def __init__ (self, outer, inner):
self.outer = outer
self.inner = inner

def __call__ (self, *args):
return self.outer (self.inner (*args))

def __str__ (self):
return '%s ° %s' % (self.outer, self.inner)

Daniel

Jul 18 '05 #3
Radovan Garabik wrote:
because neither in mathematics people agree on the order:
a°b(x) == a(b(x)) or
a°b(x) == b(a(x)) ?


Is this a joke or what?

In mathematics people DO agree on the order:

if a:B->A and b:X->B, then a°b:X->A and
(a°b)(x)=a(b(x ))
Jul 18 '05 #4
what you would *really* like to do, is to be able to extend any class, and
override it's operators.
in your example, you would like to do something like:

def mul_funcs(self, other):
def temp(*args, **kw):
return self(other(*arg s, **kw))
return temp

and then:
FunctionType.__ mul__(self, other) = mul_funcs

"Daniel Dittmar" <da************ @sap.com> wrote in message
news:c2******** **@news1.wdf.sa p-ag.de...
Radovan Garabik wrote:
or, without leaving ascii:

def (x)composition( y):
return lambda par: x(y(par))
print (a composition b)(x)


or without leaving Python

class Composition:
def __init__ (self, outer, inner):
self.outer = outer
self.inner = inner

def __call__ (self, *args):
return self.outer (self.inner (*args))

def __str__ (self):
return '%s ° %s' % (self.outer, self.inner)

Daniel

Jul 18 '05 #5
On Thu, 11 Mar 2004 15:40:14 +0100, Curzio Basso
<cu**********@u nibas.ch> wrote:
Radovan Garabik wrote:
because neither in mathematics people agree on the order:
a°b(x) == a(b(x)) or
a°b(x) == b(a(x)) ?


Is this a joke or what?

In mathematics people DO agree on the order:

if a:B->A and b:X->B, then a°b:X->A and
(a°b)(x)=a(b(x ))


No they DON'T. Both notations are used. The notation (using
concatenation instead of circle to denote composition)

ba: x -> a(b(x))

is called diagrammatic order, and to be totally consistent we should
really write

x -> (x b) a

and is more often used in Category Theory (and close relatives like
Homological Algebra, etc. ) where you deal more with commutative
diagrams and the like and functions being applied to arguments appear
only very rarely.

With my best regards,
G. Rodrigues

Jul 18 '05 #6
Uwe Mayer <me*****@hadiko .de> wrote in message news:<c2******* ***@news.rz.uni-karlsruhe.de>.. .
Hi,

I know the python community is not very receptive towards extending the
python syntax. Nevertheless I'd like to make a suggestion and hear your pro
and cons.

I want so suggest a concatenation operator like in mathematics: °
such that:

a(b(c(d))) <=> a°b°c(d)

Now, why do you think such an extension would be completely useless? ;)

Ciao
Uwe


This is not useless, but does not require new notations. Just use
callable objects instead of functions and overload "*" to denote
composition.
Michele Simionato
Jul 18 '05 #7
On Thu, Mar 11, 2004 at 12:38:49PM +0100, Uwe Mayer wrote:
Hi,

I know the python community is not very receptive towards extending the
python syntax. Nevertheless I'd like to make a suggestion and hear your pro
and cons.

I want so suggest a concatenation operator like in mathematics: ??
such that:

a(b(c(d))) <=> a??b??c(d)

Now, why do you think such an extension would be completely useless? ;)


Composition of regular functions is not too useful in daily programming
tasks but concatenation of stream processes is quite useful. That is
what makes pipes in shell programming so effective.

Oren

Jul 18 '05 #8
On Thu, Mar 11, 2004 at 07:25:01AM -0800, Michele Simionato wrote:
This is not useless, but does not require new notations. Just use
callable objects instead of functions and overload "*" to denote
composition.


What about instances which already support __mul__ and __call__, a
combination that is perfectly legal today?

Jeff

Jul 18 '05 #9
Uwe Mayer <me*****@hadiko .de> wrote in message news:<c2******* ***@news.rz.uni-karlsruhe.de>.. .
Hi,

I know the python community is not very receptive towards extending the
python syntax. Nevertheless I'd like to make a suggestion and hear your pro
and cons.

I want so suggest a concatenation operator like in mathematics: °
such that:

a(b(c(d))) <=> a°b°c(d)

Now, why do you think such an extension would be completely useless? ;)

Ciao
Uwe


One of the things I like best about Python is the ease of use. This
method would hurt, rather than help the cause, IMO.

Here are the arguments against it:

(1) Where is the ° key on the keyboard? I do chemistry related
programing, and getting the ° into my GUIs (when I need to show
degrees) takes a bit of time and effort. The old way is easier to
type, ergo easier to use.

(2) The precedence and ordering of the operation would have to be more
clearly defined. This seems similar to the Unix pipe | operator.
However, in your proposal the result of c(d) is piped into b, and that
result is piped into a. This could lead to confusion. Should we have
a pipe-style °, in which case the syntax would be: c(d)°b°a, or do
the way you suggest: a°b°c(d). Either way would be confusing to
somebody. (As far as using | to get around the problems with point
(1),

(3) How would this operator play with other operators?

(4) For my personal style, I don't like to use constructs that are too
esoteric. I tend to avoid the tertiary operator in C++, and I tend
not to get fancy with the 'and' and 'or' operators in Python. It
makes code more readable and maintainable, IMO. Any programmer who
writes code without any thought to code maintainance is doing the
employer or client a disservice.

(5) One of the best aspects of Python is how easy it is to learn in
the first place. Someone with a background in C/C++, Java, Pascal,
Perl, etc. can learn python in a few hours. Adding weird operators
would make the process more difficult. Anyone who has been though
language Holy Wars knows that ease of use and learning is about the
only way to convince anyone to even consider Python.

Just my opinions.

-Bob
Jul 18 '05 #10

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

Similar topics

3
1999
by: François Miville-Dechêne | last post by:
I find your language very nice, it is actually more than three quarters of what I had been dreaming for years a programming language should be. But I mourn the passing of APL, another interpreted language. I like interpreted languages, for they can be used in calculator mode, testing function after function without bothering to code long protocols in the language and outside it. One suggestion I would propose would be to make common...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9115
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.