Re: Is Lexical Binding The Norm Yet?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Is Lexical Binding The Norm Yet?
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.lisp
Date : 21. Jan 2024, 18:35:34
Autres entêtes
Organisation : Stefan Ram
Message-ID : <binding-20240121183433@ram.dialup.fu-berlin.de>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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()


Date Sujet#  Auteur
21 Jan 24 * Re: Is Lexical Binding The Norm Yet?3Stefan Ram
21 Jan 24 `* Re: Is Lexical Binding The Norm Yet?2Stefan Ram
21 Jan 24  `- Re: Is Lexical Binding The Norm Yet?1Stefan Ram

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal