joyride

pez 2024-07-03T10:20:39.257759Z

I wonder what would be involved to support the cljs.repl utilities. So that this would work:

(require '[cljs.repl :refer [apropos dir doc find-doc print-doc pst source]])

pez 2024-08-06T09:59:54.008709Z

I actually didn’t try much with ns-aliases. I didn’t understand how to leverage it for solvning my problem. And when I tried it it returned an empty map. But that was some older version or sci. Nu tried bumping Joyride to https://github.com/babashka/sci/commit/7fb09a7826f7451ed73587888bc909076394b1ba, but that needs some work somewhere. I get build warnings:

------ WARNING #1 - :undeclared-var --------------------------------------------
 File: /Users/pez/.gitlibs/libs/org.babashka/sci/7fb09a7826f7451ed73587888bc909076394b1ba/src/sci/impl/analyzer.cljc:1703:16
--------------------------------------------------------------------------------
1700 |   (if (<= children-count 16)
1701 |     #?(:clj #(let [^objects arr (into-array Object %&)]
1702 |                (clojure.lang.PersistentArrayMap/createWithCheck arr))
1703 |        :cljs #(PersistentArrayMap.createWithCheck (into-array %&))
----------------------^---------------------------------------------------------
 Use of undeclared Var sci.impl.analyzer/PersistentArrayMap
--------------------------------------------------------------------------------
1704 |        :default array-map)
1705 |     #?(:clj #(let [^clojure.lang.ISeq s %&]
1706 |                (clojure.lang.PersistentHashMap/createWithCheck s))
1707 |        :cljs #(PersistentHashMap.createWithCheck (into-array %&))
--------------------------------------------------------------------------------

------ WARNING #2 - :undeclared-var --------------------------------------------
 File: /Users/pez/.gitlibs/libs/org.babashka/sci/7fb09a7826f7451ed73587888bc909076394b1ba/src/sci/impl/analyzer.cljc:1707:16
--------------------------------------------------------------------------------
1704 |        :default array-map)
1705 |     #?(:clj #(let [^clojure.lang.ISeq s %&]
1706 |                (clojure.lang.PersistentHashMap/createWithCheck s))
1707 |        :cljs #(PersistentHashMap.createWithCheck (into-array %&))
----------------------^---------------------------------------------------------
 Use of undeclared Var sci.impl.analyzer/PersistentHashMap
