[#15] Add println
This commit is contained in:
parent
4cb8e16daf
commit
595d4d3ead
2
deps.edn
2
deps.edn
|
@ -3,7 +3,7 @@
|
||||||
:deps
|
:deps
|
||||||
{org.clojure/clojure {:mvn/version "1.10.3"}
|
{org.clojure/clojure {:mvn/version "1.10.3"}
|
||||||
borkdude/sci {:git/url "https://github.com/borkdude/sci"
|
borkdude/sci {:git/url "https://github.com/borkdude/sci"
|
||||||
:sha "e80a2093722c510ef7988ed4e3b0d9f19f821b52"}
|
:sha "1ae916d4ab972b0a38da3a18665c5fb176401ebc"}
|
||||||
reagent/reagent {:mvn/version "1.0.0"}
|
reagent/reagent {:mvn/version "1.0.0"}
|
||||||
cljsjs/react {:mvn/version "17.0.2-0"}
|
cljsjs/react {:mvn/version "17.0.2-0"}
|
||||||
cljsjs/react-dom {:mvn/version "17.0.2-0"}
|
cljsjs/react-dom {:mvn/version "17.0.2-0"}
|
||||||
|
|
25
resources/public/html/local.html
Normal file
25
resources/public/html/local.html
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../js/scittle.js" type="application/javascript"></script>
|
||||||
|
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
|
||||||
|
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
|
||||||
|
<script src="../js/scittle.reagent.js" type="application/javascript"></script>
|
||||||
|
<script type="application/x-scittle">
|
||||||
|
(require '[reagent.core :as r]
|
||||||
|
'[reagent.dom :as rdom])
|
||||||
|
|
||||||
|
(def state (r/atom {:clicks 0}))
|
||||||
|
|
||||||
|
(defn my-component []
|
||||||
|
[:div
|
||||||
|
[:p "Clicks: " (:clicks @state)]
|
||||||
|
[:p [:button {:on-click #(do (print :foo) (println :dude) (prn (with-out-str (prn :foo))) (swap! state update :clicks inc))}
|
||||||
|
"Click me!"]]])
|
||||||
|
|
||||||
|
(rdom/render [my-component] (.getElementById js/document "app"))
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,10 +1,12 @@
|
||||||
(ns scittle.core
|
(ns scittle.core
|
||||||
(:refer-clojure :exclude [time])
|
(:refer-clojure :exclude [time])
|
||||||
(:require [goog.object :as gobject]
|
(:require [cljs.reader :refer [read-string]]
|
||||||
|
[goog.object :as gobject]
|
||||||
[goog.string]
|
[goog.string]
|
||||||
[sci.core :as sci]
|
[sci.core :as sci]
|
||||||
|
[scittle.impl.common :refer [cljns]]
|
||||||
[scittle.impl.error :as error]
|
[scittle.impl.error :as error]
|
||||||
[cljs.reader :refer [read-string]]))
|
[scittle.impl.io :as io]))
|
||||||
|
|
||||||
(clojure.core/defmacro time
|
(clojure.core/defmacro time
|
||||||
"Evaluates expr and prints the time it took. Returns the value of expr."
|
"Evaluates expr and prints the time it took. Returns the value of expr."
|
||||||
|
@ -17,15 +19,20 @@
|
||||||
ret#))
|
ret#))
|
||||||
|
|
||||||
(def stns (sci/create-ns 'sci.script-tag nil))
|
(def stns (sci/create-ns 'sci.script-tag nil))
|
||||||
(def cljns (sci/create-ns 'clojure.core nil))
|
|
||||||
(def rns (sci/create-ns 'cljs.reader nil))
|
(def rns (sci/create-ns 'cljs.reader nil))
|
||||||
|
|
||||||
|
'clojure.core {}
|
||||||
|
|
||||||
(def namespaces
|
(def namespaces
|
||||||
{'clojure.core
|
{'clojure.core
|
||||||
{'println println
|
{'*print-fn* io/print-fn
|
||||||
'prn prn
|
'*print-newline* io/print-newline
|
||||||
'system-time system-time
|
;; '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
|
'random-uuid random-uuid
|
||||||
'read-string (sci/copy-var read-string rns)}
|
'read-string (sci/copy-var read-string rns)}
|
||||||
'goog.object {'set gobject/set
|
'goog.object {'set gobject/set
|
||||||
|
|
4
src/scittle/impl/common.cljs
Normal file
4
src/scittle/impl/common.cljs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
(ns scittle.impl.common
|
||||||
|
(:require [sci.core :as sci]))
|
||||||
|
|
||||||
|
(def cljns (sci/create-ns 'clojure.core nil))
|
35
src/scittle/impl/io.cljs
Normal file
35
src/scittle/impl/io.cljs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
(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#)))
|
Loading…
Reference in a new issue