r...@zedat.fu-berlin.de (Stefan Ram) writes:
[...]
>>>However, to evaluate a method call such as "o.m( a, a1, ... )",
>>>currying does not necessarily have to be used. One can as well
>>>determine the function to be used for "m" from the type of "o"
>>>and then call that function with arguments
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Meredith Montgomery writes:
>>The code below works, but you can see it's kinda ugly. I wish I could
>>uncurry a procedure, but I don't think this is possible. (Is it?)
>
> from functools import partial
> from operator import add
> add5 = partial( a
Meredith Montgomery writes:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> Meredith Montgomery writes:
>>>Is that at all possible somehow? Alternatively, how would you do your
>>>toy oop-system?
>>
>> Maybe something along those lines:
>>
>> from functools import partial
>>
>> def counte
Chris Angelico writes:
> On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery
> wrote:
>>
>> def Counter(name = None):
>> o = {"name": name if name else "untitled", "n": 0}
>> def inc(o):
>> o["n"] += 1
>> return o
>> o["inc"] = inc
>> def get(o):
>> return o["n"]
>> o["get"]
On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery
wrote:
>
> def Counter(name = None):
> o = {"name": name if name else "untitled", "n": 0}
> def inc(o):
> o["n"] += 1
> return o
> o["inc"] = inc
> def get(o):
> return o["n"]
> o["get"] = get
> return o
>
Want a neat demo
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Meredith Montgomery writes:
>>Is that at all possible somehow? Alternatively, how would you do your
>>toy oop-system?
>
> Maybe something along those lines:
>
> from functools import partial
>
> def counter_create( object ):
> object[ "n" ]= 0
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Meredith Montgomery writes:
>>Is that at all possible somehow? Alternatively, how would you do your
>>toy oop-system?
>
> Maybe something along those lines:
>
> from functools import partial
>
> def counter_create( object ):
> object[ "n" ]= 0
Just for investigation sake, I'm trying to simulate OO-inheritance.
(*) What did I do?
I decided that objects would be dictionaries and methods would be
procedures stored in the object. A class is just a procedure that
creates such object-dictionary. So far so good. Trouble arrived when I