Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56520

Re: Tail recursion to while iteration in 2 easy steps

Date 2013-10-09 15:45 -0700
From Charles Hixson <charleshixsn@earthlink.net>
Subject Re: Tail recursion to while iteration in 2 easy steps
References (10 earlier) <525348d7$0$29984$c3e8da3$5496439d@news.astraweb.com> <mailman.823.1381192919.18130.python-list@python.org> <52536f96$0$29984$c3e8da3$5496439d@news.astraweb.com> <mailman.824.1381202841.18130.python-list@python.org> <5253cee4$0$29976$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.911.1381358766.18130.python-list@python.org> (permalink)

Show all headers | View raw


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 <INSERT **ANY** HIGH-LEVEL
> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-01 17:30 -0400
  Re: Tail recursion to while iteration in 2 easy steps rusi <rustompmody@gmail.com> - 2013-10-01 22:16 -0700
    Re: Tail recursion to while iteration in 2 easy steps Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-02 10:23 +0200
      Re: Tail recursion to while iteration in 2 easy steps rusi <rustompmody@gmail.com> - 2013-10-02 06:29 -0700
    Re: Tail recursion to while iteration in 2 easy steps Ravi Sahni <ganeshsahni07@gmail.com> - 2013-10-03 22:57 +0530
      Re: Tail recursion to while iteration in 2 easy steps rusi <rustompmody@gmail.com> - 2013-10-04 03:52 -0700
  Re: Tail recursion to while iteration in 2 easy steps Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-02 10:17 +0200
    Re: Tail recursion to while iteration in 2 easy steps Mark Janssen <dreamingforward@gmail.com> - 2013-10-02 11:59 -0700
    Re: Tail recursion to while iteration in 2 easy steps Mark Janssen <dreamingforward@gmail.com> - 2013-10-02 14:05 -0700
      Re: Tail recursion to while iteration in 2 easy steps Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-04 11:49 +0200
        Re: Tail recursion to while iteration in 2 easy steps Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-04 10:51 +0000
        Re: Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-04 18:32 -0400
          Re: Tail recursion to while iteration in 2 easy steps Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-07 19:15 +0200
            Re: Tail recursion to while iteration in 2 easy steps Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-07 19:57 +0200
              Re: Tail recursion to while iteration in 2 easy steps Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-08 10:56 +0200
                Re: Tail recursion to while iteration in 2 easy steps Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-08 12:49 +0300
            Re: Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-07 16:42 -0400
            Re: Tail recursion to while iteration in 2 easy steps random832@fastmail.us - 2013-10-07 17:19 -0400
              Re: Tail recursion to while iteration in 2 easy steps Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-10-08 10:41 +0200
            Re: Tail recursion to while iteration in 2 easy steps MRAB <python@mrabarnett.plus.com> - 2013-10-07 22:39 +0100
            Re: Tail recursion to while iteration in 2 easy steps Piet van Oostrum <piet@vanoostrum.org> - 2013-10-07 18:03 -0400
            Re: Tail recursion to while iteration in 2 easy steps Mark Janssen <dreamingforward@gmail.com> - 2013-10-07 15:47 -0700
              Re: Tail recursion to while iteration in 2 easy steps Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-07 23:50 +0000
                Re: Tail recursion to while iteration in 2 easy steps Mark Janssen <dreamingforward@gmail.com> - 2013-10-07 17:24 -0700
                Formal-ity and the Church-Turing thesis rusi <rustompmody@gmail.com> - 2013-10-07 20:17 -0700
                Re: Formal-ity and the Church-Turing thesis Ravi Sahni <ganeshsahni07@gmail.com> - 2013-10-08 10:46 +0530
                Re: Formal-ity and the Church-Turing thesis rusi <rustompmody@gmail.com> - 2013-10-07 22:44 -0700
                Re: Formal-ity and the Church-Turing thesis Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-08 07:43 +0100
                Re: Formal-ity and the Church-Turing thesis Ravi Sahni <ganeshsahni07@gmail.com> - 2013-10-08 18:31 +0530
                Re: Formal-ity and the Church-Turing thesis rusi <rustompmody@gmail.com> - 2013-10-08 06:33 -0700
                Re: Formal-ity and the Church-Turing thesis Steven D'Aprano <steve@pearwood.info> - 2013-10-08 07:50 +0000
                Re: Formal-ity and the Church-Turing thesis Ravi Sahni <ganeshsahni07@gmail.com> - 2013-10-08 18:16 +0530
                Re: Formal-ity and the Church-Turing thesis Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-08 13:11 +0000
                Re: Formal-ity and the Church-Turing thesis Robert Day <robertkday@gmail.com> - 2013-10-08 14:25 +0100
                Re: Formal-ity and the Church-Turing thesis Chris Angelico <rosuav@gmail.com> - 2013-10-09 08:36 +1100
                Re: Formal-ity and the Church-Turing thesis Mark Janssen <dreamingforward@gmail.com> - 2013-10-07 22:19 -0700
                Re: Formal-ity and the Church-Turing thesis rusi <rustompmody@gmail.com> - 2013-10-07 23:01 -0700
                Re: Formal-ity and the Church-Turing thesis Mark Janssen <dreamingforward@gmail.com> - 2013-10-08 10:39 -0700
                Re: Tail recursion to while iteration in 2 easy steps Mark Janssen <dreamingforward@gmail.com> - 2013-10-07 17:16 -0700
                Re: Tail recursion to while iteration in 2 easy steps Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-08 02:36 +0000
                Re: Tail recursion to while iteration in 2 easy steps Mark Janssen <dreamingforward@gmail.com> - 2013-10-07 20:27 -0700
                Re: Tail recursion to while iteration in 2 easy steps Steven D'Aprano <steve@pearwood.info> - 2013-10-08 09:22 +0000
                Re: Tail recursion to while iteration in 2 easy steps Charles Hixson <charleshixsn@earthlink.net> - 2013-10-09 15:45 -0700
                Re: Tail recursion to while iteration in 2 easy steps Piet van Oostrum <piet@vanoostrum.org> - 2013-10-07 22:46 -0400
                Re: Tail recursion to while iteration in 2 easy steps Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-08 10:25 +0300
                Re: Tail recursion to while iteration in 2 easy steps Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-08 11:18 +0200
              Re: Tail recursion to while iteration in 2 easy steps Piet van Oostrum <piet@vanoostrum.org> - 2013-10-07 22:45 -0400
                Re: Tail recursion to while iteration in 2 easy steps Mark Janssen <dreamingforward@gmail.com> - 2013-10-07 20:34 -0700
    Re: Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-02 18:17 -0400
      Re: Tail recursion to while iteration in 2 easy steps Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-03 01:24 +0000
        Re: Tail recursion to while iteration in 2 easy steps Dave Angel <davea@davea.name> - 2013-10-03 01:39 +0000
        Re: Tail recursion to while iteration in 2 easy steps MRAB <python@mrabarnett.plus.com> - 2013-10-03 02:46 +0100
          Re: Tail recursion to while iteration in 2 easy steps Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-03 02:34 +0000
            Re: Tail recursion to while iteration in 2 easy steps Chris Angelico <rosuav@gmail.com> - 2013-10-03 14:14 +1000
            Re: Tail recursion to while iteration in 2 easy steps random832@fastmail.us - 2013-10-03 10:16 -0400
            Re: Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-03 15:04 -0400
        Re: Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-02 22:41 -0400
          Re: Tail recursion to while iteration in 2 easy steps Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-04 01:30 +0000
        Re: Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-02 23:06 -0400
        Re: Tail recursion to while iteration in 2 easy steps random832@fastmail.us - 2013-10-03 10:14 -0400
        Literal syntax for frozenset, frozendict (was: Tail recursion to while iteration in 2 easy steps) Ben Finney <ben+python@benfinney.id.au> - 2013-10-04 10:18 +1000
        Re: Literal syntax for frozenset, frozendict Ethan Furman <ethan@stoneleaf.us> - 2013-10-03 18:31 -0700
    Re: Tail recursion to while iteration in 2 easy steps Duncan Booth <duncan.booth@invalid.invalid> - 2013-10-03 14:52 +0000
      Re: Tail recursion to while iteration in 2 easy steps Neil Cerutti <neilc@norwich.edu> - 2013-10-03 16:03 +0000
        Re: Tail recursion to while iteration in 2 easy steps Duncan Booth <duncan.booth@invalid.invalid> - 2013-10-04 10:16 +0000
          Re: Tail recursion to while iteration in 2 easy steps Ian Kelly <ian.g.kelly@gmail.com> - 2013-10-04 04:41 -0600
          Re: Tail recursion to while iteration in 2 easy steps Ian Kelly <ian.g.kelly@gmail.com> - 2013-10-04 04:46 -0600
            Re: Tail recursion to while iteration in 2 easy steps Duncan Booth <duncan.booth@invalid.invalid> - 2013-10-04 11:16 +0000
          Re: Tail recursion to while iteration in 2 easy steps Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-04 14:11 +0300
          Re: Tail recursion to while iteration in 2 easy steps Terry Reedy <tjreedy@udel.edu> - 2013-10-04 17:14 -0400
          Re: Tail recursion to while iteration in 2 easy steps Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-05 09:39 +0200
          Re: Tail recursion to while iteration in 2 easy steps random832@fastmail.us - 2013-10-07 17:27 -0400
            Re: Tail recursion to while iteration in 2 easy steps Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-08 10:11 +0300
          Re: Tail recursion to while iteration in 2 easy steps Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-08 11:43 +0200

csiph-web