From b5789ed71d3eea3b85c956d566d212938de9aac2 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 22 Sep 2021 23:22:21 +0200 Subject: [PATCH] Update to newest SCI with print-fn --- deps.edn | 2 +- src/scittle/core.cljs | 16 +++++----------- src/scittle/impl/io.cljs | 35 ----------------------------------- 3 files changed, 6 insertions(+), 47 deletions(-) delete mode 100644 src/scittle/impl/io.cljs diff --git a/deps.edn b/deps.edn index c3a167a..614ffe7 100644 --- a/deps.edn +++ b/deps.edn @@ -3,7 +3,7 @@ :deps {org.clojure/clojure {:mvn/version "1.10.3"} borkdude/sci {:git/url "https://github.com/borkdude/sci" - :sha "1ae916d4ab972b0a38da3a18665c5fb176401ebc"} + :sha "315e5ee6d6ce0b7f6ccac641ed79adde65dea666"} reagent/reagent {:mvn/version "1.0.0"} cljsjs/react {:mvn/version "17.0.2-0"} cljsjs/react-dom {:mvn/version "17.0.2-0"} diff --git a/src/scittle/core.cljs b/src/scittle/core.cljs index 84520b8..feff374 100644 --- a/src/scittle/core.cljs +++ b/src/scittle/core.cljs @@ -5,8 +5,7 @@ [goog.string] [sci.core :as sci] [scittle.impl.common :refer [cljns]] - [scittle.impl.error :as error] - [scittle.impl.io :as io])) + [scittle.impl.error :as error])) (clojure.core/defmacro time "Evaluates expr and prints the time it took. Returns the value of expr." @@ -21,17 +20,9 @@ (def stns (sci/create-ns 'sci.script-tag nil)) (def rns (sci/create-ns 'cljs.reader nil)) -'clojure.core {} - (def namespaces {'clojure.core - {'*print-fn* io/print-fn - '*print-newline* io/print-newline - ;; 'with-out-str (sci/copy-var io/with-out-str cljns) - 'prn (sci/copy-var io/prn cljns) - 'print (sci/copy-var io/print cljns) - 'println (sci/copy-var io/println cljns) - 'time (sci/copy-var time cljns) + {'time (sci/copy-var time cljns) 'system-time (sci/copy-var system-time cljns) 'random-uuid random-uuid 'read-string (sci/copy-var read-string rns)} @@ -95,3 +86,6 @@ (js/document.addEventListener "DOMContentLoaded" (fn [] (when-not @auto-load-disabled? (eval-script-tags))), false) + +(enable-console-print!) +(sci/alter-var-root sci/print-fn (constantly *print-fn*)) diff --git a/src/scittle/impl/io.cljs b/src/scittle/impl/io.cljs deleted file mode 100644 index 52065f8..0000000 --- a/src/scittle/impl/io.cljs +++ /dev/null @@ -1,35 +0,0 @@ -(ns scittle.impl.io - (:refer-clojure :exclude [prn print println with-out-str]) - (:require - [cljs.core :as c] - [goog.string] - [sci.core :as sci] - [scittle.impl.common :refer [cljns]])) - -(def print-fn (sci/copy-var *print-fn* cljns)) -(def print-newline (sci/copy-var *print-newline* cljns)) - -(defn println [& objs] - (binding [*print-fn* @print-fn - *print-newline* @print-newline] - (apply c/println objs))) - -(defn prn [& objs] - (binding [*print-fn* @print-fn - *print-newline* @print-newline] - (apply c/prn objs))) - -(defn print [& objs] - (binding [*print-fn* @print-fn] - (apply c/print objs))) - -(defn ^:macro with-out-str - "Evaluates exprs in a context in which *print-fn* is bound to .append - on a fresh StringBuffer. Returns the string created by any nested - printing calls." - [_ _ & body] - `(let [sb# (goog.string/StringBuffer.)] - (binding [cljs.core/*print-newline* true - cljs.core/*print-fn* (fn [x#] (.append sb# x#))] - ~@body) - (cljs.core/str sb#)))