473,795 Members | 2,766 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python compilers?

Is anyone working on a python-to-native compiler?
I'd be interested in taking a look.

Come to think of it, is anyone working on a sexpr-enabled version of
Python, or anything similar? I really miss my macros whenever I try to
use it...

Jul 18 '05
58 4033
Svein Ove Aas <sv************ @brage.info> writes:
Mitja wrote:
Thorsten Kampe <th******@thors tenkampe.de>
(news:1m******* ********@thorst enkampe.de) wrote:
* Tor Iver Wilhelmsen (2004-05-18 17:26 +0100)
Grant Edwards <gr****@visi.co m> writes:

> Dude, didn't you take high-school math? 1/3 _is_ 0.33333...

No, because at some point you will stop writing 3's, either out of
boredom, exhaustion or because you need to pee. At that instant, you
introduce a rounding error, making 3 * 1/3 = 0.99999999999.. . instead
of 1.0

Must have been a long time since you went to school... 1/3 is
/exactly/ 0.3...: http://mathworld.wolfram.com/RepeatingDecimal.html


Even worse....
0.9999999999999 99999999... is exactly 1 :)


Only for infinite counts of '9', and computers don't do infinity.


We need to stop randomly mixing exact math with computer
implementations (and approximations) thereof.

"<digit><digit> ..." is the accepted ASCII rendition of the repeating
overbar, and thus explicitly means "on to infinity". 0.99... exactly
equals 1.

If you want to shift the discussion to computer implementations then
that is a different story. We can talk binary representations of
decimal fractions, and the value of rationals as a useful
representation.

But why not also complain that Python does not have a complete
representation of pi. After all, the value of pi is known to well
beyond the IEEE 80-bit or 64-bit or whatever that an implementation
provides. Even if we did mp math and did really long pi
representations , they would of course not be exact. "e" isn't handled
completely either. Why not complain about those?

