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

在Gforth的random.fs中使用shuffle词遇未定义词错误求助

Gforth random.fs未定义词错误及cell相关疑问

问题描述

我尝试使用以下shuffle代码:

: random-range ( n -- r )
  dup 1- random mod
;

: shuffle ( array len -- )
    1- 0 do
        i random-range swap rot over !
    loop ;

但Gforth抛出错误:

~/gforth/random.fs:34: Undefined word
    user rng-state $10 >>>cell<<< uallot drop
Backtrace:
$107349A20 throw 
$10735FCC0 no.extensions 
$107349CE0 interpreter-notfound1

错误出现在我使用的random.fs扩展第34行。cell在Gforth的词索引里有定义,但我搞不懂为什么会报错。

补充信息

执行see cell得到以下输出:

see cell 
8 Constant cell  
 ok

请问这个输出是否正常?

解答

  1. 错误根源:报错里的>>>cell<<<并非Gforth标准语法,你使用的random.fs代码包含非标准语法扩展,Gforth默认无法识别。
  2. cell定义正常:see cell输出8 Constant cell完全没问题,这表示你的64位Gforth环境中,单元格大小被正确定义为8字节。
  3. 解决方法:将random.fs里的>>>cell<<<替换为标准Gforth词cells即可——cells的作用就是将数值转换为对应单元格的字节数,比如$10 cells等价于原代码想要实现的功能。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 03:27:11