[210_19] feat: (srfi srfi-165) 初始化
#409
Open
+1,429
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
needs #408.
[210_19]
(srfi srfi-165)https://srfi.schemers.org/srfi-165/srfi-165.html
任务相关的代码文件
goldfish/srfi/srfi-165.scmtests/goldfish/srfi/srfi-165-test.scm如何测试
2026/2/12 实现 SRFI-165 (The Environment Monad)
What
完整实现 SRFI-165 规范,提供环境单子(Environment Monad)支持:
make-computation-environment-variable,computation-environment-ref/update/update!make-computation,computation-pure,computation-bindcomputation-ask,computation-local,computation-environment-copycomputation-each,computation-sequence,computation-forked,computation-bind/forkedcomputation-fn,computation-with,computation-with!define-computation-type使用向量(vector)+ 哈希表 + alist 实现双层环境(local/global)查找机制
通过
box模式模拟可变性(暂时无 SRFI-111,手动模拟)提供默认计算类型
make-computation-environment和computation-runWhy
SRFI-165 提供了一种纯函数式的方式来处理隐式参数传递和上下文依赖计算,解决了以下问题:
update)与副作用更新(update!)的灵活组合forked实现环境隔离,支持临时修改不影响外层上下文How
核心架构:
<computation-environment-variable>):通过define-record-type定义,包含名称、默认值、不可变标志和唯一ID[global-ht local-alist predefined-cells...],其中 global 为哈希表(SRFI-125),local 为 alist关键实现细节:
make-computation将过程包装为接收computecontinuation 的形式,支持延迟执行computation-bind实现 monadic bind,支持多值传递(通过call-with-values)computation-forked使用computation-environment-copy创建环境浅拷贝,确保分支隔离define-computation-type为宏,在展开时生成带预定义变量的构造函数和运行器variable-comparator(SRFI-128)确保哈希表键的正确比较依赖:SRFI-1(列表操作)、SRFI-128(比较器)、SRFI-125(哈希表)