Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


devel / comp.lang.python / on implementing a toy oop-system

SubjectAuthor
* on implementing a toy oop-systemMeredith Montgomery
`* Re: on implementing a toy oop-systemStefan Ram
 +- Re: on implementing a toy oop-systemStefan Ram
 +- Re: on implementing a toy oop-systemMeredith Montgomery
 `* Re: on implementing a toy oop-systemMeredith Montgomery
  +* Re: on implementing a toy oop-systemChris Angelico
  |+- Re: on implementing a toy oop-systemMeredith Montgomery
  |`- Re: on implementing a toy oop-systemJulio Di Egidio
  `* Re: on implementing a toy oop-systemMeredith Montgomery
   +* Re: on implementing a toy oop-systemStefan Ram
   |`* Re: on implementing a toy oop-systemMeredith Montgomery
   | `* Re: on implementing a toy oop-systemStefan Ram
   |  `- Re: on implementing a toy oop-systemMeredith Montgomery
   `- Re: on implementing a toy oop-systemJulio Di Egidio

1
on implementing a toy oop-system

<86r10qg89w.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19424&group=comp.lang.python#19424

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!vI7O8iMkFNFLei4SFZylhA.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: on implementing a toy oop-system
Date: Sun, 04 Sep 2022 18:05:31 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86r10qg89w.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="41492"; posting-host="vI7O8iMkFNFLei4SFZylhA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:wImvYheRUJeUynhP85XiNyWrSbY=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Sun, 4 Sep 2022 21:05 UTC

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
decided to have inheritance. The problem might related to the
lexical-nature of closures, but I'm not sure.

(*) A problem

Say I have a Counter-creating object procedure and a Car-creating object
procedure. Cars want to track how many times they park, so they inherit
a counter.

--8<---------------cut here---------------start------------->8---
def Car(maker = None, color = None):
o = inherit(Object(), Counter())
o["maker"] = maker
o["color"] = color
o["speed"] = 0
--8<---------------cut here---------------end--------------->8---

What Object() does is just to return a dictionary. What inherit() does
is just to merge the two dictionaries into a single one (to be used by
the Car procedure).

This didn't come out as I expected, though. Let me show you
step-by-step where the problem is. First, here's a counter in action.

>>> c1 = Counter()
>>> c1["inc"]()["inc"]()
{'id': <function Object.<locals>.id at 0x0000016547C648B0>, 'n': 2, [...]}
>>> c1["n"]
2

That's good and expected: I incremented it twice. But look what happens
with a Car's counter.

>>> c = Car()
>>> c = Car()
>>> c
{'id': <function Object.<locals>.id at 0x0000016547C64B80>, 'n': 0,
'inc': <function Counter.<locals>.inc at 0x0000016547C64C10>, 'dec':
<function Counter.<locals>.dec at 0x0000016547C64CA0>, 'maker': None,
'color': None, 'speed': 0, 'accelerate': <function
Car.<locals>.accelerate at 0x0000016547C64AF0>, 'park': <function
Car.<locals>.park at 0x0000016547C64D30>}

>>> c["inc"]()
{'id': <function Object.<locals>.id at 0x0000016547C64B80>, 'n': 1,
'inc': <function Counter.<locals>.inc at 0x0000016547C64C10>, 'dec':
<function Counter.<locals>.dec at 0x0000016547C64CA0>}

We can see something got incremented! But...

>>> c["n"]
0

Indeed, what got incremented is the dictionary attached to the /inc/
procedure of the Counter closure, so it's that dictionary that's being
mutated. My /inherit/ procedure is not able to bring that procedure
into the Car dictionary.

Is that at all possible somehow? Alternatively, how would you do your
toy oop-system?

(*) Full code below

from random import random

def Object():
myid = random()
def id():
return myid
return {
"id": id
}

def inherit(o, parentObject):
o.update(parentObject)
return o

def Counter(begin_at = 0):
o = Object()
o["n"] = begin_at
def inc():
nonlocal o
o["n"] += 1
return o
o["inc"] = inc
def dec():
nonlocal o
o["n"] -= 1
return o
o["dec"] = dec
return o

