Agent first
@Document 描述声明意图,用受检查的引用连接相关 API。编译器提供签名与类型,测试关联来自 @Test。
import std.annotation.Document
import std.testing.Test
@Document(description: "A task visible to the user.")
value Task {
String title
}
@Document(description: "Formats a task title for a summary.")
String describe(Task task) {
return "Task: " + task.title
}
@Test(functions: [describe.function])
Void describesTask() {
require(
condition: describe(Task(title: "Learn Norm")) == "Task: Learn Norm",
message: "task summary"
)
}
@Document(
description: "Entry point for agents exploring task summaries.",
types: [Task.class],
functions: [describe.function]
)
class TaskApi {}
main() {
printLine(describe(Task(title: "Learn Norm")))
}
norm query agent_document.norm describe --source --references --testsnorm query agent_document.norm TaskApi --sourcenorm refactor name agent_document.norm describe --to summarize --previewnorm check agent_document.norm --format jsonnorm test agent_document.norm --format json查询结果节选describe.documentation: Formats a task title for a summary.
describe.references: 4
describe.tests: 1
TaskApi.documentation: Entry point for agents exploring task summaries.
程序输出Task: Learn Norm
这里的语义查询和重构需要开发版工具链。Agent 在验证前应用预览中的编辑。
了解 Agent 工具 →Application development
每个示例都是可独立运行的完整文件,旁边展示经过验收的结果。选择想了解的问题。
把身份、值、有限状态、命名调用和表达式结果组合在一起。
interface Labeled {
String label()
}
value TaskId {
Integer number
}
enum State {
Ready,
Doing(Integer percent),
Done
}
class Task implements Labeled {
TaskId id
String title
State state
String label() {
String progress = switch state {
case Ready { break "ready" }
case Doing(Integer percent) { break "${percent}%" }
case Done { break "done" }
}
if state == State.Done { "${title} ✓" } else { "${title}: ${progress}" }
}
}
Task newTask(String title, Integer number, State state = State.Ready) {
Task(id: TaskId(number: number), title: title, state: state)
}
main() {
Task task = newTask(title: "Learn Norm", number: 7)
Task same = task
printLine(task.label())
same.state = State.Doing(percent: 50)
printLine(task.label())
same.state = State.Done
printLine(task.label())
}
运行 norm application_data.norm
验收输出Learn Norm: ready
Learn Norm: 50%
Learn Norm ✓
这些示例需要开发版工具链。
继续了解语言特性 →每节教学都有可执行示例,并由编译器持续验收。