Squashed 'docs/standards/playbook/' changes from c3f8137..25d895d
25d895d 🐛 fix(gitea_workflow): clean up temp repos after job steps 2bc3b11 🐛 fix(gitea_workflow): clean up temporary repo dirs in workflows 98c3f30 📝 docs(agent_rules): allow plan execution on current branch 16c7230 📝 docs(prompts): define custom verify layering 8efc4dd 🐛 fix(skills): quote commit-message description bc8498f 🐛 fix(ci): install tomli for gitea tests 55cda3b 🐛 fix(tests): report missing toml parser clearly c0729c7 🐛 fix(playbook): import Optional for cli compatibility 63e24bf 📦 deps(skills): sync thirdparty skills d2f9356 🐛 fix(ci): isolate gitea workflow repos 588b81d 🐛 fix(ci): inline gitea workflow bootstrap e0b1c3a ♻️ refactor(skills): standardize first-party skill contracts 2c5050d ♻️ refactor(skills): rename repo skills source dir f049dfb 📦 deps(skills): drop duplicate first-party superpowers skills 234b335 ✨ feat(workflow): add superpowers planning and execution state tracking c1702a6 📝 docs(markdown): format tracked markdown and drop stale templates 2325409 📝 docs(markdown): clarify optional markdownlint usage 214c44e 🔧 chore(markdown): add markdownlint baseline and lint fixes a22b324 📝 docs(templates): add execution and memory-bank prompt templates 223a797 📝 docs(templates): update README for Claude Code and current features 4ac8672 📝 docs: simplify README + platform-agnostic tools + auto-create local rules 2431c9d 📝 docs: add claude_md config and use cross-platform paths d64b248 📝 docs: fix README.md inaccuracies and add Claude Code info c8d6bf2 🐛 fix(playbook): use relative paths in CLAUDE.md when not at project root 6518f0f ✨ feat(playbook): auto-create CLAUDE.md with path discovery 6ec9a45 ✨ feat(skills): add skill_link symlink support + platform-agnostic prompt 9f8b6b5 📝 docs: update README and config example for Claude Code support 79cff6c 📝 docs(skills): add Claude Code platform support 452c6f5 ✨ feat(playbook): auto-inject AGENTS.md into CLAUDE.md e1dbf3c 🐛 fix(skills): remove dual-path from commit-message skill f3a7259 🔧 chore(ci): use prepare_repo.sh in both workflows da08212 🔧 chore(ci): extract prepare_repo.sh and clean up workflows 7ade85e 🗑️ remove(tsl): drop syntax_book/, data/ source and build script f94dba0 ♻️ refactor(skills): update playbook.py and tests for thirdparty/ layout b3df412 ♻️ refactor(skills): separate thirdparty skills into thirdparty/ subdirectory 64950e7 📦 deps(skills): sync thirdparty skills a2e3cb0 ✨ feat(playbook): add no_backup deploy controls 8609d59 🐛 fix(docs): repair reference catalog source links 956da11 🐛 fix(playbook): publish hidden ci test fixes 3f67754 📦 deps(skills): sync thirdparty skills 08ca87b 📦 deps(skills): add karpathy thirdparty sync 96b705b 📝 docs(tsl): rebuild canonical syntax and routing manual 3ed5052 📦 deps(skills): sync thirdparty skills 60108dd 📦 deps(skills): sync thirdparty skills da85d4e 🐛 fix(thirdparty): prune nested project snapshots a2a697e 📦 deps(skills): sync thirdparty skills 9df610a 🐛 fix(thirdparty): exclude duplicated superpowers skills 33dd5bb 🐛 fix(thirdparty): preserve optional manifest fields 91b0ea7 🐛 fix(thirdparty): preserve manifest during snapshot update 2e26f98 🔧 chore(thirdparty): generalize skills sync pipeline 5b9c1e3 📦 deps(skills): sync superpowers 2f2d34a 📝 docs(readme): normalize subtree command spacing 62db7db 🐛 fix(ci): serialize superpowers update and sync 3463223 🐛 fix(ci): use literal superpowers sync paths 48f6de8 📦 deps(skills): sync superpowers 4b23529 🔧 chore(ci): merge superpowers update and sync workflow a56d75b 📦 deps(skills): sync superpowers 84bcefa 🔧 chore(ci): use ci[bot] commit author name 00a07e5 📦 deps(skills): sync superpowers 7b84daf 🐛 fix(templates): enforce main loop progress tracking 51373d7 🔧 chore(ci): automate superpowers sync workflow eaaa39c 🐛 fix(ci): prevent stale superpowers sync from restoring skills block 79755c6 📦 deps(skills): sync superpowers 836d878 📦 deps(skills): sync superpowers 8216c9f 📦 deps(skills): sync superpowers 9439505 🐛 fix(playbook): address reported repo issues git-subtree-dir: docs/standards/playbook git-subtree-split: 25d895d8b3f56624ccfe99ad7289e9eb49e0f316
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
# Runtime Context And With
|
||||
|
||||
文档类型:语法主线
|
||||
是否可直接用于生成代码:仅部分
|
||||
是否含已验证可执行示例:是
|
||||
是否含已验证反例:是
|
||||
遇到不确定时跳转到:[07_expressions_and_operators.md](07_expressions_and_operators.md)、[22_namespace_libpath_and_unit_runtime.md](22_namespace_libpath_and_unit_runtime.md)、[../finance/market_data_context.md](../finance/market_data_context.md)
|
||||
|
||||
手册位置:第 11 篇,共 32 篇。上一篇:[10_units_and_scope.md](10_units_and_scope.md)。下一篇:[12_pitfalls.md](12_pitfalls.md)。
|
||||
|
||||
这一篇只处理运行时环境参数和 `with` 后缀,不处理任何金融业务语义。
|
||||
|
||||
## 这一篇解决什么问题
|
||||
|
||||
回答“`SetSysParam` / `GetSysParam` 怎样用、`SysParams[...]` 是什么、`#Func() with array(...)` 这种后缀环境调用在当前解释器里怎样写”。
|
||||
|
||||
## 必须记住的规则
|
||||
|
||||
- TSL 有一组运行时系统参数;当前页只写已经实际验证过的通用写法。
|
||||
- 已验证:`SetSysParam(key, value)` 和 `GetSysParam(key)` 可以直接用字符串键。
|
||||
- 已验证:`SysParams[key]` 可以直接读写这些运行时参数。
|
||||
- 当前已验证的 `with` 形式,是写在函数文件调用后面:`#Func() with array(...)`。
|
||||
- 当前已做双文件运行验证:`with array(...)` 只在该次调用里临时覆盖对应键,调用结束后会恢复外部原值。
|
||||
- 当前已做双文件运行验证:如果外部原值本来不存在,`with array(...)` 调用结束后,对应键会恢复成 `nil`。
|
||||
- 不要把上面的后缀 `with` 直接泛化成“任何本地函数调用后面都能接 `with array(...)`”;这一点当前没有通过。
|
||||
- 当前页只收通用键的例子;像 `pn_stock()`、`pn_date()` 这类金融上下文参数,统一放到业务层文档里解释。
|
||||
|
||||
## 已验证语法
|
||||
|
||||
直接设置和读取系统参数:
|
||||
|
||||
代码块身份:已验证可执行示例
|
||||
|
||||
```tsl
|
||||
program test;
|
||||
begin
|
||||
SetSysParam("a", 123);
|
||||
SetSysParam("b", "XYZ");
|
||||
WriteLn(GetSysParam("a"));
|
||||
WriteLn(GetSysParam("b"));
|
||||
end.
|
||||
```
|
||||
|
||||
已验证运行结果:
|
||||
|
||||
- 依次输出 `123`、`XYZ`
|
||||
|
||||
`SysParams[...]` 直接读写:
|
||||
|
||||
代码块身份:已验证可执行示例
|
||||
|
||||
```tsl
|
||||
program test;
|
||||
begin
|
||||
SysParams["a"] := 321;
|
||||
SysParams["b"] := "QQ";
|
||||
WriteLn(SysParams["a"]);
|
||||
WriteLn(SysParams["b"]);
|
||||
WriteLn(GetSysParam("a"));
|
||||
end.
|
||||
```
|
||||
|
||||
已验证运行结果:
|
||||
|
||||
- 依次输出 `321`、`QQ`、`321`
|
||||
- 说明 `SysParams[...]` 和 `GetSysParam(...)` / `SetSysParam(...)` 指向的是同一组运行时环境参数
|
||||
|
||||
沿用同一个 `TestDo.tsf`,看 `with array(...)` 的覆盖边界:
|
||||
|
||||
代码块身份:配置片段 / 概念骨架
|
||||
|
||||
```text
|
||||
// TestDo.tsf
|
||||
function TestDo();
|
||||
begin
|
||||
return array(GetSysParam("a"), GetSysParam("b"));
|
||||
end;
|
||||
|
||||
// main.tsl
|
||||
program test;
|
||||
begin
|
||||
SetSysParam("a", 7);
|
||||
SetSysParam("b", 8);
|
||||
r := #TestDo() with array("a": 101, "b": 202);
|
||||
WriteLn(r[0]);
|
||||
WriteLn(r[1]);
|
||||
WriteLn(GetSysParam("a"));
|
||||
WriteLn(GetSysParam("b"));
|
||||
end.
|
||||
|
||||
// command
|
||||
tsl .\main.tsl -LIBPATH "D:\path\to\dir\"
|
||||
```
|
||||
|
||||
已验证运行结果:
|
||||
|
||||
- `r[0]` 输出 `101`
|
||||
- `r[1]` 输出 `202`
|
||||
- 调用结束后,外层 `GetSysParam("a")` 输出 `7`
|
||||
- 调用结束后,外层 `GetSysParam("b")` 输出 `8`
|
||||
- 说明 `with array(...)` 是“只在该次调用里临时覆盖,再恢复外部原值”
|
||||
|
||||
沿用上一个 `TestDo.tsf`,只把 `main.tsl` 改成下面这样:
|
||||
|
||||
代码块身份:配置片段 / 概念骨架
|
||||
|
||||
```text
|
||||
// main.tsl
|
||||
program test;
|
||||
begin
|
||||
r := #TestDo() with array("a": 101, "b": 202);
|
||||
WriteLn(r[0]);
|
||||
WriteLn(r[1]);
|
||||
WriteLn(GetSysParam("a") = nil);
|
||||
WriteLn(GetSysParam("b") = nil);
|
||||
end.
|
||||
```
|
||||
|
||||
已验证运行结果:
|
||||
|
||||
- 依次输出 `101`、`202`、`1`、`1`
|
||||
- 说明外层原值不存在时,调用后不是“泄露”成 `101` / `202`,而是恢复成 `nil`
|
||||
|
||||
## 最小可编译示例
|
||||
|
||||
如果你只是想先记住最小的运行时环境入口,用这个:
|
||||
|
||||
代码块身份:已验证可执行示例
|
||||
|
||||
```tsl
|
||||
program test;
|
||||
begin
|
||||
SetSysParam("a", 1);
|
||||
WriteLn(GetSysParam("a"));
|
||||
end.
|
||||
```
|
||||
|
||||
## 常见误写
|
||||
|
||||
- 把系统参数页直接写成金融函数页。
|
||||
- 把 `#Func() with array(...)` 误判成也能直接套在本地函数 `Demo()` 后面。
|
||||
- 以为 `with array(...)` 改的是全局永久值,不会恢复外层原环境。
|
||||
|
||||
代码块身份:反例 / 不可照写
|
||||
|
||||
```text
|
||||
program test;
|
||||
function Demo();
|
||||
begin
|
||||
return GetSysParam("a");
|
||||
end;
|
||||
begin
|
||||
r := Demo() with array("a": 11);
|
||||
end.
|
||||
```
|
||||
|
||||
上面这种“本地函数后缀 `with`”写法在当前解释器里没有通过,会报 `Statement missing terminator`,随后出现 `function compile error`。
|
||||
|
||||
## 跳转指引
|
||||
|
||||
- 回看表达式与调用:见 [07_expressions_and_operators.md](07_expressions_and_operators.md)
|
||||
- 涉及函数文件查找路径:见 [22_namespace_libpath_and_unit_runtime.md](22_namespace_libpath_and_unit_runtime.md)
|
||||
- 业务层环境参数:见 [../finance/index.md](../finance/index.md)
|
||||
Reference in New Issue
Block a user