Print character list in clojure

I tried to print a list of characters, and I was wondering if I could remove the quotes.

(def process-print-list
  (fn [a-list]
  (cond (empty? a-list) 'false
  (list? a-list) (let [a a-list] (println (first a)) (process-print-
list (rest a) ))
  :else (process-print-list (rest a-list) ))))

the list is ('x' y 'z))

with the following output:

(quote x)
(quote y)
(quote z) 

I'm just trying to print it:

x
y
z
+3
source share
2 answers

You must use namefn to get the name of the character.

(def my-list (list 'x 'y 'z))

(defn process-list
  [a-list]
  (map #(name %) a-list))

(process-list my-list)
;=> ("x" "y" "z")

Or with print

 (defn process-print-list
    [a-list]
    (doall (map #(println (name %)) a-list)) 
     nil)

  (process-print-list my-list)
  ;x
  ;y
  ;z
  ;=>nil

Or combine the ones you want to get the return type you want ...

+2
source

('x 'y 'z)- syntax abbreviation for ((quote x) (quote y) (quote z)). If you really need a list of characters (i.e. (x y z)), you are probably quoting too much.

'(x y z)          ;=> (x y z)
'('x 'y 'z)       ;=> ((quote x) (quote y) (quote z))
(list 'x 'y 'z)   ;=> (x y z)

, , , . list.

. :

(doseq [sym some-list]
  (println sym))
+7

Source: https://habr.com/ru/post/1780649/


All Articles