Hatena::Groupcadr

わだばLisperになる このページをアンテナに追加 RSSフィード

2004 | 12 |
2005 | 01 | 02 | 07 | 10 | 11 |
2006 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2007 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2008 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2009 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2010 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2011 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 11 |

2010-01-09

KMRCLを眺める (62) READ-FILE-TO-STRINGS

| 12:40 | KMRCLを眺める (62) READ-FILE-TO-STRINGS - わだばLisperになる を含むブックマーク はてなブックマーク - KMRCLを眺める (62) READ-FILE-TO-STRINGS - わだばLisperになる

今回はKMRCLのio.lisp中からREAD-FILE-TO-STRINGSです。

前回のREAD-STREAM-TO-STRINGSをWITH-OPEN-FILEで包んだものです。

定義は、

(defun read-file-to-strings (file)
  "Opens a reads a file. Returns the contents as a list of strings"
  (with-open-file (in file :direction :input)
    (read-stream-to-strings in)))

となっています。

使用例は、

(DEFVAR *WORDS*
  (READ-FILE-TO-STRINGS "/usr/share/dict/words"))

(LENGTH *WORDS*)
;⇒ 98569

(FILTER (LAMBDA (LINE)
          (UNLESS (EQUAL "" LINE)
            (CHAR= #\Z (CHAR LINE 0))))
        *WORDS*)
⇒ ("Z" "Z's" "Zachariah" "Zachariah's" "Zachary" "Zachary's" "Zachery"
 "Zachery's" "Zagreb" "Zagreb's" "Zaire" "Zaire's" "Zairian" "Zairians"
 "Zambezi" "Zambezi's" "Zambia" "Zambia's" "Zambian" "Zambians" "Zamboni"
 "Zamenhof" "Zamenhof's" "Zamora" "Zamora's" "Zane" "Zane's" "Zanuck"
 "Zanuck's" "Zanzibar" "Zanzibar's" "Zapata" "Zapata's" "Zaporozhye"
 "Zaporozhye's" "Zapotec" "Zapotec's" "Zappa" "Zappa's" "Zebedee" "Zebedee's"
 "Zechariah" "Zechariah's" "Zedekiah" "Zedekiah's" "Zedong" "Zedong's"
 "Zeffirelli" "Zeffirelli's" "Zeke" "Zeke's" "Zelig" "Zelig's" "Zelma"
 "Zelma's" "Zen" "Zen's" "Zenger" "Zenger's" "Zeno" "Zeno's" "Zens" "Zephaniah"
 "Zephaniah's" "Zephyrus" "Zephyrus's" "Zeppelin" "Zeppelin's" "Zest" "Zest's"
 "Zeus" "Zeus's" "Zhengzhou" "Zhivago" "Zhivago's" "Zhukov" "Zhukov's" "Zibo"
 "Zibo's" "Ziegfeld" "Ziegfeld's" "Ziegler" "Ziegler's" "Ziggy" "Ziggy's"
 "Zimbabwe" "Zimbabwe's" "Zimbabwean" "Zimbabweans" "Zimmerman" "Zimmerman's"
 "Zinfandel" "Zinfandel's" "Zion" "Zion's" "Zionism" "Zionism's" "Zionisms"
 "Zionist" "Zionist's" "Zionists" "Zions" "Ziploc" "Zn" "Zn's" "Zoe" "Zoe's"
 "Zola" "Zola's" "Zollverein" "Zollverein's" "Zoloft" "Zomba" "Zomba's" "Zorn"
 "Zorn's" "Zoroaster" "Zoroaster's" "Zoroastrian" "Zoroastrianism"
 "Zoroastrianism's" "Zoroastrianisms" "Zorro" "Zorro's" "Zosma" "Zosma's" "Zr"
 "Zr's" "Zsigmondy" "Zsigmondy's" "Zubenelgenubi" "Zubenelgenubi's"
 "Zubeneschamali" "Zubeneschamali's" "Zukor" "Zukor's" "Zulu" "Zulu's" "Zulus"
 "Zuni" "Zwingli" "Zwingli's" "Zworykin" "Zworykin's" "Zyrtec" "Zyrtec's"
 "Zyuganov" "Zyuganov's" "Zürich" "Zürich's")

位のところでしょうか

ファイルをオープンして行ごとに処理していくのも良いとは思いますが、LIST処理言語LISPとしては、一旦リストにしてしまうと色々素材の料理が楽ですね。