def Car(maker = None, color = None):
o = inherit(Object(), Counter())
o["maker"] = maker
o["color"] = color
o["speed"] = 0
def accelerate(speed):
nonlocal o
print(f"Car-{o['id']()}: accelerating to {speed}...")
o["speed"] = speed
return o
o["accelerate"] = accelerate
def park():
nonlocal o
o["speed"] = 0
o["parked"] = True
o["inc"]()
print(f"Car-{o['id']()}: parked! ({o['n']} times)")
return o
o["park"] = park
return o

def tests():
c1 = Counter()
c2 = Counter(100)
c1["inc"]()["inc"]()
c2["dec"]()["dec"]()["dec"]()
print("c1 is 2:", c1["n"])
print("c2 is 97:", c2["n"])
car1 = Car("VW", "Red")
car1["accelerate"](100)
print("speed is 100:", car1["speed"])
car2 = Car("Ford", "Black")
car2["accelerate"](120)["park"]()
car2["accelerate"](50)["park"]()
print("has parked 2 times:", car2["n"])

Re: on implementing a toy oop-system

<inheritance-20220905094544@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19425&group=comp.lang.python#19425

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: 5 Sep 2022 08:47:18 GMT
Organization: Stefan Ram
Lines: 35
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <inheritance-20220905094544@ram.dialup.fu-berlin.de>
References: <86r10qg89w.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de g9CCqiObG80UMKWwv1zd5A+R7GUGnlamiKSEqkTiybp2LT
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Mon, 5 Sep 2022 08:47 UTC

Meredith Montgomery <mmontgomery@levado.to> 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
def counter_increment( object ):
object[ "n" ]+= 1
def counter_value( object ):
return object[ "n" ]

counter_class =( counter_create, counter_increment, counter_value )

def inherit_from( class_, target ):
class_[ 0 ]( target )
for method in class_[ 1: ]:
target[ method.__name__ ]= partial( method, target )

car = dict()

inherit_from( counter_class, car )

print( car[ "counter_value" ]() )
car[ "counter_increment" ]()
print( car[ "counter_value" ]() )

. The "create" part is simplified. I just wanted to show how
to make methods like "counter_increment" act on the object
that inherited them using "partial".

Re: on implementing a toy oop-system

<classes-20220905123432@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19426&group=comp.lang.python#19426

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: 5 Sep 2022 11:40:48 GMT
Organization: Stefan Ram
Lines: 88
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <classes-20220905123432@ram.dialup.fu-berlin.de>
References: <86r10qg89w.fsf@levado.to> <inheritance-20220905094544@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de jiP4kKXIOLkAwFC33GvdJAmvl+SuWct/cIrYg6lyhdyTG0
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Mon, 5 Sep 2022 11:40 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>Maybe something along those lines:

A little more elaborated and without "partial":

# the oop library

def parent( class_ ):
parent = None
try:
parent = class_[ 'parent' ]
except KeyError:
pass
return parent

def do_invoke( instance, method, arguments ):
return method( instance, *arguments )

def invoke_method_of_class \
( instance, selector: str, class_, arguments ):
assert( type( selector )is str )
methods = class_[ 'methods' ]
if selector in methods:
return do_invoke( instance, methods[ selector ], arguments )
else:
par = parent( class_ )
if par:
return \
invoke_method_of_class( instance, selector, par, arguments )

def invoke_method( instance, selector: str, *arguments ):
assert( type( selector )is str )
class_ = instance[ 'class' ]
return \
invoke_method_of_class( instance, selector, class_, arguments )

def prepare_instance( class_, instance ):
fields = class_[ 'fields' ]
for field in fields:
instance[ field ]= fields[ field ]
methods = class_[ 'methods' ]
methods[ 'reset' ]( instance )
par = parent( class_ )
if par:
prepare_instance( par, instance )

def create_instance( class_, instance ):
instance[ 'class' ]= class_
prepare_instance( class_, instance )

def new_instance( class_ ):
instance = {}
create_instance( class_, instance )
return instance

# class definitions

def reset( counter ): counter[ 'n' ]= 0
def greet( counter ): print( "I'm a counter." )
def increment( counter ): counter[ 'n' ]+= 1
def value( counter ): return counter[ 'n' ]

class_counter = \
{ 'name': 'counter',
'parent': None,
'methods': \
{ 'reset': reset, # the constructor must be called 'reset'
'increment': increment, 'value': value, 'greet': greet },
'fields': { 'n': 0 }}

