You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Racket中使用#lang scheme定义函数报错set-cdr!未绑定标识符

解决Racket中set-cdr!未绑定标识符错误

出错代码

#lang scheme

(define (queue! q x)
  (let ( (b (list x))
       )
    (if (null? (car q))
        (set-cdr! q b)
        (set-cdr! (car q) b))
    (set-car! q b)))

报错信息

set-cdr!: unbound identifier in: set-cdr!

IDE会高亮第一个(set-cdr! q b)语句。

问题原因

  • Racket中#lang scheme无法提供R5RS/R6RS/R7RS标准环境,导致set-cdr!这类标准Scheme过程无法被识别。
  • #lang scheme是旧版PLT Scheme(2010年6月更名为Racket)的遗留写法,且PLT Scheme与R5RS标准存在差异,其正确声明应为#lang PLTscheme,但不推荐继续使用该旧版环境。

修复方案

将代码开头的语言声明替换为#lang r5rs,即可兼容R5RS标准的代码示例(如Scheme Cookbook中的旧代码),修复后的代码如下:

#lang r5rs

(define (queue! q x)
  (let ( (b (list x))
       )
    (if (null? (car q))
        (set-cdr! q b)
        (set-cdr! (car q) b))
    (set-car! q b)))

内容的提问来源于stack exchange,提问作者Scooter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 17:27:35