Skip to content

append函数的问题 #619

@da-liii

Description

@da-liii

问题根源

这是 Goldfish Scheme 的 append 函数实现有 bug,当使用 append 构建长列表时(约 500+ 个元素),列表结构会损坏变成 dotted pair。

复现代码

(let loop ((entries (map (lambda (i) (cons (number->string i) (list "lib"))) (iota 1000)))
(visible '()))
(if (null? entries)
visible
(let* ((entry (car entries))
(function-name (car entry)))
(loop (cdr entries)
(if (not (member function-name visible))
(append visible (list function-name)) ; 这里会失败
visible)))))

错误信息

;append first argument, ("0" "1" "2" ...), is a pair but should be a proper list

影响

  1. gf doc "string-spli" 模糊匹配功能无法使用
  2. 任何使用 append 循环构建长列表的代码都会失败
  3. visible-function-names 函数在函数数量超过阈值时崩溃

需要修复的地方

Goldfish Scheme 的底层 append 实现(可能在 s7.c 或 base.scm 中)需要修复。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions