From: Donal K. Fellows on

TIP #365: ADD PYTHON COMPATIBILITY MODE
=========================================
Version: $Revision: 1.1 $
Author: Donal K. Fellows <dkf_at_users.sf.net>
State: Draft
Type: Project
Tcl-Version: 8.6
Vote: Pending
Created: Thursday, 01 April 2010
URL: http://www.tcl.tk/cgi-bin/tct/tip/365.html
Post-History:

-------------------------------------------------------------------------

ABSTRACT
==========

This TIP adds support for reading and evaluating code written in
Python
to the /tclsh/ interpreter.

RATIONALE
===========

There is a lot of Python code out there, all of which suffers from
the
problem that the implementation quality of those interpreters is
distinctly below what any reasonable person would consider
"production". This presents a major opportunity for the well-known
dynamic Tcl community to provide people across the whole world the
power of Tcl (especially through the new *case* command) while
requiring no changes on the users part other than a simple recoding
of
the calling sequence for their code.

PROPOSED CHANGE
=================

A *PythonLanguageCompatibility* package will be provided. Upon being
*package require*d, the remainder of the script will be evaluated in
the Python language. This enables simple programs like this to be
written:

package require Tcl 8.6
interp create worker
$worker eval {
package require PythonLanguageCompatibility
romanDgts= 'ivxlcdmVXLCDM_'
def ToRoman(num):
namoR = ''
if num >=4000000:
print 'Too Big -'
return '-----'
for rdix in range(0, len(romanDgts), 2):
if num==0: break
num,r = divmod(num,10)
v,r = divmod(r, 5)
if r==4:
namoR += romanDgts[rdix+1+v] + romanDgts[rdix]
else:
namoR += r*romanDgts[rdix] + (romanDgts[rdix+1] if(v==1)
else '')
return namoR[-1::-1]
}
interp alias {} ToRoman $worker ToRoman
after 100 {package require PythonLanguageCompatibility}
after 200 {package forget PythonLanguageCompatibility}
for {set i 0} {$i < 10000} {incr i} {
try {
print '%x - %s'%(i,ToRoman(i))
} trap {LANGUAGE WRONG} {} {
puts "$i was not printed as a roman number"
}
}

Clearly this allows the intermixing of both Tcl's and Python's
strengths with minimal effort on users' parts.

COPYRIGHT
===========

This document has been placed in the public domain.

-------------------------------------------------------------------------

TIP AutoGenerator - written by Donal K. Fellows
From: George Petasis on
στις 1/4/2010 4:10 μμ, O/H Donal K. Fellows έγραψε:
>
> TIP #365: ADD PYTHON COMPATIBILITY MODE
> =========================================
> Version: $Revision: 1.1 $
> Author: Donal K. Fellows<dkf_at_users.sf.net>
> State: Draft
> Type: Project
> Tcl-Version: 8.6
> Vote: Pending
> Created: Thursday, 01 April 2010
> URL: http://www.tcl.tk/cgi-bin/tct/tip/365.html
> Post-History:
>
> -------------------------------------------------------------------------
>
> ABSTRACT
> ==========
>
> This TIP adds support for reading and evaluating code written in
> Python
> to the /tclsh/ interpreter.
>
> RATIONALE
> ===========
>
> There is a lot of Python code out there, all of which suffers from
> the
> problem that the implementation quality of those interpreters is
> distinctly below what any reasonable person would consider
> "production". This presents a major opportunity for the well-known
> dynamic Tcl community to provide people across the whole world the
> power of Tcl (especially through the new *case* command) while
> requiring no changes on the users part other than a simple recoding
> of
> the calling sequence for their code.
>
> PROPOSED CHANGE
> =================
>
> A *PythonLanguageCompatibility* package will be provided. Upon being
> *package require*d, the remainder of the script will be evaluated in
> the Python language. This enables simple programs like this to be
> written:
>
> package require Tcl 8.6
> interp create worker
> $worker eval {
> package require PythonLanguageCompatibility
> romanDgts= 'ivxlcdmVXLCDM_'
> def ToRoman(num):
> namoR = ''
> if num>=4000000:
> print 'Too Big -'
> return '-----'
> for rdix in range(0, len(romanDgts), 2):
> if num==0: break
> num,r = divmod(num,10)
> v,r = divmod(r, 5)
> if r==4:
> namoR += romanDgts[rdix+1+v] + romanDgts[rdix]
> else:
> namoR += r*romanDgts[rdix] + (romanDgts[rdix+1] if(v==1)
> else '')
> return namoR[-1::-1]
> }
> interp alias {} ToRoman $worker ToRoman
> after 100 {package require PythonLanguageCompatibility}
> after 200 {package forget PythonLanguageCompatibility}
> for {set i 0} {$i< 10000} {incr i} {
> try {
> print '%x - %s'%(i,ToRoman(i))
> } trap {LANGUAGE WRONG} {} {
> puts "$i was not printed as a roman number"
> }
> }
>
> Clearly this allows the intermixing of both Tcl's and Python's
> strengths with minimal effort on users' parts.
>
> COPYRIGHT
> ===========
>
> This document has been placed in the public domain.
>
> -------------------------------------------------------------------------
>
> TIP AutoGenerator - written by Donal K. Fellows

