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
在Clojure中从数据库打印表_Clojure - Fatal编程技术网

在Clojure中从数据库打印表

在Clojure中从数据库打印表,clojure,Clojure,我的目标是将表格打印得尽可能近,每个列之间的间距均匀 (defn PrintTable [tableName] "prints table in clear format" (let [tableRef (get (deref dataBase) tableName) ; get refrence for table keyList (keys @tableRef)] ; get key list of table (doseq [tableKeys (range

我的目标是将表格打印得尽可能近,每个列之间的间距均匀

(defn PrintTable [tableName]
  "prints table in clear format"
  (let [tableRef (get (deref dataBase) tableName) ; get refrence for table
        keyList (keys @tableRef)] ; get key list of table
    (doseq [tableKeys (range (count keyList))] ; print the keys of the table
      (let [key (nth (keys @tableRef) tableKeys)]
        (print key "\t|"))
    )
    (println)
    (doseq [rows (range (count @(tableRef (nth (keys @tableRef) 0))))] ; print for each rows all the values
      (doseq [cols (range (count keyList))]
        (let [key (nth (keys @tableRef) cols)]
          (print (@(tableRef key) rows) "\t|")
        )
      )
      (println)
    )
  )
  (println)
)
我曾尝试使用tab,但结果是:

P_Id    |LastName   |FirstName  |Address    |City   |
1   |Darmon     |Gilad  |ishayahu   |Haifa  |
2   |SM     |Shiran     |erez   |RamatIshay     |

D_Id    |Name   |OwnerLastName  |OwnerFirstName     |
a   |Bono   |Darmon     |Gilad  |
b   |Bony   |SM     |Shiran     |

有没有更好的对齐打印的建议?

使用
格式
使cols对齐:

user> (println (format "%20s %20s %20s\n%20s %20s %20s" 
                 "short" "medium" "reallylong" 
                 "reallylong" "medium" "short"))

               short               medium           reallylong
          reallylong               medium                short
nil
user> 
或左对齐
%-20s

user> (println (format "%-20s %-20s %-20s\n%-20s %-20s %-20s" 
                        "short" "medium" "reallylong" 
                        "reallylong" "medium" "short")) 

short                medium               reallylong 
reallylong           medium               short 
nil 
user>

使用
格式
使COL对齐:

user> (println (format "%20s %20s %20s\n%20s %20s %20s" 
                 "short" "medium" "reallylong" 
                 "reallylong" "medium" "short"))

               short               medium           reallylong
          reallylong               medium                short
nil
user> 
或左对齐
%-20s

user> (println (format "%-20s %-20s %-20s\n%-20s %-20s %-20s" 
                        "short" "medium" "reallylong" 
                        "reallylong" "medium" "short")) 

short                medium               reallylong 
reallylong           medium               short 
nil 
user>
这可能会有帮助:

阿尔法-随时可能发生变化。 打印文本表中的地图集合。打印表格标题 ks,然后为每行输出一行,对应于键 在堪萨斯州。如果未指定ks,请使用行中第一项的键。

这可能会有帮助:

阿尔法-随时可能发生变化。 打印文本表中的地图集合。打印表格标题 ks,然后为每行输出一行,对应于键 在堪萨斯州。如果未指定ks,请使用行中第一项的键。

另请参见。另请参见。