type
status
date
slug
summary
tags
category
icon
password
Property
Jul 13, 2023 01:59 PM
Higher Order Functions


函数作为一等公民,意味着他们可以像操作值一样
Designing Functions


函数的域是它可能作为参数的所有输入的集合。
函数的范围是它可能返回的一组输出值。
纯函数的行为是它在输入和输出之间创建的关系。

保持纯洁和不要重复dry
Generalization



/Higher Order Functions

函数之间的共同结构可能是一个计算过程,而不是一个数字。




Functions as Return Values


就是js中的闭包



operand 操作


the parent frame is always where the function is defined。parent frame 总是定义函数的时候就确定了

Self Reference



print_sums(1) first operator



next_sum
多次调用,就是parent frame的不同,然后n也不同
函数的多次调用,每次都会生成新的函数,因此函数的内存地址是不一样的
命令行会显示返回的函数的地址,但是直接执行py文件不会,除非你调用print函数

- 作者:Kitety
- 链接:https://www.kitety.com/article/cs-61a-5
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章