def reset( car ): pass
def greet( car ): print( "I'm a car." )

class_car = \
{ 'name': 'car',
'parent': class_counter, # car inherits from counter
'methods': { 'reset': reset, 'greet': greet },
'fields': {} }

# using the classes

car = new_instance( class_car )
invoke_method( car, "greet" )
print( invoke_method( car, "value" ))
invoke_method( car, "increment" )
print( invoke_method( car, "value" ))

Re: on implementing a toy oop-system

<86leqxlphb.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19427&group=comp.lang.python#19427

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!wV23SPyuRKrhUqTV5ggwqQ.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: Mon, 05 Sep 2022 14:07:12 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86leqxlphb.fsf@levado.to>
References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="30800"; posting-host="wV23SPyuRKrhUqTV5ggwqQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:mccWgELV+uGNqA7JMcviQbNdIE8=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Mon, 5 Sep 2022 17:07 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Meredith Montgomery <mmontgomery@levado.to> 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
> def counter_increment( object ):
> object[ "n" ]+= 1
> def counter_value( object ):
> return object[ "n" ]
>
> counter_class =( counter_create, counter_increment, counter_value )
>
> def inherit_from( class_, target ):
> class_[ 0 ]( target )
> for method in class_[ 1: ]:
> target[ method.__name__ ]= partial( method, target )
>
> car = dict()
>
> inherit_from( counter_class, car )
>
> print( car[ "counter_value" ]() )
> car[ "counter_increment" ]()
> print( car[ "counter_value" ]() )
>
> . The "create" part is simplified. I just wanted to show how
> to make methods like "counter_increment" act on the object
> that inherited them using "partial".

That's simple and interesting. I'll study your more elaborate approach
next, but I like what I see already. Thank you so much.

Re: on implementing a toy oop-system

<86o7v5kdsv.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19581&group=comp.lang.python#19581

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!gi2hsOsEEzGPVN6KOJE8gg.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: Fri, 23 Sep 2022 17:59:12 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86o7v5kdsv.fsf@levado.to>
References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="19710"; posting-host="gi2hsOsEEzGPVN6KOJE8gg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:CkB/QWbCTlSrnrfYFlxvvw2v59c=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Fri, 23 Sep 2022 20:59 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Meredith Montgomery <mmontgomery@levado.to> 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
> def counter_increment( object ):
> object[ "n" ]+= 1
> def counter_value( object ):
> return object[ "n" ]
>
> counter_class =( counter_create, counter_increment, counter_value )
>
> def inherit_from( class_, target ):
> class_[ 0 ]( target )
> for method in class_[ 1: ]:
> target[ method.__name__ ]= partial( method, target )
>
> car = dict()
>
> inherit_from( counter_class, car )
>
> print( car[ "counter_value" ]() )
> car[ "counter_increment" ]()
> print( car[ "counter_value" ]() )
>
> . The "create" part is simplified. I just wanted to show how
> to make methods like "counter_increment" act on the object
> that inherited them using "partial".

I really liked this idea. I organized it my way. Have a look. (Thank
you for the lecture!)

--8<---------------cut here---------------start------------->8---
from functools import partial

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

def Car(maker):
o = {"maker": maker, "state": "off"}
inherit_from(Counter, o)
def on(o):
if o["is_on"]():
raise ValueError("oh, no: car is already on")
o["inc"]()
print(f"{o['maker']}: bruum!")
o["state"] = "on"
return o
o["on"] = partial(on, o)
def off(o):
if o["is_off"]():
raise ValueError("oh, no: car is already off")
print(f"{o['maker']}: spat!")
o["state"] = "off"
return o
o["off"] = partial(off, o)
def is_on(o):
return o["state"] == "on"
o["is_on"] = partial(is_on, o)
def is_off(o):
return o["state"] == "off"
o["is_off"] = partial(is_off, o)
return o

def main():
car1 = Car("Ford")
car2 = Car("VW")
for i in range(5):
car1["on"](); car1["off"]()
for i in range(3):
car2["on"](); car2["off"]()
print(f"car turned on = {car1['get']()} ({car1['maker']})")
print(f"car turned on = {car2['get']()} ({car2['maker']})")

