cljs.core/print appends newline in Node-based REPLs

Description

In all cases below, the functions `print-things1`, `print-things2`, and `print-ints1` are defined as follows:

```

(defn print-things1 []

(print "a")

(print "b")

(print "c")

(println "d")

(print "e" "f")

(print "g"))

(defn print-things2 []

(println "x")

(println "y")

(println "z" "w"))

(defn print-ints1 []

(print 1)

(print 2)

(print 3 4 5))

```

Behavior with Clojure/Java 1.10.1 REPL (and many older Clojure versions):

```

$ clojure

Clojure 1.10.1

;; First define functions as shown above

user=> (print-things1)

abcd

e fgnil

user=> (print-things2)

x

y

z w

nil

user=> (print-ints1)

123 4 5nil

user=>

```

Note that `print` does not append a newline to the output at the end, whereas `println` does. Both `print` and `println` print a single space character between multiple arguments.

Current behavior with version 1.10.520 of CloureScript, and also with latest master as of 2019-Aug-08, which is this commit SHA: 3f5a60a31ac1aae9eb509da26249db51316c34e6

When starting a Node-based REPL from the terminal with the command below:

```

$ clojure -m cljs.main --repl-env node

ClojureScript 1.10.520

;; First define functions as shown above

cljs.user=> (print-things1)

a

b

c

d

e f

g

nil

cljs.user=> (print-things2)

x

y

z w

nil

cljs.user=> (print-ints1)

1

2

3 4 5

nil

cljs.user=>

```

Note that `print` always appends a newline after the values printed, and thus behaves the same as Clojure/Java and ClojureScript `println`.

You get exactly the same behavior when starting a Node-based ClojureScript REPL by connecting via a socket REPL using the `deps.edn` file below, starting Clojure using the command `clojure -A:socket`, and then `telnet localhost 50505` from another terminal.

```

{:aliases

{:socket {:jvm-opts ["-Dclojure.server.repl={:port,50505,:accept,cljs.server.node/repl}"]}}

:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}}

```

Implementation details I noticed while developing a proposed patch:

The `*print-fn*` in ClojureScript is always passed string arguments. A call like `(print 1 2)` causes `*print-fn*` to be called once with the string `"1 2"`. That seems perfectly reasonable to me.

I had some debug statements recording details during the execution of cljs.core/maybe-enable-print!, and whenever I started a Node-based REPL, the value of `*target*` at that time was always `"default"`. The condition `(exists? js/console)` is true when starting a Node-based REPL using the commands above, so `enable-console-print!` is the code being used to set up `*print-fn*` with today's ClojureScript. `enable-console-print!` sets `*print-fn*` to use the log method of js/console, which is documented to always append a newline after printing its arguments.

Environment

None

Status

Assignee

Unassigned

Reporter

Andy Fingerhut

Labels

None

Approval

None

Patch

None

Priority

Minor
Configure