首页 > 解决方案 > 对象:目录错误:不理解#name

问题描述

以下列出目录中文件的简单代码来自这里

(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版。

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

标签: directorysmalltalkgnu-smalltalk

解决方案


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

working: dirName
    Change the current working directory to dirName.

您的代码将如下所示:

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

推荐阅读