## (*) How to inherit the methods from a class
##
def inherit_from(C, target):
o = C()
for k, v in o.items():
if callable(v):
target[k] = partial(v, target)
else:
target[k] = v
--8<---------------cut here---------------end--------------->8---

Re: on implementing a toy oop-system

<mailman.488.1663970804.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19582&group=comp.lang.python#19582

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: Sat, 24 Sep 2022 08:06:31 +1000
Lines: 38
Message-ID: <mailman.488.1663970804.20444.python-list@python.org>
References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
<86o7v5kdsv.fsf@levado.to>
<CAPTjJmoQ4D7+n94wBKUOU3X0b7jAgvv=oRMHDH3Hc1DFQ7hW1w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de J4Hty8fH0HJ51t30O0gWRQ44BUk2vNKOjitFK+egTSHA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=TVmQy2XP;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'def': 0.04; '2022': 0.05;
'fundamental': 0.09; 'neat': 0.09; 'aside': 0.16; 'chrisa': 0.16;
'classes,': 0.16; 'constructor': 0.16; 'difference,': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'practically': 0.16; 'sept': 0.16; 'subject:oop': 0.16;
'subject:toy': 0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20;
'creates': 0.22; 'returns': 0.22; 'sat,': 0.22; 'classes': 0.26;
'else': 0.27; 'function': 0.27; 'message-id:@mail.gmail.com':
0.32; 'there': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'name:':
0.37; 'using': 0.37; 'received:209.85': 0.37; 'class': 0.37;
'received:209': 0.39; 'received:209.85.208': 0.39; 'want': 0.40;
"there's": 0.61; 'similar': 0.65; 'little': 0.73; 'closure': 0.84;
'meredith': 0.84; 'thing?': 0.84; 'declaration': 0.91; 'demo':
0.91; 'inc': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date;
bh=GhA0hx+hlo0BBjoPqtfG9e2Z+C8wJnZTnaUbEojKZvM=;
b=TVmQy2XPo6BktN9JV5A240ILSsJWZbFUNYBG1P7hVMCCBFA+PcgzV3lb5p7LBBZLkQ
tuKoTaZbiQ/uKqyIdYt6dP1fZbCJMw0hEKOPLhgWYUV/NTz6igzIsygwHJlpPk+S96VR
wFFj/8heUOYFSrnJBL9eTvFOvepjf7CbJ1Xf0t9hN6CWQ8srZKgdk+/bguKgr7eqK6SI
t+dQlkiyL/zhT5JNHG/O0OIhqAyQUCGXLLrz7OYI5hOkXZ8u6sTOLjeNY77k3M0tpvGT
JBBveV2DhAl6ck64OjbOGIfK/RCXpAZrihxvCxr3N/SGBr9/KFnPK4f1Pt0Cb/d5pheR
aA5w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date;
bh=GhA0hx+hlo0BBjoPqtfG9e2Z+C8wJnZTnaUbEojKZvM=;
b=8L/oSM3AyJiqoUo+KYAdkd1yBuv5EBm4JJrsr1+0sZtT0yIb3j7Ev0grNmiGLhn7m7
y7hwjq7YnROWBCy6z5ZD2J6Kyt2MgPR2QYjfgYJF5XLSwRDTzeNP94zd+xvBrKSj9cLe
7vkeap80JexqrE/B0orX05ilDcqKuzJPm4pTnNnhu8NQ47asmE26gDnDeoaheC5RmfhN
vQ8dSnAI0c/ribpzY+c/C0T052DE1iau6abjaHm/POoyLD+trx4urzPuI/GGSVBH7pGv
f15xD0pb+R8rSkAp508EJQybH6sZthGHd9REpn4rD4ihwvUpqyBtPZuAKGDpkfAhzngg
RVVA==
X-Gm-Message-State: ACrzQf0wjDB2B2HL3p46vI7sIJRTTb74ux0cUz0s5NuXpGwMUzGdWEnl
+Srxr8WSuM1ByS6DQhfJ09RQg0GThxYGbz0MP75ZsKqU
X-Google-Smtp-Source: AMsMyM5pJD1r9SWzl5edJGqBxaPZI9fHvL7l8mjJ7f1enrjovGuaXgSeLq3HGFPqTz58IV7qg0j0zvKyEERYuFcpaco=
X-Received: by 2002:a05:6402:43cf:b0:450:eae1:c9d3 with SMTP id
p15-20020a05640243cf00b00450eae1c9d3mr10621068edc.231.1663970803088; Fri, 23
Sep 2022 15:06:43 -0700 (PDT)
In-Reply-To: <86o7v5kdsv.fsf@levado.to>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmoQ4D7+n94wBKUOU3X0b7jAgvv=oRMHDH3Hc1DFQ7hW1w@mail.gmail.com>
X-Mailman-Original-References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
<86o7v5kdsv.fsf@levado.to>
 by: Chris Angelico - Fri, 23 Sep 2022 22:06 UTC

