如何遍历Common Lisp中的目录? [英] How do I iterate through a directory in Common Lisp?

查看:128
本文介绍了如何遍历Common Lisp中的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在达尔文(Darwin)上使用OpenMCL,我想这样做:

I'm using OpenMCL on Darwin, and I'd like to do something like:

(loop for f in (directory "somedir")
  collect (some-per-file-processing f))

但是我无法获得目录返回除 NIL 以外的任何内容,而且我似乎找不到任何内容很好的在线说明(每个系统不同)。

But I can't get directory to return anything other than NIL, and I can't seem to find any good explanation online (other than "its different for each system").

任何指针吗?

推荐答案

您的路径名规范是否包含通配符?起初,Common Lisp的路径名东西有些难以理解-至少对我来说是...... CLHS 目录函数上的状态:

Does your pathname specification contain a wildcard? Common Lisp's pathname stuff is somewhat hard to grasp at first - at least for me it was... As the CLHS states on the directory function:


如果pathspec不为空,则
结果列表将包含
零或一个元素。

If the pathspec is not wild, the resulting list will contain either zero or one elements.

要让您的路径名包含通配符,您可以尝试使用make-pathname函数,例如

In order to have your pathname include a wildcard, you might try the make-pathname function, like

(directory (make-pathname :directory '(:absolute "srv" "hunchentoot") :name :wild :type "lisp"))

甚至

(directory (make-pathname :directory '(:absolute "srv" "hunchentoot") :name :wild :type :wild))

我发现 CL-FAD 库对于处理路径名和文件系统有很大的帮助米特别是其 列表目录 函数可能比普通的标准目录函数更易于使用。

I found the CL-FAD library a great help for dealing with pathnames and the file system. In particular, its list-directory function might be easier to use than the plain standard directory function.

这篇关于如何遍历Common Lisp中的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