lisp 習題 用列表元素標識檔案一行。
定義一個函式,接受一個檔名並返回一個由字串組成的列表,來表示檔案裡的每一行
CL-USER> (defun pseudo-cat (file)
(with-open-file (str file :direction :input)
(let ((x nil))
(
do
((line (read-line str nil 'eof)
(read-line str nil 'eof)))
((eql line 'eof))
(push line x))x)))
STYLE-WARNING: redefining COMMON-LISP-USER::PSEUDO-CAT in DEFUN
PSEUDO-CAT
CL-USER> (pseudo-cat "COPYING")
(" "Public License instead of this License. But first, please read"
"the library. If this is what you want to do, use the GNU Lesser General"
"may consider it more useful to permit linking proprietary applications with"
"into proprietary programs. If your program is a subroutine library, you"
" The GNU General Public License does not permit incorporating your program"
轉化為表示式
CL-USER> (defun pseudo-cat (file)
(with-open-file (str file :direction :input)
(let ((x nil))
(
do
((line (read-line str nil 'eof)
(read-line str nil 'eof)))
((eql line 'eof))
(push (make-array 1 :initial-element line) x))
(reverse x))))
STYLE-WARNING: redefining COMMON-LISP-USER::PSEUDO-CAT in DEFUN
PSEUDO-CAT
CL-USER> (pseudo-cat "copying")
(#(" GNU GENERAL PUBLIC LICENSE")
#(" Version 3, 29 June 2007") #("")
#(" Copyright (C) 2007 Free Software Foundation, Inc. #(" Everyone is permitted to copy and distribute verbatim copies")
#(" of this license document, but changing it is not allowed.") #("")
#(" Preamble") #("")
#(" The GNU General Public License is a free, copyleft license for")
CL-USER> (defun pseudo-cat (file)
(with-open-file (str file :direction :input)
(let ((x nil))
(
do
((line (read-line str nil 'eof)
(read-line str nil 'eof)))
((eql line 'eof))
(push line x))x)))
STYLE-WARNING: redefining COMMON-LISP-USER::PSEUDO-CAT in DEFUN
PSEUDO-CAT
CL-USER> (pseudo-cat "COPYING")
(" "Public License instead of this License. But first, please read"
"the library. If this is what you want to do, use the GNU Lesser General"
"may consider it more useful to permit linking proprietary applications with"
"into proprietary programs. If your program is a subroutine library, you"
" The GNU General Public License does not permit incorporating your program"
轉化為表示式
CL-USER> (defun pseudo-cat (file)
(with-open-file (str file :direction :input)
(let ((x nil))
(
do
((line (read-line str nil 'eof)
(read-line str nil 'eof)))
((eql line 'eof))
(push (make-array 1 :initial-element line) x))
(reverse x))))
STYLE-WARNING: redefining COMMON-LISP-USER::PSEUDO-CAT in DEFUN
PSEUDO-CAT
CL-USER> (pseudo-cat "copying")
(#(" GNU GENERAL PUBLIC LICENSE")
#(" Version 3, 29 June 2007") #("")
#(" Copyright (C) 2007 Free Software Foundation, Inc. #(" Everyone is permitted to copy and distribute verbatim copies")
#(" of this license document, but changing it is not allowed.") #("")
#(" Preamble") #("")
#(" The GNU General Public License is a free, copyleft license for")
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-741265/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- lisp 習題 區分非遞減的列表Lisp
- lisp 習題 occurrencesLisp
- lisp 習題 post+Lisp
- lisp 習題 our-unionLisp
- HTML標記語法之列表元素HTML
- lisp 習題 矩陣旋轉Lisp矩陣
- 用DOS命令生成光碟檔案列表
- lisp 習題 錢幣換算問題Lisp
- Xcode 檔案後狀態標識XCode
- lisp 習題 (member '(a) '((a) (b))) 為什麼返回nilLisp
- 用white-space解決文章標題列表換行問題
- 把文字檔案一行一行讀出來
- 企業雲盤檔案服務標識修改
- JSP自定義標籤開發+TLD檔案元素詳解JS
- 快速建立檔案列表(轉)
- 獲取檔案列表 .net
- nginx學習(二):初識配置檔案Nginx
- Windows 快速統計檔案列表中檔案大小Windows
- 讀取檔案最後一行
- 關於標籤元素的重點知識
- 遞迴獲取檔案列表遞迴
- vi中跳到檔案的第一行和最後一行
- 檔案指標指標
- linux_取檔案唯一行_取檔案重複行Linux
- 8.13 標頭檔案剖析:標頭檔案路徑(下)
- 99-lisp lisp 的99個問題 P11-20Lisp
- 99-lisp lisp 的99個問題 P1-10Lisp
- locate標頭檔案和庫檔案
- 用定製標籤庫和配置檔案實現對JSP頁面元素的訪問控制 (轉)JS
- git列出跟蹤的檔案列表Git
- dirlisting目錄檔案列表索引索引
- 如何防止Apache顯示檔案列表Apache
- 教大家python讀取一行一行檔案內容的方法Python
- 學習android所需Java知識點列表AndroidJava
- .vue檔案中style標籤的幾個識別符號Vue符號
- C 標頭檔案
- C# 替換文字檔案中的某一行 (要求此檔案存在)C#
- Nifty File Lists for mac檔案列表建立工具Mac