On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery
<mmontgomery@levado.to> 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 of how classes and closures are practically the same thing?

def Counter(name=None):
if not name: name = "untitled"
n = 0
def inc():
nonlocal n; n += 1
def get():
return n
return locals()

Aside from using a nonlocal declaration rather than "self.n", this is
extremely similar to classes, yet there are no classes involved.

A class statement creates a namespace. The locals() function returns
the function's namespace.

Each call to Counter() creates a new closure context, just like each
call to a constructor creates a new object.

There's very little difference, at a fundamental level :)

ChrisA

Re: on implementing a toy oop-system

<868rm937gf.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19584&group=comp.lang.python#19584

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!gi2hsOsEEzGPVN6KOJE8gg.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: Fri, 23 Sep 2022 22:08:16 -0300
Organization: Aioe.org NNTP Server
Message-ID: <868rm937gf.fsf@levado.to>
References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
<86o7v5kdsv.fsf@levado.to>
<CAPTjJmoQ4D7+n94wBKUOU3X0b7jAgvv=oRMHDH3Hc1DFQ7hW1w@mail.gmail.com>
<mailman.488.1663970804.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="53605"; posting-host="gi2hsOsEEzGPVN6KOJE8gg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:mzTpOwQgvMvj4OTk+v9mDyogXro=
 by: Meredith Montgomery - Sat, 24 Sep 2022 01:08 UTC

Chris Angelico <rosuav@gmail.com> writes:

> On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery
> <mmontgomery@levado.to> 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 of how classes and closures are practically the same thing?
>
> def Counter(name=None):
> if not name: name = "untitled"
> n = 0
> def inc():
> nonlocal n; n += 1
> def get():
> return n
> return locals()
>
> Aside from using a nonlocal declaration rather than "self.n", this is
> extremely similar to classes, yet there are no classes involved.
>
> A class statement creates a namespace. The locals() function returns
> the function's namespace.
>
> Each call to Counter() creates a new closure context, just like each
> call to a constructor creates a new object.
>
> There's very little difference, at a fundamental level :)

I started out this way, but I had to change direction to implement
inheritance: the difficulty with closures seems to be lexical scoping,
which makes it hard (or impossible) for me to move these closures to
another ``object''. For instance, the nonlocal /n/ in /inc/ above is
forever bound to that closure; there seems to be no way to make /inc/
update some /n/ in another ``object'', which is needed in my conception
of inheritance. I think Python would have to let me duplicate closures.
(Thanks for showing me /locals()/.)

Re: on implementing a toy oop-system

<1a4a7fc6-dcdb-4282-87ff-875613f95520n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19585&group=comp.lang.python#19585

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:ac8:7f54:0:b0:35d:159d:f88e with SMTP id g20-20020ac87f54000000b0035d159df88emr9397898qtk.415.1664007712336;
Sat, 24 Sep 2022 01:21:52 -0700 (PDT)
X-Received: by 2002:a05:6870:59d:b0:f3:627:e2b0 with SMTP id
m29-20020a056870059d00b000f30627e2b0mr7495634oap.47.1664007712008; Sat, 24
Sep 2022 01:21:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Sat, 24 Sep 2022 01:21:51 -0700 (PDT)
In-Reply-To: <mailman.488.1663970804.20444.python-list@python.org>
Injection-Info: google-groups.googlegroups.com; posting-host=93.41.97.126; posting-account=F3H0JAgAAADcYVukktnHx7hFG5stjWse
NNTP-Posting-Host: 93.41.97.126
References: <86r10qg89w.fsf@levado.to> <inheritance-20220905094544@ram.dialup.fu-berlin.de>
<CAPTjJmoQ4D7+n94wBKUOU3X0b7jAgvv=oRMHDH3Hc1DFQ7hW1w@mail.gmail.com>
<86o7v5kdsv.fsf@levado.to> <mailman.488.1663970804.20444.python-list@python.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1a4a7fc6-dcdb-4282-87ff-875613f95520n@googlegroups.com>
Subject: Re: on implementing a toy oop-system
From: jul...@diegidio.name (Julio Di Egidio)
Injection-Date: Sat, 24 Sep 2022 08:21:52 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2435
 by: Julio Di Egidio - Sat, 24 Sep 2022 08:21 UTC

