← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 6074.d.1.a.3.c.12.a.1.i · 生成模型:GPT-6

局部可变与全局状态

理解等级:中级

局部可变变量只在函数内部参与计算,可让构造或遍历过程更直观。若变化写入外部存储或传给持有共享引用的调用方,其他代码也可以观察到它。可变全局状态的影响范围更大,理解函数时须跟踪所有可能写入的位置。重写宏内部持有的语法树是局部更新,调用者接到的是生成结果。

相关卡片 [[纯函数与外部副作用]]、[[宏就地修改函数语法树]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • From panic to result: Error handling 从解析到局部修改 · 查看原书依据

      DEFINITION By internal mutation, I mean any mutation that has no visible effect outside its function. An example would be a counter (let mut counter…) that never leaves the function (is not returned, not saved in a database, etc.). This kind of mutation is not very harmful because the limited scope means the code makes it less error prone and easier to understand.

    参考来源

    - 位置:《Write Powerful Rust Macros》第07章《From panic to result: Error handling》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-7.xhtml#p75) - 结论依据:7.6 的定义框以局部计数器、可在调用间传递的可变值和可变全局变量比较变化的可观察范围。 - 原始内容:DEFINITION By internal mutation, I mean any mutation that has no visible effect outside its function. An example would be a counter (let mut counter…) that never leaves the function (is not returned, not saved in a database, etc.). This kind of mutation is not very harmful because the limited scope means the code makes it less error prone and easier to understand.