Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.freenet.ag!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'debugging': 0.05; 'class,': 0.07; 'python': 0.09; '###': 0.09; 'def': 0.10; '(read': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'have:': 0.17; 'instance': 0.17; 'instance,': 0.17; 'test.': 0.17; 'variables': 0.17; '(in': 0.18; 'jan': 0.18; 'email addr:gmail.com>': 0.20; 'question.': 0.20; 'to:name:python-list@python.org': 0.20; 'written': 0.20; "i'd": 0.22; 'example': 0.23; '>': 0.23; '15,': 0.23; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'am,': 0.27; '(3)': 0.27; 'c++': 0.27; 'to?': 0.27; 'message- id:@mail.gmail.com': 0.27; 'lines': 0.28; 'chris': 0.28; 'python).': 0.29; 'url:mailman': 0.29; 'case,': 0.29; 'definition': 0.29; 'skip:_ 10': 0.29; 'skip:& 10': 0.29; 'class': 0.29; 'normally': 0.30; 'function': 0.30; 'url:python': 0.32; '(2)': 0.32; 'url:listinfo': 0.32; "aren't": 0.33; 'instances': 0.33; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; '(1)': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'tool': 0.36; 'url:org': 0.36; 'method': 0.36; 'subject: (': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'your': 0.60; '&': 0.61; 'skip:n 10': 0.63; 'state.': 0.71; '2013': 0.84; 'etc,': 0.84; 'self.value': 0.84; 'subject:read': 0.84; 'subject:write': 0.84; 'fibonacci': 0.91; 'write:': 0.91 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=8Ba2NADrLDKeYgbNkTGODCRnjhK9D1GPcxW2zKSiOH4=; b=OSHql22lU89A0aFeHtJ1Ki4I9Km9MVBqunyngJtSdK8vIaAdp9UeRz7Rv5Vu3rTu0h TwvRN1emQJHol/w2pVtCKC/X8pdnCMQtLQAAJ5Tn8x4FtGHo359jY1cvoSuMXIP17bhV iqLMkOAHdoJP8em6p4HznWausau24w9NWOqEMN2S/tpK15RDnizRUy9sOOmUHUkZzFQm Q7T1uXcBArk18AWhTiTIAGHCgz1VmpPyr+2+lS3IjM2EMUnZdGKny5O0tF8rQRANZP2u lOia540H8ygK5405I7vemGqi3/QzaHHjBk04G0fArOoADZNQsE8Oz1Yxz5qXmubVc8bv sKig== MIME-Version: 1.0 In-Reply-To: References: <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> From: Chris Kaynor Date: Mon, 14 Jan 2013 13:37:33 -0800 Subject: Re: Finding the variables (read or write) To: "python-list@python.org" Content-Type: multipart/alternative; boundary=20cf300fb0fd23d15b04d34675a1 X-Gm-Message-State: ALoCoQloP/4EVsj8010+Y6kZvHFGMiflagG1oT8yKjbjIme0TrVhNc1jYrfRK5+hU8K6NWomnOET 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: 124 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358199482 news.xs4all.nl 6923 [2001:888:2000:d::a6]:54678 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36822 --20cf300fb0fd23d15b04d34675a1 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jan 14, 2013 at 1:28 PM, Chris Angelico wrote: > On Tue, Jan 15, 2013 at 6:48 AM, wrote: > > I'd like to develop a small debugging tool for python programs.In > Dynamic Slicing How can I find the variables that are accessed in a > statement? And find the type of access (read or write) for those variables > (in Python). > > ### Write: A statement can change the program state. > > ### Read : A statement can read the program state . > > **For example in these 4 lines we have: > > (1) x = a+b => write{x} & read{a,b} > > (2) y=6 => write{y} & read{} > > (3) while(n>1) => write{} & read{n} > > (4) n=n-1 => write{n} & read{n} > > An interesting question. What's your definition of "variable"? For > instance, what is written and what is read by this statement: > > self.lst[2] += 4 > > Is "self.lst" considered a variable? (In C++ etc, this would be a > member function manipulating an instance variable.) Or is "self" the > variable? And in either case, was it written to? What about: > > self.lst.append(self.lst[-1]+self.lst[-2]) > > (which might collect Fibonacci numbers)? > And those aren't even covering the case that a, normally non-mutating, method actually mutates. Consider the following class (untested): class Test(object): def __init__(self, value): self.value = value self.adds = 0 def __add__(self, other): self.adds += 1 other.adds += 1 return Test(self.value + other.value) With that class, x = a + b would mutate x, a, and b, presuming a and b are instances of Test. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > --20cf300fb0fd23d15b04d34675a1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Mon, Jan 14, 2013 at 1:28 PM, Chris Angelico <rosuav@g= mail.com> wrote:
On Tue, Jan 15, 2013 at 6:= 48 AM, =A0<servekarimi@gmail.co= m> wrote:
> I'd like to develop a small debugging tool for python programs.In = Dynamic Slicing How can I find the variables that are accessed in a stateme= nt? And find the type of access (read or write) for those variables (in Pyt= hon).
> ### Write: A statement can change the program state.
> ### Read : A statement can read the program state .
> **For example in these 4 lines we have:
> (1) x =3D a+b =A0 =A0=3D> write{x} & read{a,b}
> (2) y=3D6 =A0 =A0 =A0 =A0=3D> write{y} & read{}
> (3) while(n>1) =3D> write{} & read{n}
> (4) n=3Dn-1 =A0 =A0 =A0=3D> write{n} & read{n}

An interesting question. What's your definition of "variable= "? For
instance, what is written and what is read by this statement:

self.lst[2] +=3D 4

Is "self.lst" considered a variable? (In C++ etc, this would be a=
member function manipulating an instance variable.) Or is "self" = the
variable? And in either case, was it written to? What about:

self.lst.append(self.lst[-1]+self.lst[-2])

(which might collect Fibonacci numbers)?

And those aren't even covering the case that a, normally non-mu= tating, method actually mutates. Consider the following class (untested):

class Test(object):
=A0 def= __init__(self, value):
=A0 =A0 self.value =3D value
<= div style>=A0 =A0 self.adds =3D 0
=A0 def __add__(self, oth= er):
=A0 =A0 self.adds +=3D 1
=A0 =A0 other.adds +=3D 1
=A0 =A0 return Test(self.value + other.value)

<= /div>
With that class,
=A0x =3D a + b
would mutate x, a, and b, presuming a and b are instances of Test.
=A0

ChrisA
--
http://mail.python.org/mailman/listinfo/python-list

--20cf300fb0fd23d15b04d34675a1--