Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder1.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'else:': 0.03; 'interpreter': 0.04; 'subject:Python': 0.05; 'compiler': 0.05; 'that?': 0.05; "'a'": 0.07; 'line:': 0.07; 'pypy': 0.07; 'referring': 0.07; 'rewrite': 0.07; 'statically': 0.07; 'type,': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runtime': 0.09; 'subject:Why': 0.09; 'subject:create': 0.09; 'terry': 0.09; 'typed': 0.09; 'def': 0.10; 'language,': 0.11; "'b'": 0.16; 'b):': 0.16; 'better?': 0.16; 'binding,': 0.16; 'compilers': 0.16; 'executed,': 0.16; 'objects?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject: \n ': 0.16; 'variations': 0.16; 'later': 0.16; 'string': 0.17; 'wrote:': 0.17; 'integer': 0.17; 'module,': 0.17; 'string,': 0.17; 'jan': 0.18; 'input': 0.18; 'latter': 0.22; 'needed.': 0.23; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'object,': 0.27; 'strongly': 0.27; 'header:X-Complaints-To:1': 0.28; 'subject:like': 0.29; 'types.': 0.29; 'objects': 0.29; 'that.': 0.30; 'function': 0.30; 'figure': 0.30; 'could': 0.32; 'function.': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'program,': 0.34; 'pm,': 0.35; 'subject:?': 0.35; 'something': 0.35; 'received:org': 0.36; 'skip:{ 10': 0.36; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'different': 0.63; 'ever': 0.63; 'therefore': 0.65; 'believe': 0.69; 'believe,': 0.84; 'dict,': 0.84; 'fly,': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Date: Mon, 04 Mar 2013 19:31:09 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362443484 news.xs4all.nl 6980 [2001:888:2000:d::a6]:33447 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40488 On 3/4/2013 5:55 PM, CM wrote: > Could you help me understand this better? For example, if you > have this line in the Python program: > > foo = 'some text' > bar = {'apple':'fruit'} > > If the interpreter can determine at runtime that foo is a string > and bar is a dict, why can't the compiler figure that out at > compile time? Or is the problem that if later in the program > you have this line: > > foo = 12 > > now foo is referring to an integer object, not a string, and > compilers can't have two names referring to two different > types of objects? I believe you mean one name referring to multiple types. > Something like that? Something like that. In python, objects are strongly typed, names do not have types. Or if you prefer, names are typed according to their current binding, which can freely change. As for why this can be an advantage, consider this simple function. def min2(a, b): if a <= b: return a else: return b When the def statement is executed, the names 'a' and 'b' have no binding and therefore no type, not even a temporary type. In a statically typed language, either you or the compiler must rewrite that function for every pair of types that are ever input to min2. If the compiler does it, it either has to analyze an entire program, or it have to compile variations on the fly, as needed. The latter is what the psycho module, and, I believe, the pypy jit compiler does. -- Terry Jan Reedy