Adding a Par construct to Python?
steven at REMOVE.THIS.cybersource.com.au
Wed May 20 01:57:38 EDT 2009
On Tue, 19 May 2009 21:41:08 -0700, Aaron Brady wrote:
> On May 19, 11:20 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>> Steven D'Aprano <ste... at REMOVE.THIS.cybersource.com.au> writes:
>> > (4) the caller is responsible for making sure he never shares data
>> > while looping over it.
>> > I don't think I've missed any possibilities. You have to pick one of
>> > those four.
>> I wonder if the compiler can check that a given function doesn't change
>> any data. Then:
>> def f(x):
>> return x*sqrt(x) + 3 # does not mutate any data
>> def g(x): ... # likewise
>> s = parallel_dot_product(parallel_map(f, vec), parallel_map(g,vec))
> You can do the basics of this using the 'ast' module. Just check that
> no nodes in the ast tree are Assign nodes, including augmented assign.
> Then 'f' is defined as:
> f= pure( '''
> return x*sqrt(x) + 3 # does not mutate any data
> ''' )
Can you explain how you can tell that there are no side-effects from
x*sqrt(x)+3 ? What if I have this?
def __add__(self, other):
parrot += 1
return 5 + other
x = Funny()
More information about the Python-list