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


Groups > comp.lang.python > #45202

Re: Python for philosophers

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'pop': 0.05; 'subject:Python': 0.06; 'binary': 0.07; 'level,': 0.07; 'tool,': 0.07; 'abstraction': 0.09; 'expression:': 0.09; 'global,': 0.09; 'stack,': 0.09; 'stack.': 0.09; 'statements': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; 'windows': 0.15; '(written': 0.16; 'evaluates': 0.16; 'foo():': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'grasp': 0.16; 'interpreter,': 0.16; 'means.': 0.16; 'operands': 0.16; 'operands,': 0.16; 'parentheses': 0.16; 'subtraction': 0.16; 'through,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'app': 0.19; 'trying': 0.19; "python's": 0.19; 'result.': 0.19; 'help.': 0.21; 'command': 0.22; '>>>': 0.22; 'code,': 0.22; 'load': 0.23; 'integer': 0.24; 'interpret': 0.24; 'replace': 0.24; 'simpler': 0.24; 'mon,': 0.24; 'question': 0.24; 'push': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'leave': 0.29; 'on,': 0.29; 'am,': 0.29; '(like': 0.30; 'operations,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'lines': 0.31; '13,': 0.31; 'decimal': 0.31; 'division': 0.31; 'quite': 0.32; 'ago': 0.33; 'sources': 0.33; 'maybe': 0.34; 'knowledge': 0.35; "can't": 0.35; 'except': 0.35; 'something': 0.35; '(2)': 0.35; 'no,': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'really': 0.36; 'fun,': 0.36; 'functions.': 0.36; 'module.': 0.36; 'view,': 0.36; 'useful': 0.36; 'thanks': 0.36; 'example,': 0.37; 'so,': 0.37; 'too': 0.37; 'two': 0.37; 'awesome': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'explain': 0.39; 'does': 0.39; '12,': 0.39; 'aside': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'expression': 0.60; 'march': 0.61; 'simple': 0.61; "you're": 0.61; 'offer': 0.62; 'myself': 0.63; 'pick': 0.64; 'more': 0.64; 'within': 0.65; 'here': 0.66; 'design.': 0.68; 'compiling': 0.84; 'different.': 0.84; 'evaluation.': 0.84; "it'd": 0.84; 'picture,': 0.84; 'technique': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=CtpyRkufp5SaZe3/ktE0LCDzlsMmTtqgxsIXpUU+0KY=; b=zj6FnYZzhxVcQENTNzG5wmDwEeMgK9mQz+YVfzAiSiKSrAgIpaz6xNUOQfSDSyruAm ISRdTCCskScQbhpyq1DoIXeBuC3Xdb60RNyXgCwDtb8FBwlQTNFgGKhrGkYGse8Qh+1M EgwZAEE5Sbtpq9z5ddvJz4vjoVKA1KI7JtXij4WzMa1I/XUqauM6uioP5VijeoDZp4ul j4ZlYTfhk2n0KWu+rONgTxyCPHj1tnDYIW2sx4lVKn4k/MadsatGpZM7pbYpvuzunOK3 0NMqy9pz7xHjv8RcbZwT3OKmKPrUfU4XX8+MwuRvDDiak3Q562shhWCed7H0ygTpnOxY 6gbg==
MIME-Version 1.0
X-Received by 10.52.179.129 with SMTP id dg1mr4094634vdc.111.1368395308654; Sun, 12 May 2013 14:48:28 -0700 (PDT)
In-Reply-To <6e40860b-c0e5-46f9-9ba9-4ea4f4dc77c2@googlegroups.com>
References <CAMbF=C_GF_AKO2dD_=bH6VN2GVcSbC=KtHFLw62CKq2yitcfyQ@mail.gmail.com> <CAMbF=C8qE1q_m5xKSFMt=gincCnOEZuext1Z2rch5AQQazC4yA@mail.gmail.com> <mailman.1582.1368370291.3114.python-list@python.org> <6e40860b-c0e5-46f9-9ba9-4ea4f4dc77c2@googlegroups.com>
Date Mon, 13 May 2013 07:48:28 +1000
Subject Re: Python for philosophers
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1597.1368395317.3114.python-list@python.org> (permalink)
Lines 130
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368395317 news.xs4all.nl 15972 [2001:888:2000:d::a6]:48654
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45202

