Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Text 在clojure中读取文件并忽略第一行?_Text_Clojure_Functional Programming_Matching - Fatal编程技术网

Text 在clojure中读取文件并忽略第一行?

Text 在clojure中读取文件并忽略第一行?,text,clojure,functional-programming,matching,Text,Clojure,Functional Programming,Matching,使用来自的代码,我有 …水平平铺ascii图像。现在,我怎样才能“忽略”第一行呢?我这样做的原因是每个图像都有坐标(例如“2063”)作为第一行,我不需要这条线。我尝试了一些方法(保留索引、模式匹配),但我的方法感觉有些做作。假设您想跳过文件的第一行,并像在平铺图像中那样处理剩余的行,您只需将(line seq rdr)替换为 (next (line-seq rdr)) 事实上,您可能应该考虑选择相关行和处理: ;; rename repeat-image to repeat-line (d

使用来自的代码,我有


…水平平铺ascii图像。现在,我怎样才能“忽略”第一行呢?我这样做的原因是每个图像都有坐标(例如“2063”)作为第一行,我不需要这条线。我尝试了一些方法(保留索引、模式匹配),但我的方法感觉有些做作。

假设您想跳过文件的第一行,并像在
平铺图像中那样处理剩余的行,您只需将
(line seq rdr)
替换为

(next (line-seq rdr))
事实上,您可能应该考虑选择相关行和处理:

;; rename repeat-image to repeat-line

(defn read-image [rdr]
  (next (line-seq rdr)))

(defn repeat-image! [n lines]
  (doseq [line lines]
    (repeat-line n line)))
在打开的情况下使用内部

(with-open [rdr ...]
  (repeat-image! (read-image rdr)))
如果您的文件包含多个图像,并且您需要跳过每个图像的第一行,那么最好的方法是编写一个函数,将序列行划分为序列图像(这取决于文件的格式),然后将其映射到
(line-seq-rdr)
(map-next…)
结果上:

(->> (line-seq rdr)
     ;; should partition the above into a seq of seqs of lines, each
     ;; describing a single image:
     (partition-into-individual-image-descriptions)
     (map next))

注意。通过将惰性
分区为单独的图像描述
这将产生惰性序列的惰性序列;您需要在使用open
关闭读卡器之前使用它们。

为了澄清,每个图像都在一个单独的文件中。
(->> (line-seq rdr)
     ;; should partition the above into a seq of seqs of lines, each
     ;; describing a single image:
     (partition-into-individual-image-descriptions)
     (map next))