Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.python / Re: Is Lexical Binding The Norm Yet?

SubjectAuthor
* Re: Is Lexical Binding The Norm Yet?Stefan Ram
`* Re: Is Lexical Binding The Norm Yet?Stefan Ram
 `- Re: Is Lexical Binding The Norm Yet?Stefan Ram

1
Re: Is Lexical Binding The Norm Yet?

<prototype-20240120111210@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25152&group=comp.lang.python#25152

  copy link   Newsgroups: comp.lang.lisp comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.lisp,comp.lang.python
Subject: Re: Is Lexical Binding The Norm Yet?
Date: 20 Jan 2024 10:13:40 GMT
Organization: Stefan Ram
Lines: 46
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <prototype-20240120111210@ram.dialup.fu-berlin.de>
References: <uo1i8c$jbru$2@dont-email.me> <86r0ijsdyj.fsf@williamsburg.bawden.org> <871qajgr9k.fsf@nightsong.com> <uo4id7$14ifr$1@dont-email.me> <jwvedeg510z.fsf-monnier+comp.lang.lisp@gnu.org> <uo9cbb$264u2$1@dont-email.me> <20240117122629.806@kylheku.com> <uo9o4k$281t4$1@dont-email.me> <qitjqi521brjnpvebd2b1bidrhevocbt62@4ax.com> <uod249$30h1g$3@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de bZ5fgMPL6iinXMX0xNiBoAvuWyrFWVMkhz3pVq0wwZIMXK
Cancel-Lock: sha1:5vUMwzwWH0NOgpJYEXIFaStj3BE= sha256:UMkhXDtlqemCgAsfWYy4BF5EZzKaq88+FX4GMffnyQE=
X-Copyright: (C) Copyright 2024 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-1901, en-US, it, fr-FR
 by: Stefan Ram - Sat, 20 Jan 2024 10:13 UTC

Newsgroups: comp.lang.lisp,comp.lang.python

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>On Thu, 18 Jan 2024 23:39:26 -0500, George Neuner wrote:
>>Programming with closures is more like using "prototype OO". Prototype
>>systems don't have classes, but rather ANY object can be modified to
>>change its set of instance data and/or methods, and can be cloned to
>>create new objects of that same "type".
>That’s true of Python, too.

Yes that's true. Forgive me guys if that's too "off topic"
in comp.lang.lisp, but it might not be obvious how to create
an object in Python and then attach fields or methods to it.
So here I humbly submit a small example program to show this.

main.py

from types import *

# create a new object
def counter_object(): pass

# attach a numeric field to the object
counter_object.counter_value = 0

# define a named function
def increment_value( self ): self.counter_value += 1

# attach the named function to the object as a method
counter_object.increment_value = \
MethodType( increment_value, counter_object )

# call the method
counter_object.increment_value()

# attach an unnamed function to the object
counter_object.get_value = \
MethodType( lambda self: self.counter_value, counter_object )

# call that method
print( counter_object.get_value() )

This program will then print "1" and a line terminator.

Newsgroups: comp.lang.lisp,comp.lang.python

Re: Is Lexical Binding The Norm Yet?

<prototypes-20240121082408@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25153&group=comp.lang.python#25153

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Is Lexical Binding The Norm Yet?
Date: 21 Jan 2024 07:28:12 GMT
Organization: Stefan Ram
Lines: 64
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <prototypes-20240121082408@ram.dialup.fu-berlin.de>
References: <uo1i8c$jbru$2@dont-email.me> <86r0ijsdyj.fsf@williamsburg.bawden.org> <871qajgr9k.fsf@nightsong.com> <uo4id7$14ifr$1@dont-email.me> <jwvedeg510z.fsf-monnier+comp.lang.lisp@gnu.org> <uo9cbb$264u2$1@dont-email.me> <20240117122629.806@kylheku.com> <uo9o4k$281t4$1@dont-email.me> <qitjqi521brjnpvebd2b1bidrhevocbt62@4ax.com> <uod249$30h1g$3@dont-email.me> <prototype-20240120111210@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 yZUfescOwqQ/D+VmzaFfnweZciYqIHmPV9HHyzbWk3n5T3
Cancel-Lock: sha1:pqlF2reCMa4v18Q7Ua7YSPUUWM0= sha256:Y2mdvl9ISDPk8hEF4G+W2lfBlmAA34KnCR5FMJZ6AoA=
X-Copyright: (C) Copyright 2024 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-1901, en-US, it, fr-FR
 by: Stefan Ram - Sun, 21 Jan 2024 07:28 UTC

Newsgroups: comp.lang.python

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>from types import *

What do you mean, the cloning part is missing?

import types

# create a new object
def counter_object(): pass

# attach a numeric field to the object
counter_object.counter_value = 0

# define a named function
def increment_value( self ): self.counter_value += 1

# attach the named function to the object as a method
counter_object.increment_value = \
types.MethodType( increment_value, counter_object )

# call the method
counter_object.increment_value()

# attach an unnamed function to the object
counter_object.get_value = \
types.MethodType( lambda self: self.counter_value, counter_object )

