Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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; 'example:': 0.03; 'algorithm': 0.04; 'source,': 0.04; 'output': 0.05; '(except': 0.07; 'compiler': 0.07; 'encouraging': 0.07; 'remaining': 0.07; 'x86': 0.07; '"source': 0.09; 'atom': 0.09; 'definition,': 0.09; 'difference,': 0.09; 'high-level': 0.09; 'measure': 0.09; 'oh,': 0.09; 'repeated': 0.09; 'stating': 0.09; 'subject:while': 0.09; 'used.': 0.09; 'python': 0.11; 'language,': 0.12; 'translation': 0.12; 'wrote': 0.14; 'language.': 0.14; 'buggy': 0.16; 'charles': 0.16; 'command,': 0.16; 'compiler.': 0.16; 'construct.': 0.16; 'constructs': 0.16; 'degree.': 0.16; 'emit': 0.16; 'exists,': 0.16; 'experiments': 0.16; 'hardware.': 0.16; 'janssen': 0.16; 'key)': 0.16; 'lexical': 0.16; 'lisp': 0.16; 'measurement': 0.16; 'merely': 0.16; 'message- id:@earthlink.net': 0.16; 'motorola': 0.16; 'operation:': 0.16; 'otherwise:': 0.16; 'processor,': 0.16; 'reasonably': 0.16; 'received:dsl.mindspring.com': 0.16; 'reversed': 0.16; 'specifying': 0.16; 'subject:recursion': 0.16; 'such,': 0.16; 'targeting': 0.16; 'valid.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'discussion': 0.18; 'obviously': 0.18; 'written': 0.21; 'seems': 0.21; 'machine': 0.22; '>>>': 0.22; 'programming': 0.22; 'putting': 0.22; 'saying': 0.22; 'header :User-Agent:1': 0.23; 'either.': 0.24; 'integer': 0.24; 'rid': 0.24; 'specify': 0.24; 'techniques,': 0.24; 'mon,': 0.24; 'sort': 0.25; 'source': 0.25; 'changes,': 0.26; 'define': 0.26; 'equivalent': 0.26; 'long,': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'generally': 0.29; 'operations,': 0.30; "i'm": 0.30; '(which': 0.31; 'included': 0.31; 'code': 0.31; 'software,': 0.31; '(usually': 0.31; '-0700,': 0.31; '>>>>': 0.31; 'analytical': 0.31; 'assert': 0.31; "d'aprano": 0.31; 'description,': 0.31; 'directly,': 0.31; 'layer': 0.31; 'steven': 0.31; 'probably': 0.32; 'languages': 0.32; 'supposed': 0.32; 'run': 0.32; 'implemented': 0.33; 'device': 0.34; 'could': 0.34; 'problem': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'really': 0.36; 'believed': 0.36; 'machine.': 0.36; 'reality': 0.36; 'science.': 0.36; 'more': 0.64; 'different': 0.65; 'afraid': 0.65; 'talking': 0.65; 'virus': 0.65; 'here': 0.66; 'between': 0.67; 'person,': 0.68; 'physics': 0.68; 'physical': 0.72; 'russian': 0.74; 'forth': 0.81; 'compiling': 0.84; 'cosmic': 0.84; 'fact.': 0.84; 'guaranteed.': 0.84; 'mistaken': 0.84; 'one*': 0.84; 'single,': 0.84; 'standing': 0.84; 'take,': 0.84; 'underneath': 0.84; 'defeat': 0.91; 'good,': 0.91; 'light,': 0.91; 'notion': 0.91; 'procedural': 0.91; 'same,': 0.91; 'besides,': 0.93; 'many,': 0.93; 'technique': 0.93; '2013': 0.98 Date: Wed, 09 Oct 2013 15:45:05 -0700 From: Charles Hixson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130922 Icedove/17.0.9 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Tail recursion to while iteration in 2 easy steps References: <87had0axxy.fsf@dpt-info.u-strasbg.fr> <524C80B6.3010204@unistra.fr> <87li292wnt.fsf@dpt-info.u-strasbg.fr> <878uy52ea0.fsf@dpt-info.u-strasbg.fr> <5252F610.9040403@rece.vub.ac.be> <525348d7$0$29984$c3e8da3$5496439d@news.astraweb.com> <52536f96$0$29984$c3e8da3$5496439d@news.astraweb.com> <5253cee4$0$29976$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <5253cee4$0$29976$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 129 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381358766 news.xs4all.nl 15872 [2001:888:2000:d::a6]:58202 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56520 On 10/08/2013 02:22 AM, Steven D'Aprano wrote: > On Mon, 07 Oct 2013 20:27:13 -0700, Mark Janssen wrote: > >>>>> But even putting that aside, even if somebody wrote such a >>>>> description, it would be reductionism gone mad. What possible light >>>>> on the problem would be shined by a long, long list of machine code >>>>> operations, even if written using assembly mnemonics? >>>> Only that you've got a consistent, stable (and therefore, >>>> formalizable) translation from your language to the machine. >>> You are mistaken to think that there is a single, one-to-one, mapping >>> between high-level code and machine code. >> It's not mistaken. > I'm afraid it is. Reality trumps your theory. gcc, clang, Microsoft > Visual Studio, and all the many, many other C compilers do not generate > identical machine code even when targeting the same hardware. This is a > fact. It's not even the case that there is One True Way to implement a > particular program on a given hardware device and compilers merely are > buggy for doing something else. There are often different ways to > implement it which are equally good, the only difference being personal > preference. > > >> Given a stable and formalized language definition, >> there should only be continued optimization of the lexical and >> procedural constructs into better machine code. > Better than what? "Continued" optimization? When you say "lexical and > procedural constructs", do you mean "source code"? > > >> In the case of an >> "interpreted" language like Python (which I'll define as a language >> which includes a layer of indirection between the user and the machine, > Irrelevant. In the case of Python, there is a machine. The fact that it > is a VM rather than a physical machine is irrelevant. A machine is a > machine -- we could be talking about a Lisp Machine, a Forth Machine, a > x86 processor, an Motorola 68000, an Atom processor, one of those old > Russian mainframes that used three-state trits instead of two-state bits, > or even Babbage's Analytical Engine. > > Besides, most modern CPUs don't execute machine code directly, they run > the machine code in a virtual machine implemented in hardware. So the > difference between Python and x86 machine code is just a matter of degree. > > > >> encouraging the nice benefits of interactivity), such optimization isn't >> really apropos, because it's not the purpose of python to be optimal to >> the machine as much as "optimal to the programmer". In any case, while >> such optimization can continue over time, they generally create new >> compiler releases to indicate such changes. The one-to-one mapping is >> held by the compiler. >> >> Such determinism *defines* the machine, otherwise you might as well get >> rid of the notion of computer *science*. All else is error, akin to >> cosmic rays or magic. Unless the source code changes, all else >> remaining equal, the machine code is supposed to be the same, no matter >> how many times it is compiled. > That is akin to saying that there is *only one* way to measure the speed > of light (say), standing in exactly the same place, using exactly the > same equipment, using precisely the same measurement techniques, and that > if we allow alternative methods for measuring the speed of light, physics > is no longer a science. > > >>> [Only if you use the exact source, compiler, switches, etc]] will the >>> output be the same. >>> And even that is not guaranteed. >> Oh, and what would cause such non-determinism? > The compiler-writer, of course. A compiler is software, and is written by > a person, who can program it to do anything the writer wants. If the > writer wants the compiler to be non-deterministic, it can be. > > Some viruses use a similar technique to try to avoid virus scanners. They > encrypt the payload, which is functionally equivalent to randomizing it > (except it can be reversed if you have the key) so as to defeat virus > scanners. > > A more whimsical example: perhaps a mischievous compiler writer included > something like this in her compiler: > > > when compiling integer multiplication, INT * INT: > if today is Tuesday: > emit machine code that does multiplication using repeated addition > otherwise: > emit machine code that does multiplication using ADD and SHIFT > > > Both implementations of multiplication are perfectly valid. There may be > a performance difference, or there may not be. Since no sensible > programming language is going to specify the *detailed* machine code > implementation of its high-level operations, such a mischievous compiler > would still be valid. > > >>> Take, for example, the single high-level operation: >>> >>> sort(alist) >>> >>> What machine code will be executed? Obviously that will depend on the >>> sort algorithm used. There are *dozens*. Here are just a few: >> Well, since you didn't specify your programming language, you're then >> merely stating an English construct. > What difference does it make? But if it will make you feel better, I'm > specifying Hypertalk. You've probably never heard of it, but regardless, > it exists, and it has a sort command, and the high-level language does > not specify which of many sort algorithms is to be used. > > > >> As such, there can be no single >> mapping from English into the machine, which is why there are so many >> different languages and experiments that map your [English] concepts >> into source code. > And there is no single mapping from PROGRAMMING LANGUAGE HERE> source code to machine code either. I would assert that Python is not inherently a virtual machine language. Originally, IIRC, it was believed that LISP couldn't be compiled. Also, you could implement that virtual machine as a hardware machine. (Also, of course, on modern hardware assembly language is run on a virtual machine, implemented by an underneath microcode layer.) You can reasonably say that an implementation of Python is done in terms of a virtual machine. (Usually I don't bother about this kind of nit-pick, but in this discussion it seems apropos.) -- Charles Hixson