I wonder whether a more restricted form of Python would not be acceptable in situations where speed is critical. I mean, instead of cl-python, that tries to mimic the semantic of Python closely, the Lisp community could write a compiler for the subset of Python that the majority of people really use. This subset of Python would share the semantic of Lisp.
I believe that the strategy of specialised operators adopted in Scheme and Racket could be useful for Python too. I mean, operators like fx+, fl+, fl*, etc could help the compiler infer the type of the operands. I am not thinking about Python at large, but that brand of Python that Lisp programmers like so much to implement: cl-python, bigpy, lambda-py, etc. A Lisp to Python translator could be very useful for Lisp programers that need to port a small Python library to Lisp. Of course, translation to Lisp is meaningless if the result proves to be as slow as Python. 2014-05-14 10:40 GMT-03:00 Konrad Hinsen <[email protected]>: > Eduardo Costa writes: > > > Is there anything in the semantic of Python that makes it much more > difficult to > > implement a Python compiler than a Racket compiler? > > Python is much more dynamic than Racket. As an illustration, look at a > simple > operation: addition. In Racket, > > (+ a b) > > requires dispatching on the types of a and, from a finite (and small) > list of admitted candidates (fixnum, flonum, ...). Anything else is an > error. > > In Python, > > a + b > > is just syntactic sugar for > > a.__add__(b) > > which means (1) Look up the type of a, (2) look up '__add__' in the > method dictionary of that type and its supertypes, (3) if not found, > look up '__radd__' in the method dictionary of the type of b, (4) call > the resulting method. None of the intermediate lookups can be cached > because everything might be different the next time that operation is > executed: a and b can have different types, and the definition of > __add__ for the types of a and b can have changed. > > Konrad. > ____________________ > Racket Users list: > http://lists.racket-lang.org/users >
____________________ Racket Users list: http://lists.racket-lang.org/users

