[Python-il] [pyweb-il:1072] Python coding question

Shai Berger shai at platonix.com
Wed Jul 7 17:01:05 IDT 2010


On Wednesday 07 July 2010, Gabor Szabo wrote:
> Hi,
> 
> > On Thu, Jul 1, 2010 at 5:35 PM, Dov Grobgeld <dov.grobgeld at gmail.com> 
wrote:
> >> 
> >> Then "python" might look like:
> >> 
> >>     ∀ n ∈ names:
> >>       if n ≠ "foo":
> >>         α ← n
> >>         ß = re∘search〈"foo", α〉
> >> 
> 
> I have not done any math for a long, long time. Would you mind explaining
> what would the above do?
> 
To complement Haran's reply, the translation of the above exposes why this 
wouldn't necessarily be a good idea:

for n in names:
	if n != "foo":
		a = n
		b = re.search("foo",a)

But the differences matter:

Dov chooses to use the function composition operator ∘ for attribute access; 
to me, this makes little sense, but perhaps I'm missing something.

Why he avoids the use of parentheses for function application also escapes me.

But most importantly, the use of ∀ (for all) in the loop construct implies 
parallelism, or, more accurately, independence between the code applied to 
each member of the set -- where Python forces an order and allows 
dependencies.

I haven't been in academia for quite some time, but as far as I recall, people 
only used ∀ when defining conditions (e.g, """ ∀ n ∈ names: n ≠ "foo" """ as a 
boolean expression) using read-only operations; when state-modifying iteration 
was intended, people tended to use "for".

My 2 cents,
	Shai.


More information about the Python-il mailing list