On Saturday, 24 September 2022 at 00:07:07 UTC+2, Chris Angelico wrote:
> On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery
<snip>
> A class statement creates a namespace. The locals() function returns
> the function's namespace.
>
> Each call to Counter() creates a new closure context, just like each
> call to a constructor creates a new object.
>
> There's very little difference, at a fundamental level :)

That's like saying that functional and OO are essentially the
same, i.e. yet another piece of purely upside down spam.

"Closure" is someway akin to "encapsulation" just because the
very basic design principles of *modularity* is find in every
language and piece of code that is not just pure nonsense and
spaghetti, but the similarity is only superficial, firstly because
encapsulation and closure actually and very fundamentally DO
NOT work the same way (functional is *lexical*, you entire
generation of incompetent morons and spammers) plus of
course OO adds inheritance and polymorphism, and altogether
you and an entire do not even know what your name is anymore...

HTH,

Julio

Re: on implementing a toy oop-system

<86wn9npd8x.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19593&group=comp.lang.python#19593

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!NIZyIN09DZNT0m6ha5gDSQ.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: Wed, 28 Sep 2022 15:25:50 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86wn9npd8x.fsf@levado.to>
References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
<86o7v5kdsv.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="31594"; posting-host="NIZyIN09DZNT0m6ha5gDSQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:BorM7bQcQgXcCAjmiA7kuX+zMQY=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Wed, 28 Sep 2022 18:25 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> Meredith Montgomery <mmontgomery@levado.to> 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
>> def counter_increment( object ):
>> object[ "n" ]+= 1
>> def counter_value( object ):
>> return object[ "n" ]
>>
>> counter_class =( counter_create, counter_increment, counter_value )
>>
>> def inherit_from( class_, target ):
>> class_[ 0 ]( target )
>> for method in class_[ 1: ]:
>> target[ method.__name__ ]= partial( method, target )
>>
>> car = dict()
>>
>> inherit_from( counter_class, car )
>>
>> print( car[ "counter_value" ]() )
>> car[ "counter_increment" ]()
>> print( car[ "counter_value" ]() )
>>
>> . The "create" part is simplified. I just wanted to show how
>> to make methods like "counter_increment" act on the object
>> that inherited them using "partial".
>
> I really liked this idea. I organized it my way. Have a look. (Thank
> you for the lecture!)

But it lacks consistency.

> from functools import partial
>
> 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

This parent class is not defined in the same way as the child class
below. The class below uses partial to fix the object in the method,
but the parent one does not. We need consistency.

But if we curry the parent class's methods (that is, if we apply partial
on it to fix the object in its first argument), we will curry them a
second time in inherit_from. That won't work. I can't see an elegant
solution there, so what I'm going to do is to keep a copy of the
uncurried original method.

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?)

# -*- mode: python; python-indent-offset: 2 -*-
def Counter(name = None):
self = {"name": name if name else "untitled", "n": 0}
def inc(self):
self["n"] += 1
return self
self["inc_uncurried"] = inc
self["inc"] = curry(inc, self)
def get(self):
return self["n"]
self["get_uncurried"] = get
self["get"] = curry(get, self)
return self

def Car(maker):
self = {"maker": maker, "state": "off"}
inherit_from(Counter, self)
def on(self):
if self["is_on"]():
raise ValueError("oh, no: car is already on")
self["inc"]()
print(f"{self['maker']}: bruum!")
self["state"] = "on"
return self
self["on_uncurried"] = on
self["on"] = curry(on, self)
def off(self):
if self["is_off"]():
raise ValueError("oh, no: car is already off")
print(f"{self['maker']}: spat!")
self["state"] = "off"
return self
self["off_uncurried"] = off
self["off"] = curry(off, self)
def is_on(self):
return self["state"] == "on"
self["is_on_uncurried"] = is_on
self["is_on"] = curry(is_on, self)
def is_off(self):
return self["state"] == "off"
self["is_off_uncurried"] = is_off
self["is_off"] = curry(is_off, self)
return self