Show key headers only | View raw


On Mon, May 13, 2013 at 4:13 AM, llanitedave <llanitedave@veawb.coop> wrote:
> On Sunday, May 12, 2013 7:51:28 AM UTC-7, Chris Angelico wrote:
>> On Mon, May 13, 2013 at 12:17 AM, Citizen Kant <citizenkant@gmail.com> wrote:
>>
>> > Maybe It'd be good if I explain myself a bit more. What I'm trying here is
>>
>> > to grasp Python from the game's abstraction point of view, as if it were,
>>
>> > for example, chess.
>>
>>
>>
>> Maybe you're going for something a little too complicated. Let's boil
>>
>> the question down to a much MUCH simpler subset: expression
>>
>> evaluation. And let's take Python itself right out of the picture, and
>>
>> work with only the following elements:
>>
>>
>>
>> * Parentheses ( )
>>
>> * Multiplication and division * /
>>
>> * Addition and subtraction + -
>>
>> * Decimal integer constants 0123456789
>>
>>
>>
>> This will give the basics of algebraic evaluation. It's quite fun to
>>
>> build a simple little expression evaluator that just does these few
>>
>> operations, and it's surprisingly useful (embed it within a command
>>
>> interpreter, for instance). Some time ago I wrote one into a Windows
>>
>> app (written in C++), and when I pulled it out just now and made it a
>>
>> stand-alone tool, the whole thing was only ~60 lines of code. Nice and
>>
>> easy to work with.
>>
>>
>>
>> So, let's take an expression and see what it really means.
>>
>>
>>
>> 2*(3+4)+6
>>
>>
>>
>> One way to interpret this is with a stack. Here's how Python evaluates
>>
>> that expression:
>>
>>
>>
>> >>> def foo():
>>
>>       return 2*(three+4)+6
>>
>>
>>
>> >>> dis.dis(foo)
>>
>>   2           0 LOAD_CONST               1 (2)
>>
>>               3 LOAD_GLOBAL              0 (three)
>>
>>               6 LOAD_CONST               2 (4)
>>
>>               9 BINARY_ADD
>>
>>              10 BINARY_MULTIPLY
>>
>>              11 LOAD_CONST               3 (6)
>>
>>              14 BINARY_ADD
>>
>>              15 RETURN_VALUE
>>
>>
>>
>> (I had to replace one of the constants with a global, to foil the optimizer)
>>
>>
>>
>> The LOAD statements add to an internal stack, the BINARY operations
>>
>> pop two operands and push the result. This is more-or-less the same
>>
>> technique as I used in my evaluator, except that instead of compiling
>>
>> it to code, I just march straight through, left to right, and so I had
>>
>> to maintain two stacks (one of operands, one of operators).
>>
>>
>>
>> Is this what you had in mind when you wanted to grasp Python's
>>
>> internals? Because it's pretty easy to explore, thanks to the dis
>>
>> module. There's a huge amount that can be learned about the
>>
>> interpreter, its optimizers, and so on, just by disassembling
>>
>> functions. Alternatively, if you're thinking on a more abstract level,
>>
>> leave Python aside altogether and pick up a book on language design.
>>
>> Also can be awesome fun, but completely different.
>>
>>
>>
>> ChrisA
>
> No, that won't help.  You're trying to give him knowledge; he wants understanding.

I can't give him understanding. Best I can do is offer facts, which
lead to knowledge, which lead to understanding if absorbed
appropriately. Also, sources of knowledge (like dis.dis) can be VERY
powerful tools in gaining understanding.

ChrisA

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


Thread

Re: Python for philosophers Chris Angelico <rosuav@gmail.com> - 2013-05-13 00:51 +1000
  Re: Python for philosophers llanitedave <llanitedave@veawb.coop> - 2013-05-12 11:13 -0700
    Re: Python for philosophers Chris Angelico <rosuav@gmail.com> - 2013-05-13 07:48 +1000

csiph-web