473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PEP Proposal

Hi,

sorry, I have these ideas for longer than 10 years, please have a look on it
and comment on it. Thx.
----

This is another proposal for introducing types into Python.

There are many reasons for incorporating types into Python, but there is
also a lot of concern about doing so because of destroying the original
character of Python as a smart script language.

This proposal adds several advantages of Prolog(ue) techniques without
changing the natural understanding of Python as a language.
Proposal:

1. Method definitions can be non-unique if a type is prefixed to one or more
of its parameters, or the parameters differ in number.

2. A keyword 'reject' is added.

3. A keyword 'fail' is added.

4. A keyword 'cut' is added.
Definition:

1. A "type" is a String naming the actual class or class family which the
passed instanced is derived from, prefixing the parameter.

2. "'reject'" is a marker inside a function/method and signals that further
processing will not be done inside this method, but instead be passed to the
next available function/method in row, otherwise an implicit "fail" will
occur.

3. "'fail'" is a marker inside a function/method and signals that NO further
processing can be done in neither of this or the following
functions/methods.

4. "'cut'" is a marker inside a function/method that signals that the
failure of called functions/methods inside of it, following this statement,
automatically lead to a failure, instead of trying the next method -
normally, it would be "reject" instead.

5. Failure of functions/methods to outside of this new context are signalled
with a new exception e.g. "MethodRetrialError".

E.g.

def whoisthethief("List" x):
return iknowit(x)

def whoisthethief("String" x, "String" y):
return iknowit([x,y])

##########

def numeral_add(a, b):
if type(a)!=types.IntType:
reject
...

# equivalent to:

def numeral_add("Integer" a, b):
...
Sep 25 '08 #1
7 1044
En Thu, 25 Sep 2008 16:24:58 -0300, <py********@arcor.deescribió:
sorry, I have these ideas for longer than 10 years, please have a look
on it
and comment on it. Thx.

This is another proposal for introducing types into Python.
You got the terminology wrong. Python had "types" from the very start.
You're talking about some kind of generic functions, or an alternative
dispatch method.

Read this GvR blog post [1] and his next one; also see PEP 3124 by Phillip
J. Eby, who wrote a pretty good implementation of generic functions a long
time ago.

Your proposal requires a syntax change and three new keywords; all the
others achieve roughly equivalent results without requiring any change to
the core language.

[1] http://www.artima.com/weblogs/viewpo...?thread=155123

--
Gabriel Genellina

Sep 25 '08 #2
Gabriel Genellina wrote:
En Thu, 25 Sep 2008 16:24:58 -0300, <py********@arcor.deescribió:
>sorry, I have these ideas for longer than 10 years, please have a look
on it
and comment on it. Thx.

This is another proposal for introducing types into Python.

You got the terminology wrong. Python had "types" from the very start.
You're talking about some kind of generic functions, or an alternative
dispatch method.
Typed parameters. Method-Declaration-filtered-typed parameters. That's what
I'm thinking of.

I hear & I will answer.
Sep 25 '08 #3
On Sep 25, 12:24 pm, python-...@arcor.de wrote:
def whoisthethief("List" x):
return iknowit(x)

def whoisthethief("String" x, "String" y):
return iknowit([x,y])
I dunno if this is very Pythonic in nature, but I've done things like
rebinding methods dynamically.

ex:
>>def test(a):
.... return a * 2
....
>>print test(2)
4
>>def test2(b):
.... return b * 3
....
>>test = test2
print test(2)
6

In your case

def myNewThiefIdentifier(x,y):
return "Dunno"

whoisthethief = myNewThiefIdentifier
Which method would this affect (i.e. which 'whoisthethief')?

I assume you could figure it out, given a match on the signature, but
how much work would this require from the developer and the
interpreter?

(apologies in case Google Groups decide to multipost)
Sep 25 '08 #4
py********@arcor.de schrieb:
Gabriel Genellina wrote:
>En Thu, 25 Sep 2008 16:24:58 -0300, <py********@arcor.deescribió:
>>sorry, I have these ideas for longer than 10 years, please have a look
on it
and comment on it. Thx.

This is another proposal for introducing types into Python.
You got the terminology wrong. Python had "types" from the very start.
You're talking about some kind of generic functions, or an alternative
dispatch method.

Typed parameters. Method-Declaration-filtered-typed parameters. That's what
I'm thinking of.

I hear & I will answer.
Did you bother reading the pointers Gabriel gave to you? RuleDispatch or
other generic method dispatches exists for about as long as you ponder
about them.

Diez
Sep 25 '08 #5
On Sep 25, 4:04*pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Thu, 25 Sep 2008 16:24:58 -0300, <python-...@arcor.deescribió:
sorry, I have these ideas for longer than 10 years, please have a look *
on it
and comment on it. Thx.
This is another proposal for introducing types into Python.

You got the terminology wrong. Python had "types" from the very start. *
You're talking about some kind of generic functions, or an alternative *
dispatch method.

Read this GvR blog post [1] and his next one; also see PEP 3124 by Phillip *
J. Eby, who wrote a pretty good implementation of generic functions a long *
time ago.

Your proposal requires a syntax change and three new keywords; all the *
others achieve roughly equivalent results without requiring any change to*
the core language.

