;;模擬console原位更新輸出spa
;;空格擦除法,輸出空格,是爲了擦除短字符串尾部沒有佔用的位置,由於退格只是回退,並不刪除
(dotimes [_ 10](let [n (rand) sn (.substring (str n ) 2) len (count sn)](print sn)(flush)(Thread/sleep 500) (dotimes[_ len](print "\b"))(flush)))
;;回退鍵配合刪除字符,因爲刪除後,光標又前進一位,因此須要再次回退
(dotimes [_ 10](let [n (rand) sn (.substring (str n ) 2) len (count sn)](print sn)(flush)(Thread/sleep 500) (dotimes[t len](print "\b\u007f\b"))(flush)))
;;case宏,多個匹配,同一返回值:使用listcode
(let [n 12,unit "hour"] (case unit ("h" "hour" "hours") (* n 60 60 1000) ("m" "min" "minute" "minutes") (* n 60 1000) ("s" "sec" "second" "seconds") (* n 1000) ("ms" "milisecond" "miliseconds") n n ) )