nbb

athomasoriginal 2024-09-02T18:01:01.089699Z

Is it possible to have a nbb script get a var by name from another cljs file and use then it? For example:

(ns entry)

(def data {:name "James"})

(def home-page [] [:h1 "Welcome"])
and then an nbb script which would do something like:
(p/let [result-str (nbb/slurp "path/to/entry.cljs") 
        data       (get-var result-str "data")]
  data)

borkdude 2024-09-02T18:31:30.866939Z

yes, you can use a combination of load-string and resolve

borkdude 2024-09-02T18:32:43.068129Z

(nbb.core/load-string "(ns foo) (defn foo [])")

borkdude 2024-09-02T18:32:47.423279Z

use this within p/let

athomasoriginal 2024-09-02T18:39:43.627039Z

How would I reference a specific var? For example:

(nbb.core/load-string "(ns foo) (def data {:count 1}) (defn foo [])")
load-string would return #'foo/foo , yes? How might I use #'foo/data ?

borkdude 2024-09-02T18:43:45.025909Z

(resolve 'foo/data)

👍 1