# call that method
# Prints "1".
print( counter_object.get_value() )

# An ad-hoc function to clone an object for the purpose of "prototype
# inheritance". Might need to be refined for more general uses.
def clone_object( object_ ):
def new_object(): pass
for attribute in dir( object_ ):
if attribute[ :2 ]!= '__':
if type( getattr( object_, attribute ))== types.MethodType:
method = getattr( object_, attribute )
function = types.FunctionType( method.__code__, {} )
method = types.MethodType( function, new_object )
setattr( new_object, attribute, method )
else:
field = getattr( object_, attribute )
setattr( new_object, attribute, field )
return new_object

# create two "clones" ("clone objects")
clone = clone_object( counter_object )
other = clone_object( counter_object )

# The clones "inherited" the counter field including its value.
# Prints "1 1 1".
print( counter_object.get_value(), clone.get_value(), other.get_value() )

# Each object's counter has a value independent from the other object's
# counter.
other.increment_value()

# Prints "1 1 2"
print( counter_object.get_value(), clone.get_value(), other.get_value() )

Re: Is Lexical Binding The Norm Yet?

<print-20240121182428@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=25159&group=comp.lang.python#25159

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Is Lexical Binding The Norm Yet?
Date: 21 Jan 2024 17:27:09 GMT
Organization: Stefan Ram
Lines: 90
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <print-20240121182428@ram.dialup.fu-berlin.de>
References: <uo1i8c$jbru$2@dont-email.me> <86r0ijsdyj.fsf@williamsburg.bawden.org> <871qajgr9k.fsf@nightsong.com> <uo4id7$14ifr$1@dont-email.me> <jwvedeg510z.fsf-monnier+comp.lang.lisp@gnu.org> <uo9cbb$264u2$1@dont-email.me> <20240117122629.806@kylheku.com> <uo9o4k$281t4$1@dont-email.me> <qitjqi521brjnpvebd2b1bidrhevocbt62@4ax.com> <uod249$30h1g$3@dont-email.me> <prototype-20240120111210@ram.dialup.fu-berlin.de> <prototypes-20240121082408@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 7RPIJwGSaZAUgNXETTmGagCtHP91Fqlpg41HOSjWnCWA17
Cancel-Lock: sha1:tbe8FIvYuxBDKOBm+S1SIuEjh50= sha256:Wyrq+wfnmgz5A+cyh3kZ/DPxqkqkiWS+HgONVl87N58=
X-Copyright: (C) Copyright 2024 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-1901, en-US, it, fr-FR
 by: Stefan Ram - Sun, 21 Jan 2024 17:27 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>What do you mean, the cloning part is missing?

Most standard functions do not call the custom dunder methods
of our prototype-based objects. Yes, the standard library was
written for class-based objects ("3.3.12 Special method lookup")!

However, if you just need few staples such as "str" and "print",
you can define them yourself. (The standard library will not
use them, but you can call them in your own code.)

import types

# a custom global str functions for prototype objects
# used below
def str( x ): return x.__str__()

# a custom global print functions for prototype objects
# used below
std_print = print
def print( *args, **kwargs ):
return std_print( *( arg.__str__() for arg in args ), **kwargs )

# create a new object
def counter_object(): pass

# attach a numeric field to the object
counter_object.counter_value = 0

# define a named function
def increment_value( self ): self.counter_value += 1

# attach the named function to the object as a method
counter_object.increment_value = \
types.MethodType( increment_value, counter_object )

# call the method
counter_object.increment_value()

# attach an unnamed function to the object
counter_object.get_value = \
types.MethodType( lambda self: self.counter_value, counter_object )

# attach an unnamed function to the object
counter_object.__str__ = \
types.MethodType\
( lambda self: str( self.counter_value ), counter_object )

# call that method
# Prints "1".
print( counter_object.get_value() )

# An ad-hoc function to clone an object for the purpose of "prototype
# inheritance". Might need to be refined for more general uses.
def clone_object( object_ ):
def new_object(): pass
for attribute in dir( object_ ):
if attribute[ :2 ]!= '__' or attribute in[ '__str__' ]:
if type( getattr( object_, attribute ))== types.MethodType:
method = getattr( object_, attribute )
function = types.FunctionType\
( method.__code__, globals() )
method = types.MethodType( function, new_object )
setattr( new_object, attribute, method )
else:
field = getattr( object_, attribute )
setattr( new_object, attribute, field )
return new_object

# create two "clones" ("clone objects")
clone = clone_object( counter_object )
other = clone_object( counter_object )

# The clones "inherited" the counter field including its value.
# Prints "1 1 1".
print( counter_object.get_value(), clone.get_value(), other.get_value() )

# Each object's counter has a value independent from the other
# object's counter.
other.increment_value()

# Prints "1 1 2"
print( counter_object.get_value(), clone.get_value(), other.get_value() )

# Prints "1 1 2"
print( str( counter_object ), str( clone ), str( other ))

# Prints "1 1 2"
print( counter_object, clone, other )


devel / comp.lang.python / Re: Is Lexical Binding The Norm Yet?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor