\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#365: Add Python Compatibility Mode}
\date{April 01, 2010}
\author{Donal K. Fellows}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#365}&\textbf{Add Python Compatibility Mode}\\\hline
Author&

Donal K. Fellows \tipmail{dkf}{users.sf.net}
\\
Created&Thursday, \(\text{1}^{\text{st}}\) April 2010\\
Type&Project\\
Tcl Version&\(8.6\)\\
State&Draft\\
Vote&No voting\\
Version&\tipversion$Revision: 1.2 $\\
Keywords&Look at the date\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP adds support for reading and evaluating code written in Python to the \textit{tclsh} interpreter.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{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 \textbf{case} command) while requiring no changes on the users part other than a simple recoding of the calling sequence for their code.

\section{Proposed Change}

A \textbf{PythonLanguageCompatibility} package will be provided. Upon being \textbf{package require}d, the remainder of the script will be evaluated in the Python language. This enables simple programs like this to be written:
\begingroup\small\begin{verbatim}
 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"
    }
 }
\end{verbatim}
\endgroup

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

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
