Object: Directory error: did not understand #name

Object: Directory error: did not understand #name

以下用于列出目录中文件的简单代码来自 here

(Directory name: '.')  
allFilesMatching: '*.st' 
do: [ :f | (f name) displayNl ]

但是,它不起作用并出现以下错误:

$ gst mysrc.st
Object: Directory error: did not understand #name:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
Directory class(Object)>>doesNotUnderstand: #name: (SysExcept.st:1448)
UndefinedObject>>executeStatements (firstline.st:1)

我正在 Debian Stable Linux 上开发 GNU Smalltalk 3.2.5 版。

问题出在哪里,如何解决?

不知道谁在rosettacode上写的,但是#name:选择器不正确(在Directory中不存在class).如果你检查 Directory class 你不会在那里找到这样的选择器。相反,您会找到一个 #working: 选择器。选择器有一个描述:

working: dirName
    Change the current working directory to dirName.

您的代码将如下所示:

(Directory working: '.') allFilesMatching: '*.st' do: [ :f | 
   (f name) displayNl
]