We don't complain because the available values are "good enough".
IEEE 764 64-bit reals (internally handled as IEEE 764 80-bit) are
good-enough for most numerical needs. I'll admit, the US debt needs
some extended precision :-( but most numerical analysis gets by with
epsilons under 1e-14.

Hey, while we are on the subject of exact representation, what's with
multithreading? My computer has only one CPU. What's going on
here???? It's a lie, a LIE I tell you...

--
ha************@ boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
Jul 18 '05 #31
Paul Rubin <http://ph****@NOSPAM.i nvalid> wrote in message news:<7x******* *****@ruckus.br ouhaha.com>...
Carl Banks <im*****@aerojo ckey.invalid> writes:
I don't follow you. In what way is Python dynamic that Lisp isn't?


class foo: ... def bar(self, x):
... return x*x
... a = foo()
a.bar(3) 9 a.bar = lambda x: x*x*x
a.bar(3) 27

Well, come on, of course there's going to be some things here and
there you can do in one and not the other. In wat is Python dynamic
that Lisp isn't to such an extent that it would cripple any attempts
to compile it?
--
CARL BANKS
Jul 18 '05 #32
On 19 May 2004 14:54:48 -0700,
im*****@aerojoc key.com (Carl Banks) wrote:
Paul Rubin <http://ph****@NOSPAM.i nvalid> wrote in message
news:<7x******* *****@ruckus.br ouhaha.com>...
Carl Banks <im*****@aerojo ckey.invalid> writes:
> I don't follow you. In what way is Python dynamic that Lisp isn't?


>>> class foo:

... def bar(self, x):
... return x*x
...
>>> a = foo()
>>> a.bar(3)

9
>>> a.bar = lambda x: x*x*x
>>> a.bar(3)

27
>>>

Well, come on, of course there's going to be some things here
and there you can do in one and not the other. In wat is Python
dynamic that Lisp isn't to such an extent that it would cripple
any attempts to compile it?


It's not a matter of not being able to compile python; it's a
matter of what sort of benefits you'd gain.

For example:

if x.y.z == a.b.c:
print 'equal'

What is x.y.z? Who knows? The object to which x is bound might
create y on the fly, based on information not available to the
compiler (see __getattr__ and properties). Once the run-time
system asks object x for attribute y, it (the run-time) has to go
through the whole process again to determine z (and, therefore,
x.y.z). Similar for a.b.c, and any of that code might have
redefined what it means for such objects to be equal, which means
that the compiler can't even know what sorts of equality tests
might be available at the time that the code executes, let alone
generate a simple compare instruction.

This is important: There is little, if any, difference between
that code and running everything through the interpreter anyway.

For that matter, simply accessing x.y might change a.b. (FWIW,
though, the ensuing programmer-cide would be entirely justified.)

"Plain" Common Lisp code has (mostly) the same issues, but
performance critical Common Lisp programs contain strategically
placed type declarations (thus reducing the dynamicity of the
language) to help the compiler to know what it's up against.

There are proposals to add type declarations to Python; google is
your friend (see also 'decorators'). Similar for JIT compilers
(psyco falls into this category).

Regards,
Heather

--
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli
Jul 18 '05 #33
im*****@aerojoc key.com (Carl Banks) writes:
>> a.bar = lambda x: x*x*x
>> a.bar(3)

27


Well, come on, of course there's going to be some things here and
there you can do in one and not the other. In wat is Python dynamic
that Lisp isn't to such an extent that it would cripple any attempts
to compile it?


The example above kills any attempt to turn a.bar() into a static
procedure call. There's more like it, e.g. the existence of the
locals() dictionary and the ability to modify it. However, it should
be possible to define a reasonable subset of Python that can compile
into good code. The stuff that makes compilation difficult makes the
code unmaintainable too.

I do think that Python's designers should wait til PyPy with
native-code backends has been deployed for a while before defining too
much of Python 3.0, so we can first gain some experience with compiled
Python. Python should evolve towards being compiled most of the time.
Jul 18 '05 #34
Paul Rubin wrote:


im*****@aerojoc key.com (Carl Banks) writes:
> >>> a.bar = lambda x: x*x*x
> >>> a.bar(3)
> 27
Well, come on, of course there's going to be some things here and
there you can do in one and not the other. In wat is Python dynamic
that Lisp isn't to such an extent that it would cripple any attempts
to compile it?


The example above kills any attempt to turn a.bar() into a static
procedure call.


Of course it does--but it's one method. A compiler, if it's good,
would only make the optization on methods named "bar", and it could
probably pare the number of possible classes it could happen to down
to only a few.

I mean you could have a Turing nightmare on your hands, with all kinds
of crazy setattrs and execs and stuff, in both Python and Lisp, and
then there's not much a compiler could do but emit totally general
code. I assume Lisp compilers do this sometimes.

There's more like it, e.g. the existence of the
locals() dictionary and the ability to modify it.
New feature? I didn't think modifying the dict returned by locals
affected the variables.

However, it should
be possible to define a reasonable subset of Python that can compile
into good code. The stuff that makes compilation difficult makes the
code unmaintainable too.
True, but even if you didn't do that, I think a compiler could do a
decent job with reasonable code.

I do think that Python's designers should wait til PyPy with
native-code backends has been deployed for a while before defining too
much of Python 3.0, so we can first gain some experience with compiled
Python. Python should evolve towards being compiled most of the time.


Agreed
--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon
Jul 18 '05 #35
Carl Banks <im*****@aerojo ckey.invalid> writes:
The example above kills any attempt to turn a.bar() into a static
procedure call.
Of course it does--but it's one method. A compiler, if it's good,
would only make the optization on methods named "bar", and it could
probably pare the number of possible classes it could happen to down
to only a few.


How could it possibly know? The reassignment of a.bar could happen
anytime, anywhere in the code. Maybe even in an eval.
I mean you could have a Turing nightmare on your hands, with all kinds
of crazy setattrs and execs and stuff, in both Python and Lisp, and
then there's not much a compiler could do but emit totally general
code. I assume Lisp compilers do this sometimes.


Lisp compilers might have to do that sometimes, but Python compilers
would have to do it ALL the time. Psyco took one way out, basically
generating code at runtime and caching it for specific operand types,
but the result is considerable code expansion compared to precompilation.
Jul 18 '05 #36
Carl Banks <im*****@aerojo ckey.invalid> wrote in message news:<38******* ********@fe2.co lumbus.rr.com>. ..
There's more like it, e.g. the existence of the
locals() dictionary and the ability to modify it.


New feature? I didn't think modifying the dict returned by locals
affected the variables.


Evidence of crime :)

Python 2.3.2
x Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'x' is not defined locals()['x'] = 1
x

1
Not to mention stack frame magic available via inspect.*...
- kv
Jul 18 '05 #37
kv***********@y ahoo.com (Konstantin Veretennicov) wrote in
news:51******** *************** ***@posting.goo gle.com:
Carl Banks <im*****@aerojo ckey.invalid> wrote in message
news:<38******* ********@fe2.co lumbus.rr.com>. ..
> There's more like it, e.g. the existence of the
> locals() dictionary and the ability to modify it.


New feature? I didn't think modifying the dict returned by locals
affected the variables.


Evidence of crime :)

Python 2.3.2
x Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'x' is not defined locals()['x'] = 1
x 1


That works because you are using locals() to access your global variables.
Put the same code in a function and it behaves differently:
def test(): .... x = 0
.... locals()['x'] = 1
.... print x
.... test()

0