Just to play Devil's advocate here, multimethods(**) aren't
equivalent, roughly or otherwise, to what the OP is requesting.
Superficially it looks that way, but the actual use case for this
logic programming is something that ordinary multimethods can't do.

Prolog-style programming is sort of the exact opposite of pure
functional programming. Whereas in pure functional programming there
are no side effects, in Prolog pretty much everything is a side
effect. The way things happen in Prolog is execution of side effects
in the process of searching for pattern matches.

A decent multimethod implementation doesn't use trial and error for
dispatch; it'll use some kind of mapping and cacheing to get to the
appropriate function as quickly as possible. In logic programming
however, the trial-and-error is essential since side-effects can and
are supposed to happen in the process of trying.
Anyway, this proposal can easily be implemented more or less as
proposed without any syntax changes, using the same ideas as the
multimethod implementations, but guaranteeing trial-and-error
dispatching.
Carl Banks

(**) I avoid the term "generic function" since it constrasts starkly
with the use of the word "generic" in generic programming.
Sep 25 '08 #6
On Fri, Sep 26, 2008 at 6:14 AM, <py********@arcor.dewrote:
Typed parameters. Method-Declaration-filtered-typed parameters. That's what
I'm thinking of.
Why do we need this (rubbish) ?
Seriously. The use-case is far too small.
And don't invent use-cases either.

Instead of coming up with ideas of adding more
and more into the language from other languages
of which certain features weren't very good in
the first place, devote your time to improving
the libraries, documentation, etc.

Typed parameters is useless to me. A lot of
developers would agree.

--JamesMills

--
--
-- "Problems are solved by method"
Sep 25 '08 #7
On Sep 25, 2:24*pm, python-...@arcor.de wrote:
Hi,

sorry, I have these ideas for longer than 10 years, please have a look onit
and comment on it. Thx.

----

This is another proposal for introducing types into Python.

There are many reasons for incorporating types into Python, but there is
also a lot of concern about doing so because of destroying the original
character of Python as a smart script language.

This proposal adds several advantages of Prolog(ue) techniques without
changing the natural understanding of Python as a language.

Proposal:

1. Method definitions can be non-unique if a type is prefixed to one or more
of its parameters, or the parameters differ in number.

2. A keyword 'reject' is added.

3. A keyword 'fail' is added.

4. A keyword 'cut' is added.

Definition:

1. A "type" is a String naming the actual class or class family which the
passed instanced is derived from, prefixing the parameter.

2. "'reject'" is a marker inside a function/method and signals that further
processing will not be done inside this method, but instead be passed to the
next available function/method in row, otherwise an implicit "fail" will
occur.

3. "'fail'" is a marker inside a function/method and signals that NO further
processing can be done in neither of this or the following
functions/methods.

4. "'cut'" is a marker inside a function/method that signals that the
failure of called functions/methods inside of it, following this statement,
automatically lead to a failure, instead of trying the next method -
normally, it would be "reject" instead.

5. Failure of functions/methods to outside of this new context are signalled
with a new exception e.g. "MethodRetrialError".

E.g.

def whoisthethief("List" x):
* return iknowit(x)

def whoisthethief("String" x, "String" y):
* return iknowit([x,y])

##########

def numeral_add(a, b):
* if type(a)!=types.IntType:
* * reject
* ...

# equivalent to:

def numeral_add("Integer" a, b):
* ...
Would you settle for a class or classes which had the same
functionality, only you would call its methods with parentheses?

Modified examples:

@argtype( List )
def whoisthethief(x):
return iknowit(x)

@argtype( String, String )
def whoisthethief(x, y):
return iknowit([x,y])

def numeral_add(a, b):
if type(a)!=types.IntType:
reject()
...

/or:

def numeral_add(a, b):
if type(a)!=types.IntType:
flow.reject()
...
Sep 26 '08 #8

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

Similar topics

2
by: Guido van Rossum | last post by:
Robert and Python-dev, I've read the J2 proposal up and down several times, pondered all the issues, and slept on it for a night, and I still don't like it enough to accept it. The only reason...
21
by: Mike Meyer | last post by:
PEP: XXX Title: A rational number module for Python Version: $Revision: 1.4 $ Last-Modified: $Date: 2003/09/22 04:51:50 $ Author: Mike Meyer <mwm@mired.org> Status: Draft Type: Staqndards...
15
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html...
13
by: Ian Hickson | last post by:
A group of us have been unofficially working on a proposal of extensions to HTML4's Forms chapter, and would like to get input from a wider range of people now that we think our draft proposal is...
4
by: wkaras | last post by:
I would like to propose the following changes to the C++ Standard, the goal of which are to provide an improved ability to specify the constraints on type parameters to templates. Let me say from...
0
by: jygoh3 | last post by:
ENCYCLOPEDIA OF MOBILE COMPUTING & COMMERCE CALL FOR SHORT ARTICLES Proposal Deadline: 15 Nov 2005 (Extended)
47
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
10
by: =?iso-8859-2?B?SmFuIFJpbmdvuQ==?= | last post by:
Hello everybody, this is my first post to a newsgroup at all. I would like to get some feedback on one proposal I am thinking about: --- begin of proposal --- Proposal to add...
12
by: Ioannis Vranos | last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... }
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.