Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.lisp Subject: Re: Is Lexical Binding The Norm Yet? Date: 21 Jan 2024 17:35:34 GMT Organization: Stefan Ram Lines: 42 Expires: 1 Dec 2024 11:59:58 GMT Message-ID: References: <86r0ijsdyj.fsf@williamsburg.bawden.org> <871qajgr9k.fsf@nightsong.com> <20240117122629.806@kylheku.com> <86y1cjqpei.fsf@williamsburg.bawden.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de EEZCq/LWvobtE/N49QBU8Q44xvFqqVlSPQ3yJUEAACIPcd Cancel-Lock: sha1:h6T6HUKrjmlU0MrXZjdgGEN6KKU= sha256:8rSihSKtYTIQOpeLu/JAD3M2RjVR/0o8rmylbFgVQwo= 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 ram@zedat.fu-berlin.de (Stefan Ram) writes: >the Python standard library assumes class-based objects.) Since the thread is about "binding": Python can be very explicit when it comes to binding (should you need it). main.py import types x = 2 def f(): return x # prints "2" print( f() ) g = types.FunctionType( f.__code__, { 'x': 4 } ) # prints "4" print( g() ) h = types.FunctionType( f.__code__, globals() ) # prints "2" print( h() ) def a(): x = 3 # prints "2" print( f() ) # prints "3" print( types.FunctionType( f.__code__, locals() )() ) # prints "2" print( types.FunctionType( f.__code__, globals() )() ) a()