lispでlsを実装その1(directory関数)
Lispでlsを実装してみる。もっとも、すべてのオプションを網羅することはできず、単純にファイル名やディレクトリ名の一覧を取得できるだけのものを目指す。
とりあえず、実現にはdirectory関数が必須な感じだ。以下のようにしてみた。
(defun ls (pattern) (dolist (filelist (directory pattern)) (format t "~A~%" filelist)))
実行結果は以下のような感じ。
? (ls "/etc/*.*") /etc/6to4.conf /etc/afpovertcp.cfg /etc/aliases.db /etc/amavisd\.conf.default /etc/asl.conf /etc/authorization /etc/auto_home /etc/auto_master /etc/autofs.conf /etc/bashrc /etc/bind.keys /etc/com\.apple\.screensharing\.agent.launchd /etc/csh.cshrc /etc/csh.login /etc/csh.logout /etc/daily\.local.cagclient /etc/dnsextd.conf /etc/efax.rc /etc/find.codes /etc/fstab.hd /etc/ftpd.conf /etc/ftpd\.conf.default /etc/ftpusers /etc/gdb.conf /etc/gettytab /etc/group /etc/hostconfig /etc/hosts /etc/hosts.equiv /etc/irbrc /etc/kern_loader.conf /etc/krb5.keytab /etc/krb5.keytab~orig /etc/locate.rc /etc/mail.rc /etc/man.conf /etc/manpaths /etc/master.passwd /etc/memberd.conf /etc/moduli /etc/named.conf /etc/nanorc /etc/networks /etc/newsyslog.conf /etc/notify.conf /etc/ntp-restrict.conf /etc/ntp.conf /etc/ntp.conf~orig /etc/passwd /etc/paths /etc/pf.conf /etc/pf.os /etc/php\.ini.default /etc/profile /etc/protocols /etc/rc.common /etc/rc.imaging /etc/rc.netboot /etc/rmtab /etc/rpc /etc/rtadvd.conf /etc/services /etc/shells /etc/ssh_config /etc/sshd_config /etc/sudoers /etc/syslog.conf /etc/ttys /etc/xtab /etc/zshenv /private/etc/postfix/aliases /private/var/run/resolv.conf /usr/share/zoneinfo/Asia/Tokyo NIL ? (ls "/etc") /private/etc/ NIL ?
うーむ・・・ディレクトリとファイルを同時に取得させるのは無理か・・・
もう少し改善が必要なようだ。単純に2つの結果をappendすればいいかもしれないが。