Chiba Logo CHIBA v0.6.13
CHIBA blog RSS feed
CHIBA / DOCS / LEVEL-1 SPEC

Pipe `|>`

这里集中展示 CHIBA level-1 specification,覆盖 core language、control flow、memory、patterns、IR lowering 与 package system 等实现边界。

The docs surface keeps CHIBA level-1 specification pages browsable inside the site, with direct paths into language, control flow, memory, pattern, and lowering rules.

Pipe |>

语法

|> 表示把左侧表达式流入右侧调用或可调用体。

语义

它是表面语法糖,不应引入新的求值模型。

|> 支持 _ 作为右侧单一占位孔位。

也就是说:

  • 若右侧不出现 _,则 lhs |> rhs 按“把 lhs 作为右侧默认输入” desugar
  • 若右侧出现单个 _,则把 lhs 填入该位置

例如:

value |> f(_, y)

可理解为:

f(value, y)

当前方向下,pipe 中的 _ 只作为占位孔位使用,不是 wildcard pattern,也不应允许多个 _ 同时出现。

level-1 同时支持“默认插入第一个参数”和“单个 _ 孔位”两种风格。

level-1 当前方向把 |> 置于倒数第三弱优先级。

也就是说:

  • |> 弱于普通算术、比较、逻辑、call、field access、index 等表达式构造
  • |> 强于 :=
  • |> 也强于最外层的 = 绑定/定义语法

= 不作为普通 operator 进入表达式优先级表。

|> 是显式续接运算符。

因此,若一行以 |> 结束,则下一行继续视为同一表达式的一部分,而不是新的 statement。

例如:

value |>
	step1() |>
	step2()

应解析为单个 pipe expression。

边界

_ 在 pipe 中只允许出现一次。