なんだこれは

はてなダイアリーから移転しました。

perl の while(<>)みたいな

perl の while(<>)みたいなのは、 Common Lisp でどうやるんかなぁ。
こんな感じかな。

;;;
(defun cat-file ( file )
  "write each line of that file"
  (with-open-file (s file :direction :input)
    (loop for line = (read-line s nil s)
	 until (eq line s)
	 do (progn
	      (princ line)
	      (princ #\NewLine)))))
;;;
(defun cat-n-file (file)
  "write each lines of that file with number"
  (let ((number 0))
    (with-open-file (s file :direction :input)
      (loop for line = (read-line s nil s)
	   until (eq line s)
	   do (progn
		(princ number)
		(incf number)
		(princ #\Tab)
		(princ line)
		(princ #\NewLine))))))
;;;
(defun cut-n-file (file n &optional (sp #\Tab))
  "write n th column of each line of that file , those are splitted by sp regexp or tab character"
  (with-open-file (s file :direction :input)
    (loop for line = (read-line s nil s)
	 until (eq line s)
	 do (progn
	      (princ (nth n (ppcre:split sp line)))
	      (princ #\NewLine)))))