Blacad Docs
L8 1
正在初始化搜索引擎
    Blacad/blog
    • 首页
    • CS
    Blacad/blog
    • 首页
      • CS61A
        • L1 Welcome
        • L2 Functions
        • L3 Control
        • L4 Higher Order Function
        • L5 Environments
        • L6 Sounds
        • L7 Function Abstract
        • L8 Function Example
        • L9 Recursion
        • L10 Tree Recursion
        • L11 Sequences
        • L12 Containers
        • L13 Data Abstraction
        • L14 Trees
        • L15 Mutability
        • L16 Iterators
        • L17 Generators
        • L18 Objects
        • L19 Class Attributes
        • L20 Inheritance
        • L21 Representations
        • L22 Composition
        • L23 Efficiency
        • L24 Decomposition
        • L25 Data Example
        • L28 Scheme
        • L29 Scheme Lists
        • L30 Calculator
        • L31 Interpreters
        • L32 Tail Calls
        • L33 Programs as Data
        • L34 Macros
        • L35 SQL
        • L36 Tables
        • L37 Aggregation
        • L38 Database
        • L39 思考解决问题
        • Hog
        • Cats
        • Ants
        • Scheme
        • Note
      • CS70
        • Note10 Counting
        • Note11 Countability
        • Note12 Computability
        • Note13 Discrete Probability
        • Note14 Conditional Probability
        • Note15 RV
        • Note16 RV
        • Note17 Concentration Inequalities and the Laws of Large Numbers
        • Note18 Hashing and Load Balance
        • Note19 Geometric and Poisson Distributions
        • Note20 Continuous Probability Distribution
        • Note21 Markov Chains
        • 不完备补充
        • 限与界

    L8 1

    def trace(f):
        def traced(x):
            print("-> Calling ",f,"arg ",x)
            return f(x)
        return traced
    # 下面两段代码等效
    @trace
    def square(x):
        return x*x
    
    square = trace(square)
    
    square(5)