You can write this function in clojure in the same style:

(defn move2ascii [move]
  (let [f1 (/ move 100)
        f2 (mod move 100)
        row1 (int (inc (/ f1 8)))
        row2 (int (inc (/ f2 8)))
        col1 (char (+ (mod f1 8) 97))
        col2 (char (+ (mod f2 8) 97))]
    (str col1 row1 col2 row2)))

I don't think this is less idiomatic.
Just my 2¢.

Islon

On May 19, 8:56 am, edlich <edl...@gmail.com> wrote:
> Dear Community,
>
> I have one question about readability. As I am not yet deep into
> Clojure I can only post scala but I am sure you will get my point.
>
> Recently I wrote the following dump function in Scala:
>
>  // convert 1228 to "e2e4"
>   def move2ascii(move: Int): String = { // Clojure Style
>     (((move / 100) % 8 + 97).toChar).toString + ((move / 100) / 8 +
> 1).toString +
>             (((move % 100) % 8 + 97).toChar).toString + ((move %
> 100) / 8 + 1).toString
>   }
>
> but I could as well have written it like this in an imprative style:
> (both are equal)
>
> def move2ascii(move: Int): String = {    // Scala Style
>     val f1 = move / 100
>     val f2 = move % 100
>     val row1 = f1 / 8 + 1 // 2 von e2
>     val row2 = f2 / 8 + 1 // 4 von e4
>     val col1 = (f1 % 8 + 97).toChar // 5 = e von e2
>     val col2 = (f2 % 8 + 97).toChar // 5 = e von e4
>     col1.toString + row1.toString + col2.toString + row2.toString
>   }
>
> I am sure if you write the first function in Clojure it would look
> nearly the same.
>
> My point and my question is:
>
> Isn't the second function easier to read? I know there had been a lot
> of threads about readability
> in clojure but I am not yet convinced.
> In the second version the brain can rely on some steps inbetween which
> make it more readable
> for me. Or should the first function be split up into several more
> functions to become more readable?
>
> I would be happy if you convince me to give Clojure a better chance.
>
> Thanks in advance
> Stefan Edlich
>
> P.S.: It's nice to see the upcoming Clojure book in Manning!
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to