list storing variables

Ian Kelly ian.g.kelly at gmail.com
Mon Feb 23 14:29:33 EST 2015


On Mon, Feb 23, 2015 at 12:06 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> But there is! I just demonstrated it in a previous posting:
>
>> In Python, you can accomplish "&" by creating an object:
>>
>>    >>> a = 3
>>    >>> b = 4
>>    >>> class AmpersandA:
>>    ...     def get(self): return a
>>    ...     def set(self, value): global a; a = value
>>    ...
>>    >>> class AmpersandB:
>>    ...     def get(self): return b
>>    ...     def set(self, value): global b; b = value
>>    ...
>>    >>> l = [ AmpersandA(), AmpersandB() ]
>>    >>> for m in l:
>>    ...     m.set(7)
>>    ...
>>    >>> print(a)
>>    7
>>    >>> print(b)
>>    7
>>    >>>
>>
>> It's exactly like "&" in C escept it's a slight bit more verbose and the
>> exact implementation is dependent on the name of the variable.

"Sure, you can have list comprehensions in C! Just write a function
whose arguments are two other functions and an input array."

Obviously one can use any Turing-complete language to emulate features
of any other Turing-complete language, but I think the point is that
there is no syntactic support for it.



More information about the Python-list mailing list