← 都来码 / Dolaima← 例程索引swift/school/MANIFEST.md 原文

swift/school/MANIFEST.md · 4313 字节 · 下载原文

# 外部老程序语料 —— Swift

口径见 `../README.md`。**判据只有一条:`vmlcli --lang swift` 编不编得过**(跑起来崩不崩不算)。

- **来源**:均为 [Rosetta Code](https://rosettacode.org) 各任务的 **Swift** 实现(仓库明确认可的来源之一)。
- **许可**:Rosetta Code 站点内容为 **CC BY-SA 4.0**(部分旧页面曾为 GFDL);逐条未再细分,统一按 CC BY-SA 4.0 记。
- **三条口径**:`python3 scripts/compat-external-lint.py --dir .` → **10 个文件全部 ✅**(无汇编 / 无硬件地址操作 / 无界面库)。
- **编译复现**:`bash scripts/vml-compat-external.sh swift` → **通过 4 / 失败 6**。

| 文件名 | 类别 | 来源 URL | 许可 | 行数 | 编译 | 第一条错误(原文) |
|---|---|---|---|---|---|---|
| sieve_of_eratosthenes.swift | 数值/算术 | https://rosettacode.org/wiki/Sieve_of_Eratosthenes#Swift | CC BY-SA 4.0 | 25 | ❌ | `sieve_of_eratosthenes.swift:9:8: error: 未声明的变量 'isprime' [CodeGen_UndefinedVariable]` |
| even_or_odd.swift | 数值/算术 | https://rosettacode.org/wiki/Even_or_odd#Swift | CC BY-SA 4.0 | 13 | ✅ | — |
| palindrome_detection.swift | 字符串/文本 | https://rosettacode.org/wiki/Palindrome_detection#Swift | CC BY-SA 4.0 | 19 | ❌ | `palindrome_detection.swift:16:52: error: 未声明的变量 'removeRange' [CodeGen_UndefinedVariable]` |
| reverse_a_string.swift | 字符串/文本 | https://rosettacode.org/wiki/Reverse_a_string#Swift | CC BY-SA 4.0 | 5 | ❌ | `error: 未定义的函数 'println'(引用 2 次)` |
| bubble_sort.swift | 数组/集合 | https://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort#Swift | CC BY-SA 4.0 | 17 | ❌ | `bubble_sort.swift:1:41: error: 期望 RightParen,实际得到 LeftBracket` |
| array_concatenation.swift | 数组/集合 | https://rosettacode.org/wiki/Array_concatenation#Swift | CC BY-SA 4.0 | 3 | ✅ | — |
| ackermann.swift | 递归/控制流 | https://rosettacode.org/wiki/Ackermann_function#Swift | CC BY-SA 4.0 | 9 | ✅ | — |
| towers_of_hanoi.swift | 递归/控制流 | https://rosettacode.org/wiki/Towers_of_Hanoi#Swift | CC BY-SA 4.0 | 9 | ❌ | `error: 未定义的函数 'println'(引用 1 次)` |
| 99_bottles.swift | 经典小游戏/模拟 | https://rosettacode.org/wiki/99_bottles_of_beer#Swift | CC BY-SA 4.0 | 5 | ✅ | — |
| game_of_life.swift | 经典小游戏/模拟 | https://rosettacode.org/wiki/Conway%27s_Game_of_Life#Swift | CC BY-SA 4.0 | 95 | ❌ | `game_of_life.swift:57:18: error: 未声明的变量 'iterations' [CodeGen_UndefinedVariable]` |

(行数按 `wc -l`,即文件实际行数,末尾带换行。)

## 失败原因分类(6 个失败文件)

- **`未声明的变量` [CodeGen_UndefinedVariable](3 个)** —— 这是**级联**症状:某条顶层 `let/var` 的
  **初始化式用了前端不支持的构造式**(泛型/数组/类型构造器),该声明**静默失败、变量没被登记**,
  之后每一处引用都报"未声明的变量"。实测最小复现:
  - `var a = [Bool](repeating: true, count: 5)` → `未声明的变量 'Bool'`(`[T](…)` 数组构造器不支持)。
  - `let removeRange = Range<String.Index>(start:…, end:…)`(palindrome)→ 泛型构造器不支持。
  - sieve 的起点是 `var isprime = [Bool](repeating: true, count: max+1)`,级联出 `'isprime'` / `'i'` / `'max'` 三串报错。
- **`未定义的函数 'println'`(2 个)** —— `println` 是 **Swift 1.x 的老式输出**(Swift 3 起改为 `print`);
  本前端只有 `print`。这正是"**老程序**"语料才会踩到的点(Rosetta Code 上不少 Swift 条目停留在 1.x 年代)。
- **语法解析失败(1 个)** —— bubble_sort 的 `func bubbleSort<T:Comparable>(list:inout[T])`:
  泛型函数声明 + `inout` + `[T]` 形参类型,解析器在 `inout[T]` 处报
  `期望 RightParen,实际得到 LeftBracket`(**泛型函数声明**整体不支持)。

## 备注

- `print("\(x)")` 字符串插值、`.reversed()`、`.description` 等**能编过**(99_bottles 全绿);
  只要不碰上泛型 / 构造器 / `println` 这类,普通循环 + 数组 + 函数的程序大多能过。
- 本目录**有意不进仓库**(许可参差,见 `../README.md`)。