--------------------------------------------------------------------------------
1708 |        :default hash-map)))
1709 | 
1710 | (defn return-map [ctx the-map analyzed-children]
1711 |   (let [mf (map-fn (count analyzed-children))]
--------------------------------------------------------------------------------

------ WARNING #3 - :undeclared-var --------------------------------------------
 File: /Users/pez/.gitlibs/libs/org.babashka/sci/7fb09a7826f7451ed73587888bc909076394b1ba/src/sci/impl/analyzer.cljc:1844:51
--------------------------------------------------------------------------------
1841 |                                           vector expr m)
1842 |        (set? expr) (analyze-vec-or-set ctx set
1843 |                                        #?(:clj #(clojure.lang.PersistentHashSet/createWithCheck ^clojure.lang.ISeq %&)
1844 |                                           :cljs #(PersistentHashSet.createWithCheck (into-array %&))
---------------------------------------------------------^----------------------
 Use of undeclared Var sci.impl.analyzer/PersistentHashSet
--------------------------------------------------------------------------------
1845 |                                           :default vector)
1846 |                                        expr m)
1847 |        (seq? expr) (if (seq expr)
1848 |                      (analyze-call ctx expr m top-level?)
--------------------------------------------------------------------------------
and when using the built Joyride I get:
PersistentArrayMap is not defined
Evaluation of file js_repl.cljs failed: #error {:message "PersistentArrayMap is not defined", :data {:type :sci/error, :line 41, :column 1, :message "PersistentArrayMap is not defined", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 41, :column 1, :ns #object[sci.lang.Namespace], :file "/Users/pez/Projects/joyride/examples/.joyride/scripts/js_repl.cljs"} {:line 41, :column 1, :ns #object[sci.lang.Namespace], :file "/Users/pez/Projects/joyride/examples/.joyride/scripts/js_repl.cljs", :sci.impl/f-meta {:ns #object[sci.lang.Namespace], :macro true, :sci/built-in true, :name defn, :arglists ([name doc-string? attr-map? [params*] prepost-map? body] [name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?]), :doc "Same as (def name (core/fn [params* ] exprs*)) or (def\n    name (core/fn ([params* ] exprs*)+)) with any doc-string or attrs added\n    to the var metadata. prepost-map defines a map with optional keys\n    :pre and :post that contain collections of pre or post conditions."}} {:line 41, :column 1, :ns #object[sci.lang.Namespace], :file "/Users/pez/Projects/joyride/examples/.joyride/scripts/js_repl.cljs"})}], :file "/Users/pez/Projects/joyride/examples/.joyride/scripts/js_repl.cljs"}, :cause #object[ReferenceError ReferenceError: PersistentArrayMap is not defined]}

borkdude 2024-08-06T10:01:20.495539Z

I'll fix those warnings, but I don't get those with regular CLJS

borkdude 2024-08-06T10:01:25.701929Z

perhaps this is a shadow problem

pez 2024-08-06T10:11:46.027699Z

Ah, I was trying with https://clojuredocs.org/clojure.core/ns-aliases 😃

borkdude 2024-08-06T10:12:08.096069Z

Try 0.8.43, I fixed the shadow warnings

👀 1
borkdude 2024-08-06T10:18:02.436959Z

SCI 0.8.43 that is

pez 2024-08-06T10:28:11.450879Z

Now doing this. https://github.com/BetterThanTomorrow/joyride/blob/cljs-repl/src/joyride/sci.cljs#L128 But still get:

(require '[cljs.repl :refer [apropos dir doc find-doc print-doc pst source]])
; Could not find namespace: cljs.repl.

borkdude 2024-08-06T10:29:31.275849Z

can you just try (require '[clojure.repl]) instead, just for starters?

borkdude 2024-08-06T10:31:14.833709Z

This works out of the box with SCI 🤷

cljs.user=> (sci/binding [sci/print-fn *print-fn*] (sci/eval-string "(require '[clojure.repl :as r]) (r/doc inc)"))
-------------------------
clojure.core/inc
([x])
  Returns a number one greater than num.
nil

pez 2024-08-06T10:31:50.357599Z

That also gives me

; Could not find namespace: cljs.repl.
With the ns-alias change. Without it I get
; pst does not exist

borkdude 2024-08-06T10:32:26.930549Z

Ah it should be the reverse:

{:ns-aliases '{cljs.repl clojure.repl}

borkdude 2024-08-06T10:32:41.894689Z

so cljs.repl is an alias for clojure.repl which is built into SCI

borkdude 2024-08-06T10:33:10.484079Z

cljs.user=> (sci/binding [sci/print-fn *print-fn*] (sci/eval-string "(require '[cljs.repl :as r]) (r/doc inc)" {:ns-aliases '{cljs.repl clojure.repl}}))
-------------------------
clojure.core/inc
([x])
  Returns a number one greater than num.

pez 2024-08-06T10:33:54.752389Z

Ah, thanks!

pez 2024-08-06T10:38:06.183089Z

So now I at how to make it not croak on pst . This gives no errors:

(require '[cljs.repl :refer [apropos dir doc find-doc print-doc source]])

borkdude 2024-08-06T10:38:53.845309Z

pst doesn't exist in CLJS

borkdude 2024-08-06T10:39:09.121419Z

sorry, I'm wrong about that

borkdude 2024-08-06T10:40:03.061379Z

but maybe that's not implemented yet in SCI

borkdude 2024-08-06T10:41:54.643549Z

yes, it's only implemented for the JVM right now

pez 2024-08-06T10:45:09.029779Z

I can maybe add some NYIP version of pst to the ns in Joyride.

pez 2024-08-06T10:47:10.304899Z

Or, probably I should address the whole problem in Calva instead. Treating all cljs repls equal is not the way to go…

borkdude 2024-08-06T10:52:31.134579Z

What does nyip mean?

pez 2024-08-06T11:03:02.860709Z

Not Yet ImPlemented. 😃

borkdude 2024-08-06T11:14:21.634519Z

or we could just add it to SCI ;)

pez 2024-08-06T11:19:27.632989Z

“just” add it 😃 But, yeah, would be awesome.

borkdude 2024-08-06T11:25:29.765139Z

you could also add it as a function in the joyride SCI config

borkdude 2024-08-06T11:25:40.212959Z

which just throws with NYIP

pez 2024-08-06T11:25:45.030599Z

How do I run that

cljs.user=> (sci/binding [sci/print-fn *print-fn*] (sci/eval-string "(require '[cljs.repl :as r]) (r/doc inc)" {:ns-aliases '{cljs.repl clojure.repl}}))

borkdude 2024-08-06T11:25:56.407929Z

this is inside of a CLJS repl

🙏 1
pez 2024-08-06T11:30:22.766579Z

source fails on clojure.core things, btw:

user=> (require '[clojure.repl :refer [apropos dir doc find-doc print-doc source]])
nil
user=> (source map)
Source not found
nil
(Same with Joyride or nbb)

borkdude 2024-08-06T11:31:03.266659Z

yes, since the source isn't there, but it'll work on user sources

borkdude 2024-08-06T11:31:37.024059Z

it also doesn't work in bb for example

pez 2024-08-06T11:36:02.110299Z

Makes sense.

pez 2024-08-06T11:50:55.803729Z

Thanks for awesome service, @borkdude. https://github.com/BetterThanTomorrow/joyride/pull/189

borkdude 2024-08-06T11:52:26.484879Z

reviewed

pez 2024-08-06T12:14:26.095089Z

I fixed the review feedback. Does it look good to you know?

borkdude 2024-08-06T12:32:35.899029Z

yezzz

pez 2024-08-04T11:07:24.221809Z

I’m not sure how to employ ns-aliases for this. I am now trying another way. Mostly as a way to educate myself. For context: it is Calva that makes that require when it connects to a ClojureScript repl. What I am now trying is to add a sci-config for cljs.repl. Like so:

(ns sci.configs.cljs.repl
  (:require [cljs.repl :as repl]
            [sci.core :as sci]))

(def repl-ns (sci/create-ns 'cljs.repl))

(defn ^:macro apropos [query]
  `(cljs.repl/apropos (str ~query)))

(defn ^:macro dir [ns]
  `(cljs.repl/dir ~ns))

(def cljs-repl-namespace (merge (sci/copy-ns cljs.repl repl-ns)
                                {'apropos (sci/copy-var apropos repl-ns)
                                 'dir (sci/copy-var dir repl-ns)}))

(def namespaces {'cljs.repl cljs-repl-namespace})

(def config {:namespaces namespaces})
Then using sci.configs.cljs.repl/cljs-repl-namespace in the joyride code to add the cljs.repl namespace. Obviously I do not know what I am doing, and I get Maximum call stack size exceeded when trying to use apropos or dir from my Joyride script. Am I even close?

borkdude 2024-08-04T12:04:42.752489Z

can you show what you tried with ns-aliases instead? Also make sure you’re using the latest Sci

borkdude 2024-07-29T13:52:40.777439Z

Some of these things are already there under clojure.repl I think

borkdude 2024-07-29T13:53:00.710589Z

$ nbb
Welcome to nbb v1.2.179!
user=> (clojure.repl/apropos "tree")
(clojure.core/tree-seq)

borkdude 2024-07-29T13:53:37.290819Z

to make it work for cljs.repl I think ns-aliases can be used

pez 2024-07-29T15:16:55.068739Z

🙏