惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
量子位
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
IT之家
IT之家
V
Visual Studio Blog
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
D
Docker
V
V2EX

暗无天日

读:AI Agent 安全日志——从可见性与隐私的两难说起 - 暗无天日 AI写作的语言指纹——如何让文字不那么像机器 - 暗无天日 读:50 条 Claude Code 技巧——一个工程经理的六个月使用心得 读:AI 辅助开发为什么让 E2E 测试更有价值 - 暗无天日 读:在Emacs中使用Claude Code(Spacemacs适配版) - 暗无天日 Claude Code 背后的工程哲学——读 Agent Harness Engineering 读:Agent Harness Engineering——AI 智能体不只是模型,还有套件 - 暗无天日 browser-harness:让 AI 直接接管你的浏览器 - 暗无天日 读:Security-First CI/CD —— DevSecOps 自动化实践指南 TIL: 数字小键盘的小数点陷阱与行内算术求值 - 暗无天日 读:Immutability 不是万能药,它是一种权衡 - 暗无天日 Conducty:给 Claude Code 加上项目记忆和并行执行能力 - 暗无天日 读 — GitHub Trending 里的 Claude Code 技能包 读 — Prompt Caching 省钱指南 TIL: Emacs 中那些跟鼠标配合的冷门快捷键 - 暗无天日 读:Anvil——把 Emacs 变成 AI 的工具服务器 读:Emacs 代码折叠终极指南 - 暗无天日 读:Clojure 搭车客指南 - 暗无天日 git推送失败后恢复仓库损坏的完整记录 - 暗无天日 多智能体系统的两个有效模式——以及对 Claude Code 用户的启示 - 暗无天日 用 Org Babel 写 Literate 博文:扩展执行 + 定制导出 proced:Emacs 内置的进程查看器 - 暗无天日 从 proced 定制中学到的 Elisp 模式 读:让 Emacs proced 在 macOS 上显示 CPU 和内存 异步编程的函数着色税 - 暗无天日 链式调用的代价:JavaScript 和 Clojure 的共同教训 - 暗无天日 hyperfine:命令行基准测试工具 - 暗无天日 管道中的变量去哪了?——子 shell 作用域陷阱 - 暗无天日 开源包装器的信任陷阱:四个危险信号 - 暗无天日 程序员愿意为 AI 写文档,却不愿为同事写 - 暗无天日
读:把 JSON 当编程语言执行——一个迷你解释器的构造过程 - 暗...
lujun9972, Claude Code · 2026-05-25 · via 暗无天日

把以上组件拼起来,用测试案例覆盖解释器的全部运算单元。

四则混合运算: 一个嵌套表达式覆盖加、减、乘、除四种运算,相当于 =(1+2)*3 - 4/2 = 7=。

console.log("(1+2)*3 - 4/2 =", interpreter([{ type: 'sub', args: [
  { type: 'mul', args: [{ type: 'add', args: [1, 2] }, 3] },
  { type: 'div', args: [4, 2] }
]}], {}));
(1+2)*3 - 4/2 = 7

比较和逻辑运算: 小于/大于按序检查,=and= 短路到 null=,=or 短路到非 null=,=not 互换真假。

console.log("1<2<3 =", interpreter([{ type: 'lt', args: [1, 2, 3] }], {}));
console.log("1<3<2 =", interpreter([{ type: 'lt', args: [1, 3, 2] }], {}));
console.log("3>2>1 =", interpreter([{ type: 'gt', args: [3, 2, 1] }], {}));

console.log("and(1,2,3) =", interpreter([{ type: 'and', args: [1, 2, 3] }], {}));
console.log("and(1,null,3) =", interpreter([{ type: 'and', args: [1, null, 3] }], {}));
console.log("or(null,null,42) =", interpreter([{ type: 'or', args: [null, null, 42] }], {}));
console.log("not(null) =", interpreter([{ type: 'not', args: [null] }], {}));
console.log("not(1) =", interpreter([{ type: 'not', args: [1] }], {}));
1<2<3 = true
1<3<2 = null
3>2>1 = true
and(1,2,3) = 3
and(1,null,3) = null
or(null,null,42) = 42
not(null) = true
not(1) = null

条件表达式: null 为假走 else=,非 =null 为真走 =then=。

console.log("if(null) =", interpreter([
  { type: 'if', cond: null,
    then: [{ type: 'str', value: 'yes' }],
    else: [{ type: 'str', value: 'no' }] }
], {}));
console.log("if(gt(42,0)) =", interpreter([
  { type: 'if', cond: { type: 'gt', args: [42, 0] },
    then: [{ type: 'str', value: 'positive' }],
    else: [{ type: 'str', value: 'non-positive' }] }
], {}));
if(null) = no
if(gt(42,0)) = positive

变量 + 循环:while 累加求和 =1+2+...+5=。

let sumExample = [
  { type: 'num', name: 'i', value: 0 },
  { type: 'num', name: 'n', value: 5 },
  { type: 'num', name: 'sum', value: 0 },
  { type: 'while',
    cond: { type: 'lt', args: [{ type: 'var', name: 'i' }, { type: 'var', name: 'n' }] },
    body: [
      { type: 'num', name: 'i', value: { type: 'add', args: [{ type: 'var', name: 'i' }, 1] } },
      { type: 'num', name: 'sum', value: { type: 'add', args: [{ type: 'var', name: 'sum' }, { type: 'var', name: 'i' }] } },
    ]
  },
  { type: 'var', name: 'sum' }
];
console.log("1+2+...+5 =", interpreter(sumExample, {}));
1+2+...+5 = 15

函数 + 闭包: 定义一个阶乘函数 fact(5)=,内部用 =while 循环。

let factExample = [
  { type: 'fn', name: 'fact',
    value: { args: ['n'],
             body: [
               { type: 'num', name: 'result', value: 1 },
               { type: 'while',
                 cond: { type: 'gt', args: [{ type: 'var', name: 'n' }, 0] },
                 body: [
                   { type: 'num', name: 'result',
                     value: { type: 'mul', args: [{ type: 'var', name: 'result' }, { type: 'var', name: 'n' }] } },
                   { type: 'num', name: 'n',
                     value: { type: 'sub', args: [{ type: 'var', name: 'n' }, 1] } },
                 ]
               },
               { type: 'var', name: 'result' }
             ]
           }
  },
  { type: 'call', name: 'fact', args: [5] },
];
console.log("fact(5) =", interpreter(factExample, {}));
fact(5) = 120

字符串 + 数组: 字符串变量和数组变量都能正确定义和引用。

console.log(interpreter([
  { type: 'str', name: 'msg', value: 'Hello World!' },
  { type: 'fn', name: 'greet', value: { args: [], body: [{ type: 'var', name: 'msg' }] } },
  { type: 'call', name: 'greet', args: [] },
], {}));
console.log(interpreter([
  { type: 'vec', name: 'xs', value: [1, 2, 3] },
  { type: 'var', name: 'xs' }
], {}));
Hello World!
[ 1, 2, 3 ]