You cannot depend on the behaviour of modifying locals() remaining
unchanged over different releases of Python. Bottom line: don't do this.
Jul 18 '05 #38
kv***********@y ahoo.com (Konstantin Veretennicov) writes:
Carl Banks <im*****@aerojo ckey.invalid> wrote in message news:<38******* ********@fe2.co lumbus.rr.com>. ..
There's more like it, e.g. the existence of the
locals() dictionary and the ability to modify it.
New feature? I didn't think modifying the dict returned by locals
affected the variables.


Evidence of crime :)

Python 2.3.2
x Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'x' is not defined locals()['x'] = 1
x

1
Not to mention stack frame magic available via inspect.*...


Well, fortunately *this* level of gimmickery is already somewhat
forbidden...

Cheers,
mwh

-- so python will fork if activestate starts polluting it?

I find it more relevant to speculate on whether Python would fork
if the merpeople start invading our cities riding on the backs of
giant king crabs. -- Brian Quinlan, comp.lang.pytho n
Jul 18 '05 #39
>>>>> "Paul" == Paul Rubin <http://ph****@NOSPAM.i nvalid> writes:

Paul> I do think that Python's designers should wait til PyPy with
Paul> native-code backends has been deployed for a while before
Paul> defining too much of Python 3.0, so we can first gain some
Paul> experience with compiled Python. Python should evolve
Paul> towards being compiled most of the time.

I think we might be able to get significant benefits from the .NET
implementation (provided that Mono would prove to be legally feasible
in the future) - a lot of the JIT work is done by "other people", and
being able to seamlessly combine Python with a statically typed
language (which probably produces faster code) would be able to give
Python a sweet role in many programming projects - the role of the
initial implementation/specification language, with grunts doing the
possible mechanical porting of performance critical areas.

We could have such a role already, but only in theory. C/C++
integration is not seamless enough, and the languages themselves are
considered to be too difficult, clumsy and unproductive to attract
companies.

One thing is pretty certain to benefit any future speedup efforts,
whatever road is chosen, namely optional type declarations. Their
implementation could be left unspecified, and the initial Python
implementation could use them only for runtime type checking in
debugmode (or ignore altogether). Type inferencing could also use them
to smooth up things.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #40

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

Similar topics

12
3149
by: rhmd | last post by:
Just found Python and I love it. What an elegant language! I would like to use it for various applications, but the mathematical calculations are way too slow (a million sines 8 seconds in Python vs. 2 seconds in Excel VBA), so was thinking of learning enough C++ to do the number crunching in C++ and integrating the C++ routines with Python. My question: My question: Which compiler works best with Python? I use Windows XP and 98. Have...
699
34260
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
18
2826
by: K_Lee | last post by:
I documented the regex internal implementation code for both Tcl and Python. As much as I like Tcl, I like Python's code much more. Tcl's Stub interface to the external commands is confusing to outsider. I still don't get why the stub interface is needed. One aspect I don't understanding about python is that the Python language itself is object oriented and all the internal is implement as C object. Why not C++ object?
30
3488
by: Christian Seberino | last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python? Python's design is godly. I'm wondering if Ruby's is godly too. I've heard it has solid OOP design but then I've also heard there are lots of weird ways to do some things kinda like Perl which is bad for me. Any other ideas?
176
8191
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? Thank you, -- greetz tom
47
3679
by: Michael Scarlett | last post by:
There is an amazing article by paul graham about python, and an even better discussion about it on slashdot. The reason I point this out, is the more I read both articles, the more I realised how we would be mutilating the language with that god forsaken @ decorator. I don't know about the rest of you, but I learned python and fell in love with its syntax and simplicity. Python - just works. So please GVR. Don't complicate it. Leave it as...
14
4531
by: BOOGIEMAN | last post by:
Well that's it, how do I make Windows Application with Python ??? Is there simple way that works 100% ? How can I rework visual design done in VS 2003 to use it for my python program ?
20
2163
by: xeys_00 | last post by:
I posted a article earlier pertaining programming for my boss. Now I am gonna ask a question about programming for myself. I just finished my first C++ Class. Next semester is a class on encryption(and it's probably gonna be a math class too). And finally back in programming in the fall with C++ and Java 1. The C++ will cover pointers, and linked lists, sorting algorithms, etc... I run linux and OS X. I have read in the old days that C was...
25
3808
by: jwrweatherley | last post by:
I'm pretty new to python, but am very happy with it. As well as using it at work I've been using it to solve various puzzles on the Project Euler site - http://projecteuler.net. So far it has not let me down, but it has proved surprisingly slow on one puzzle. The puzzle is: p is the perimeter of a right angle triangle with integral length sides, {a,b,c}. which value of p < 1000, is the number of solutions {a,b,c} maximised? Here's my...
0
9672
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
10436
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
10163
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,...
1
7538
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
6780
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.