Generate character sequence from 'a' to 'z' in clojure

后端 未结 4 1432
夕颜
夕颜 2021-01-01 20:28

I want to generate character sequence from \'a\' to \'z\'. In scala, I can generate character sequence very simply:

(\'a\' to \'z\')

But in

4条回答
  •  借酒劲吻你
    2021-01-01 21:08

    If code looks "verbose" it's often just a sign that you should factor it out into a separate function. As a bonus you get the chance to give the function a meaningful name.

    Just do something like this and your code will be much more readable:

    (defn char-range [start end]
      (map char (range (int start) (inc (int end)))))
    
    (char-range \a \f)
    => (\a \b \c \d \e \f)
    

提交回复
热议问题