def main():
car1 = Car("Ford")
car2 = Car("VW")
for i in range(5):
car1["on"](); car1["off"]()
for i in range(3):
car2["on"](); car2["off"]()
print(f"car turned on = {car1['get']()} ({car1['maker']})")
print(f"car turned on = {car2['get']()} ({car2['maker']})")

>>> main()
Ford: bruum!
Ford: spat!
Ford: bruum!
Ford: spat!
Ford: bruum!
Ford: spat!
Ford: bruum!
Ford: spat!
Ford: bruum!
Ford: spat!
VW: bruum!
VW: spat!
VW: bruum!
VW: spat!
VW: bruum!
VW: spat!
car turned on = 5 (Ford)
car turned on = 3 (VW)

Re: on implementing a toy oop-system

<partial-20220928200121@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19594&group=comp.lang.python#19594

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: 28 Sep 2022 19:02:05 GMT
Organization: Stefan Ram
Lines: 18
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <partial-20220928200121@ram.dialup.fu-berlin.de>
References: <86r10qg89w.fsf@levado.to> <inheritance-20220905094544@ram.dialup.fu-berlin.de> <86o7v5kdsv.fsf@levado.to> <86wn9npd8x.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de gNCkAhd+0u8Yx4RHS8ASZQkrAxzQfBc+LWAoT7+MYaBZio
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Wed, 28 Sep 2022 19:02 UTC

Meredith Montgomery <mmontgomery@levado.to> 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( add, 5 )
print( add5( 2 ))
# might be dependent on implementation details of "functools":
uncurried = add5.func
print( uncurried( 14, 7 ))

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 "o", "a", "a1", ...

Re: on implementing a toy oop-system

<a068ec19-af1b-4692-bfbd-0ada5badd637n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19599&group=comp.lang.python#19599

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:620a:4407:b0:6cb:e111:32c2 with SMTP id v7-20020a05620a440700b006cbe11132c2mr1202605qkp.415.1664436488972;
Thu, 29 Sep 2022 00:28:08 -0700 (PDT)
X-Received: by 2002:a05:6870:1711:b0:131:cc05:d883 with SMTP id
h17-20020a056870171100b00131cc05d883mr775011oae.32.1664436488729; Thu, 29 Sep
2022 00:28:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Thu, 29 Sep 2022 00:28:08 -0700 (PDT)
In-Reply-To: <86wn9npd8x.fsf@levado.to>
Injection-Info: google-groups.googlegroups.com; posting-host=93.41.96.214; posting-account=F3H0JAgAAADcYVukktnHx7hFG5stjWse
NNTP-Posting-Host: 93.41.96.214
References: <86r10qg89w.fsf@levado.to> <inheritance-20220905094544@ram.dialup.fu-berlin.de>
<86o7v5kdsv.fsf@levado.to> <86wn9npd8x.fsf@levado.to>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a068ec19-af1b-4692-bfbd-0ada5badd637n@googlegroups.com>
Subject: Re: on implementing a toy oop-system
From: jul...@diegidio.name (Julio Di Egidio)
Injection-Date: Thu, 29 Sep 2022 07:28:08 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2404
 by: Julio Di Egidio - Thu, 29 Sep 2022 07:28 UTC

On Wednesday, 28 September 2022 at 20:26:18 UTC+2, Meredith Montgomery wrote:
> Meredith Montgomery <mmont...@levado.to> writes:
> > r...@zedat.fu-berlin.de (Stefan Ram) writes:
<snip>
> >> . The "create" part is simplified. I just wanted to show how
> >> to make methods like "counter_increment" act on the object
> >> that inherited them using "partial".
> >
> > I really liked this idea. I organized it my way. Have a look. (Thank
> > you for the lecture!)
> >
> But it lacks consistency.

It lacks all sense, you trolling piece of shit: indeed of all
the incompetent pretenders and polluters of ponds, Ram
who presents himself as a "teacher" is by far the most
despicable and disgusting, a perfect representative of
contemporary infamy.

