我读一下,如果使用大体序列的 lo/cur,那么 la的顺序会如何造成外围效应。 我试图从记忆中填入3MB档案,以便处理。 我认为,这正发生在我身上。 但是,我不知道有办法解决这一问题。 我尝试 do,但我的方案似乎没有结束。 小型投入工作:
Small input (contents of file): AAABBBCCC Correct output: ((65 65) (65 66) (66 66) (67 67) (67 67))
法典:
(def file-path "/Users/me/Desktop/temp/bob.txt")
;(def file-path "/Users/me/Downloads/3MB_song.m4a")
(def group-by-twos
(fn [a-list]
(let [first-two (fn [a-list] (list (take 2 a-list)))
the-rest-after-two (fn [a-list] (rest (rest a-list)))
only-two-left? (fn [a-list] (if (= (count a-list) 2) true false))]
(loop [result () rest-of-list a-list]
(if (nil? rest-of-list)
result
(if (only-two-left? rest-of-list)
(concat result (list rest-of-list))
(recur (concat result (first-two rest-of-list))
(the-rest-after-two rest-of-list))))))))
(def get-the-file
(fn [file-name-and-path]
(let [the-file-pointer
(new java.io.RandomAccessFile (new java.io.File file-name-and-path) "r")
intermediate-array (byte-array (.length the-file-pointer))] ;reserve space for final length
(.readFully the-file-pointer intermediate-array)
(group-by-twos (seq intermediate-array)))))
(get-the-file file-path)
正如我前面说过的那样,当我把all放在一席之地时,它似乎还没有结束。 我怎样才能为大量档案开张,是否有办法消除我需要做的事情的认知负担? 一些规则?