unreal-verse

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Unreal Verse

Unreal Verse

Overview

概述

Use Epic documentation as the source of truth for Verse syntax and behavior. Route each task to the right doc first, then implement with minimal, valid patterns.
以Epic官方文档作为Verse语法和行为的权威来源。 先将每个任务导向对应的文档章节,再用最简、合法的模式实现。

Workflow

工作流程

  1. Classify the task.
  2. Open the matching section in
    references/verse-doc-index.md
    .
  3. Draft the smallest valid Verse solution first.
  4. Verify effects (
    <suspends>
    ,
    <transacts>
    ,
    <decides>
    ), failure contexts, and container access.
  5. Return code plus a short rationale tied to the referenced docs.
  1. 对任务进行分类。
  2. 打开
    references/verse-doc-index.md
    中对应的章节。
  3. 先编写最简的合法Verse解决方案草稿。
  4. 验证效果(
    <suspends>
    <transacts>
    <decides>
    )、失败上下文和容器访问。
  5. 返回代码,并附上与参考文档相关的简短说明。

Minimal Common Patterns

常用最简模式

Use these as copy-start snippets, then adapt names and imports to the target project.
可将这些作为代码片段模板,再根据目标项目调整名称和导入内容。

Class With Mutable State

带可变状态的类

verse
counter := class:
    var total:int = 0

    Add(value:int):void =
        set total += value
verse
counter := class:
    var total:int = 0

    Add(value:int):void =
        set total += value

Failable Lookup (Option/Failure Context)

可能失败的查找(Option/失败上下文)

verse
if (first := numbers[0]):
    Print("{first}")
verse
if (first := numbers[0]):
    Print("{first}")

Map Insert + Read

映射插入与读取

verse
scores:[string]int = map{}
set scores["alice"] = 10

if (score := scores["alice"]):
    Print("{score}")
verse
scores:[string]int = map{}
set scores["alice"] = 10

if (score := scores["alice"]):
    Print("{score}")

Basic Loop

基础循环

verse
for (n := 0..2):
    Print("{n}")
verse
for (n := 0..2):
    Print("{n}")

Suspending Function

挂起函数

verse
DoLater()<suspends>:void =
    Sleep(1.0)
verse
DoLater()<suspends>:void =
    Sleep(1.0)

Race Two Tasks

任务竞态

verse
winner := race:
    TaskA()
    TaskB()
verse
winner := race:
    TaskA()
    TaskB()

Execution Rules

执行规则

  • Prefer explicit parameter and return types.
  • Keep functions small and compose behavior from small helpers.
  • Treat indexing and map reads as failable operations.
  • Use specifiers/attributes only when needed and verify exact syntax in docs.
  • Use
    race
    ,
    sync
    , and
    branch
    deliberately; always reason about cancellation and lifetime.
  • Check language-version notes before using newer syntax in older projects.
  • 优先使用显式的参数和返回类型。
  • 保持函数短小,通过小型辅助函数组合实现功能。
  • 将索引和映射读取视为可能失败的操作。
  • 仅在必要时使用说明符/属性,并在文档中验证确切语法。
  • 谨慎使用
    race
    sync
    branch
    ;始终考虑取消操作和生命周期问题。
  • 在旧项目中使用新语法前,查看语言版本说明。

Output Expectations

输出要求

  • Produce code that compiles conceptually against current Verse docs.
  • Cite the specific Epic page used for non-trivial constructs.
  • Keep examples minimal unless the user asks for full architecture.
  • 生成的代码需符合当前Verse文档的编译规范。
  • 对于非基础的语法结构,需引用对应的Epic官方页面。
  • 示例代码保持最简,除非用户要求完整架构。