That said, you bunch of spamming pieces of shit are indeed
just wasting everybody's breathable air: you wanna build an
OO system, learn how to define a language and compiler and
the v-tables for polymorphism and what-not, not that stupid
pseudo-parroting simulation that is as akin to a real language
as you with a pair of Nikes are to Michael Jordan.

Fucking generation of twisted nazi retards : get extinguished
already...

*Plonk*

Julio

Re: on implementing a toy oop-system

<86zgeii1c4.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19602&group=comp.lang.python#19602

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!uEW95JwoTmKxfGNs4v3l0g.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: Thu, 29 Sep 2022 13:37:15 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86zgeii1c4.fsf@levado.to>
References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
<86o7v5kdsv.fsf@levado.to> <86wn9npd8x.fsf@levado.to>
<partial-20220928200121@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="50054"; posting-host="uEW95JwoTmKxfGNs4v3l0g.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:NVK9VFye8SM4C6hjxGEb5EOdMzA=
 by: Meredith Montgomery - Thu, 29 Sep 2022 16:37 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Meredith Montgomery <mmontgomery@levado.to> 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( add, 5 )
> print( add5( 2 ))
> # might be dependent on implementation details of "functools":
> uncurried = add5.func
> print( uncurried( 14, 7 ))

It works on my system here. Thank you so much for your help. (I've
been learning a lot with you!)

> 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 "o", "a", "a1", ...

Was that your last approach? I only glanced at it so far. But I
remember seeing you describing an object and listing out which methods
were defined for it and then there was one procedure that would take the
role of invoking the methods (with the proper arguments).

Re: on implementing a toy oop-system

<methods-20220929174452@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19603&group=comp.lang.python#19603

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: 29 Sep 2022 16:46:58 GMT
Organization: Stefan Ram
Lines: 30
Expires: 1 Sep 2023 11:59:58 GMT
Message-ID: <methods-20220929174452@ram.dialup.fu-berlin.de>
References: <86r10qg89w.fsf@levado.to> <inheritance-20220905094544@ram.dialup.fu-berlin.de> <86o7v5kdsv.fsf@levado.to> <86wn9npd8x.fsf@levado.to> <partial-20220928200121@ram.dialup.fu-berlin.de> <86zgeii1c4.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de +fZzdrkbfcd+4FtjyP/bNg9DEuNd6gZL8/hRJRkqRHoQrO
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 29 Sep 2022 16:46 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:
>ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>Meredith Montgomery <mmontgomery@levado.to> 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( add, 5 )
>>print( add5( 2 ))
>># might be dependent on implementation details of "functools":
>>uncurried = add5.func
>>print( uncurried( 14, 7 ))
>It works on my system here. Thank you so much for your help. (I've
>been learning a lot with you!)

Glad to hear that!

>>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 "o", "a", "a1", ...
>Was that your last approach?

Yes, I think so.

(There are also languages with "multi-methods", where upon
a function call "m( o, o1, ... )" the decision which function
to call depends on all the types of all the arguments.)

Re: on implementing a toy oop-system

<86mtaihxi7.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19605&group=comp.lang.python#19605

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!uEW95JwoTmKxfGNs4v3l0g.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on implementing a toy oop-system
Date: Thu, 29 Sep 2022 15:00:00 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86mtaihxi7.fsf@levado.to>
References: <86r10qg89w.fsf@levado.to>
<inheritance-20220905094544@ram.dialup.fu-berlin.de>
<86o7v5kdsv.fsf@levado.to> <86wn9npd8x.fsf@levado.to>
<partial-20220928200121@ram.dialup.fu-berlin.de>
<86zgeii1c4.fsf@levado.to>
<methods-20220929174452@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="63656"; posting-host="uEW95JwoTmKxfGNs4v3l0g.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:aNYX1vugq9BvcqvcGeJh3YkdGyU=
 by: Meredith Montgomery - Thu, 29 Sep 2022 18:00 UTC

ram@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 "o", "a", "a1", ...
>>Was that your last approach?
>
> Yes, I think so.
>
> (There are also languages with "multi-methods", where upon
> a function call "m( o, o1, ... )" the decision which function
> to call depends on all the types of all the arguments.)

I think Clojure is one such. I've read Part 1 of ``Clojure in Action''
by Amit Rathore, 2012, Manning, ISBN 9781935182597. I liked it.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor