scicloj / clojisr

Clojure speaks statistics - a bridge between Clojure to R
https://scicloj.github.io/clojisr/
Eclipse Public License 2.0
147 stars 9 forks source link

Simpler behaviour of code generation with simple values #37

Closed daslu closed 4 years ago

daslu commented 4 years ago

Currently, the ->code function for code generation converts almost all Clojure values (except for symbols and functions) to corresponding RObjects, and puts these objects' temporary names in the generated code.

See the

E.g.:

(r/->code 3.14)
;; => ".MEM$xf63d99caf6de4aa1"
(r/->code false)
;; => ".MEM$xc6df8e9af9d94817"
(r/->code [1 2 3])
;; => ".MEM$x55d70535c65c4328"

For simple primitive values, such as number, strings and booleans, we would rather put those values explicitly in the generated R code.

That is, what we want is this:

(r/->code 3.14)
;; => "3.14"
(r/->code false)
;; => "FALSE"
(r/->code [1 2 3])
;; => ".MEM$x55d70535c65c4328"

This is will require a rather small change at the codegen namespace, and some adapdtation of the tests.

genmeblog commented 4 years ago

Prepared a branch numbers Still testing and need to write tests in tutorial

(r/->code 1)
;; => "1"
(r 1)
;; => [1] 1

(r/->code '(+ 1 2.1))
;; => "(1 + 2.1)"
(r '(+ 1 2.1))
;; => [1] 3.1

(r/->code 2/3)
;; => "(2/3)"
(r 2/3)
;; => [1] 0.66666667

(r/->code '(+ 1 2.0 3/4))
;; => "(1 + 2.0 + (3/4))"
(r '(+ 1 2.0 3/4))
;; => [1] 3.75

(r/->code true)
;; => "TRUE"
(r true)
;; => [1] TRUE

(r/->code (> 3 4))
;; => "FALSE"
(r (> 3 4))
;; => [1] FALSE
genmeblog commented 4 years ago

BETA9-SNAPSHOT