You puzzled me for a while :D
Such a TIP from Donal??? :D

George
From: Aric Bills on
On Apr 1, 7:10 am, "Donal K. Fellows"
<donal.k.fell...(a)manchester.ac.uk> wrote:
>  TIP #365: ADD PYTHON COMPATIBILITY MODE
> =========================================
>  Version:      $Revision: 1.1 $
>  Author:       Donal K. Fellows <dkf_at_users.sf.net>
>  State:        Draft
>  Type:         Project
>  Tcl-Version:  8.6
>  Vote:         Pending
>  Created:      Thursday, 01 April 2010
>  URL:          http://www.tcl.tk/cgi-bin/tct/tip/365.html
>  Post-History:
>
> -------------------------------------------------------------------------
>
>  ABSTRACT
> ==========
>
>  This TIP adds support for reading and evaluating code written in
> Python
>  to the /tclsh/ interpreter.
>
>  RATIONALE
> ===========
>
>  There is a lot of Python code out there, all of which suffers from
> the
>  problem that the implementation quality of those interpreters is
>  distinctly below what any reasonable person would consider
>  "production". This presents a major opportunity for the well-known
>  dynamic Tcl community to provide people across the whole world the
>  power of Tcl (especially through the new *case* command) while
>  requiring no changes on the users part other than a simple recoding
> of
>  the calling sequence for their code.
>
>  PROPOSED CHANGE
> =================
>
>  A *PythonLanguageCompatibility* package will be provided. Upon being
>  *package require*d, the remainder of the script will be evaluated in
>  the Python language. This enables simple programs like this to be
>  written:
>
>     package require Tcl 8.6
>     interp create worker
>     $worker eval {
>         package require PythonLanguageCompatibility
>         romanDgts= 'ivxlcdmVXLCDM_'
>         def ToRoman(num):
>           namoR = ''
>           if num >=4000000:
>             print 'Too Big -'
>             return '-----'
>           for rdix in range(0, len(romanDgts), 2):
>             if num==0: break
>             num,r = divmod(num,10)
>             v,r = divmod(r, 5)
>             if r==4:
>               namoR += romanDgts[rdix+1+v] + romanDgts[rdix]
>             else:
>               namoR += r*romanDgts[rdix] + (romanDgts[rdix+1] if(v==1)
> else '')
>           return namoR[-1::-1]
>     }
>     interp alias {} ToRoman $worker ToRoman
>     after 100 {package require PythonLanguageCompatibility}
>     after 200 {package forget PythonLanguageCompatibility}
>     for {set i 0} {$i < 10000} {incr i} {
>        try {
>           print '%x - %s'%(i,ToRoman(i))
>        } trap {LANGUAGE WRONG} {} {
>           puts "$i was not printed as a roman number"
>        }
>     }
>
>  Clearly this allows the intermixing of both Tcl's and Python's
>  strengths with minimal effort on users' parts.
>
>  COPYRIGHT
> ===========
>
>  This document has been placed in the public domain.
>
> -------------------------------------------------------------------------
>
>  TIP AutoGenerator - written by Donal K. Fellows

Thanks for the laugh!
From: George Petasis on
στις 1/4/2010 7:38 μμ, O/H Aric Bills έγραψε:
> Thanks for the laugh!

I would have believe it if it had another author. Why not? :D

Perhaps I was influenced by IKVM (http://www.ikvm.net/) I found two days
ago, which loads java bytecode directly in .NET :D

(BTW, tclpython needs to be updated to work with python 3.x. They have
removed some part of the C API the extension used to get the error
message from the python interpreter...)

George
From: Donal K. Fellows on
On 1 Apr, 18:59, George Petasis <petas...(a)yahoo.gr> wrote:
> στις 1/4/2010 7:38 μμ, O/H Aric Bills έγραψε:
> > Thanks for the laugh!
>
> I would have believe it if it had another author. Why not? :D

I was tempted to have Poul D. Uddervun (of Windup University) as a co-
author.

Donal.