I got this working and was able to use Claude to generate an interactive compound interest calculator using Scittle. You can https://claude.site/artifacts/8fa18ead-e75f-43df-acfe-03ac8ab7cf40. It made a silly mistake (`Math/pow` instead of js/Math.pow) but once it was corrected the calculator worked! I'm on the road but I'll post something about this soon. I'll post my prompt in the thread below in case anybody wants to experiment. I think it could be improved a lot with more examples in the prompt (like using js/Math, react libraries, applied-science.js-interop, promesa, etc.)
Scittle is a ClojureScript interpreter which runs entirely in the browser. It supports React via Reagent. I've attached an example of it's usage below.
Can you please create a simple compound interest calculator using Scittle?
<html>
<head>
<title>Scittle basic example</title>
<link rel="stylesheet" href="">
<script src="" type="application/javascript"></script>
<script src=""></script>
<script src=""></script>
<script src="" 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 #(swap! state update :clicks inc)}
"Click me!"]]])
(rdom/render [my-component] (.getElementById js/document "app"))
</script>
<style>
body { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; }
input { margin: 5px 0; padding: 5px; }
h1 { color: #333; }
</style>
</head>
<body>
<div id="app"></div>
</body>
</html> Follow-up prompts:
Error: Message: Could not resolve symbol: Math/pow
Did you mean js/Math.pow instead?
And:
Can you add a CSS based loading spinner as the initial content for #app so that it displays until the app is mounted?Hmm, Math/pow should work, I could fix that if it doesn't yet
Oh really? I didn't realize that namespace was available like that.
yeah, (js/console.log Math/pow) it works here:
https://babashka.org/scittle/codemirror.html
it's the only globally defined JS thing I think, a bit of an exception in CLJS
It's pretty cool that AI was able to generate this
Here's the generated code that threw the error.
(require
'[reagent.core :as r]
'[reagent.dom :as rdom])
(def state (r/atom {:principal 1000
:rate 5
:time 5
:compound-frequency 12}))
(defn calculate-compound-interest []
(let [{:keys [principal rate time compound-frequency]} @state
r (/ rate 100)
n compound-frequency
t time]
(* principal (Math/pow (+ 1 (/ r n)) (* n t)))))
(defn input-field [label key type]
[:div
[:label label]
[:input {:type type
:value (get @state key)
:on-change #(swap! state assoc key (-> % .-target .-value js/parseFloat))}]])
(defn compound-interest-calculator []
[:div
[:h1 "Compound Interest Calculator"]
[input-field "Principal Amount: $" :principal "number"]
[input-field "Annual Interest Rate (%): " :rate "number"]
[input-field "Time (years): " :time "number"]
[input-field "Compound Frequency (per year): " :compound-frequency "number"]
[:h2 "Result:"]
[:p "Future Value: $" (.toFixed (calculate-compound-interest) 2)]])
(rdom/render [compound-interest-calculator] (.getElementById js/document "app"))
I'm confused about why it works on the http://babashka.org version but throws an error on the npm/cdnjs version.Perhaps you're using an old version?
what version of scittle are you using
Sorry, on the train and internet keeps dropping.
0.2.8/scittle.js
scittle is at 0.6.17 now
facepalm somehow I must have submitted an old version to cdnjs. I'll fix it.
This seems to work: https://cdnjs.cloudflare.com/ajax/libs/scittle/0.6.17/scittle.js but your app above uses 0.2.8 in the url
yes, that's just it. this works:
<html>
<head>
<script src="">
</script>
<script type="application/x-scittle">
(js/console.log Math/pow)
</script>
</head>
</html> Ok yes it seems like cdnjs imports every version.
Ok, thanks for figuring that out. I've pushed my latest prompt that works pretty well for generating small Reagent apps up here: https://github.com/chr15m/scittle-claude-ai
Here's another demo that was one-shotted with that prompt template to generate a "CSV viewer" web app: https://claude.site/artifacts/83ac7299-c152-4ef0-acdc-e3b8e696a379 Here's what I added in the customisation section of the prompt template: > Please write an application that allows the user to upload a CSV file and renders it in a table.
that's pretty amazing
I find it impressive and a little bit frightening. 😅