google / clojure-turtle

A Clojure library that implements the Logo programming language in a Clojure context
Apache License 2.0
426 stars 41 forks source link

round decimals to 2 places #28

Closed echeran closed 7 years ago

echeran commented 8 years ago

When printing the turtle position in the REPL, we get full precision of the floating point. We only need 2 decimal places at most.

galbacarys commented 7 years ago

Hey, is this referring to the output you get after each movement command? Or is there some other print command I'm missing? I'd like to take this on.

jeisses commented 7 years ago

@galbacarys This probably refers to the string representation of the turtle. After each movement command the Turtle record is returned, thus printed in the REPL. There are some functions that determine the format of this string

echeran commented 7 years ago

Yes, @jeisses is right. Keep in mind that there's a difference between println/print (printing meant for humans to read) and prn/pr (printing in such a way that the REPL's reader can read them). The REPL uses prn to print return vals.

A custom prn has already been implemented / extended for Turtle values for CLJ and for CLJS. So for the purposes here, we just need to work within the pr-str-turtle fn to customize how the values for :x, :y, and :angle get turned into a string. The math libs in Java vs. JS are probably different, so we'll need reader conditionals.

On second thought, I think just one digit after the decimal point is enough.