This is a beginner question - I am basically just reading a file and I want to print it out. This is what I have:
(defn get-concerto [concerto]
(slurp (str local-dir concerto)))
(p/let [concert (get-concerto “test.cto”)]
(prn concert))
This is what I get:
#<Promise[~]>
Define get: the return value is indeed a promise but does it also print a promise?
This is super basic get-concerto returns a promise. I want to see the value - The contents of the file I am retreiving. I thought the let helped with this - Maybe I need an await in there (get-concerto “test.cto”) #<Promise[~]>
The let will get you a local that binds to the value but the let expression itself returns a promise. You can't break out of a promise. If you want, you can also use fs/readFileSync
It takes a bit getting used to working with promises, but you'll get the hang of it
any idea why I'm getting this? Error: Namespace name must be symbol, got: [object Object] my nbb nrepl via calva blows up with this error after running some promises, I'm not doing anything too interesting, require style is the same as cljs from the docs right, like ["fs" :as fs]
Doesn't ring a bell, full repro welcome
Kk thx I'll look more and come back if necessary I'm sorry just thought you might recognise it
No worries :)
Could it be that you are constructing a symbol with symbol yourself?
not using symbol
(ns release
(:require
["child_process" :as child-process]
[clojure.string :as string]
[exec-nbb :as en :refer [ps-run w-kg-dir]]
[promesa.core :as p]))
(defn release []
(p/do
(println 1)
(ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
"rm -r .shadow-cljs")
(println 2)
(ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
"rm -r .\\public")
(println 3)
(ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
"npx shadow-cljs release tab-app")
(println 4)
(ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
"npx shadow-cljs release tab-backend")
(println 5)
(ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
"cp assets\\index.html public\\index.html")
(println 6)
(ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
"cp assets\\simple_main.js public\\assets\\app\\js\\simple_main.js")))it's doing this, then the other ns header looks like this and is just some tiny wrappers around child process and promises
(ns exec-nbb (:require ["child_process" :as child-process] [promesa.core :as p]))
but don't worry it's not a real blocker was just hoping you might just recognize it, I will work around it and come back at some point and narrow down the source
I'm just using nbb to incrementally script my release process, so every time it's slightly more scripted instead of being manual commands or a shell script
cool. Normal bb might be an easier fit for this, but cool to see that you're using nbb for it
for removing files, you can avoid shelling out, with babashka fs, :
(fs/delete-tree ...)and (fs/copy ...)
I don't use clj other than to compile my cljs and I've day insha'Allah I'll master self hosted
I've day I'll improve my java skills too
One*
But for now
no worries, this approach should work too
Thx that's interesting, the code is ugly I'm just incrementally trying to migrate from the shell didn't know it had those built in
well, normal bb has babashka.fs - nbb doesn't. but "fs" from node has a lot of this stuff too
and by using that instead of shelling out, your code will become more cross platform too
My npm list gives:
npm list
cljacc@1.0.0 /Users/tmb/Coding/Clojure/cljacc
├── @accordproject/concerto-core@3.2.0
└── readfilesync@1.1.5
I have:
(ns concert
(:require [“@accordproject/concerto-core” :as concerto]
[nbb.core :refer [slurp]]
[promesa.core :as p]
[“readfilesync” :as fs]
[clojure.string :as str])
)
I get:
cljs꞉concert꞉>
; ENOENT: no such file or directory, scandir '/Users/tmb/Coding/Clojure/cljacc/node_modules/readfilesync/Users/tmb/Coding/Clojure/cljacc'
It seems to have duplicated ‘Users/tmb/coding/Clojure’
This looks weird indeed
I'll try and repro it here locally or on Windows
I can reproduce the problem on Windows
Also on macos. It seems a problem specific with the "readfilesync" package
@tbrooke Did you intend to use this package? It seems to contain pure nonsense https://www.npmjs.com/package/readfilesync?activeTab=explore
I suppose you meant to write:
(:require ["fs" :as fs])
(fs/readFileSync ...)
to use Node's built-in fs package?