This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-13
Channels
- # announcements (13)
- # beginners (52)
- # bitcoin (2)
- # calva (2)
- # cider (7)
- # clara (1)
- # clj-commons (11)
- # clj-kondo (6)
- # cljdoc (14)
- # clojure (68)
- # clojure-belgium (1)
- # clojure-denmark (6)
- # clojure-europe (57)
- # clojure-nl (2)
- # clojure-norway (10)
- # clojure-uk (3)
- # clojurescript (7)
- # code-reviews (17)
- # conjure (1)
- # cursive (5)
- # dev-tooling (11)
- # emacs (9)
- # fulcro (12)
- # hugsql (20)
- # introduce-yourself (6)
- # joyride (2)
- # leiningen (1)
- # lsp (61)
- # malli (30)
- # missionary (11)
- # nbb (6)
- # off-topic (26)
- # portal (5)
- # practicalli (5)
- # re-frame (8)
- # releases (8)
- # sci (21)
- # shadow-cljs (3)
- # sql (17)
- # squint (1)
- # xtdb (3)
Hey hey,
I have a program that takes a JSON as input and outputs multiple (or 0) JSONs as a response.
I would like to map which fields are actually being used from the input JSON, how and why.
I was thinking for phase 1 to replace the hash-map
s with some type that will document all the get
s from the input JSON.
I would love some feedback on my idea / more suggestions.
we can always do the whole thing manually but that could be tedious and we might miss some things that the automatic way would not (and vice versa I guess)
*lets assume the input JSONs have hundreds of fields and the values are numbers, arrays, booleans, strings and more JSONs
Suggestion: use keys
to get json keys, and clojure.set/union
to merge each key set.
(does not work for hierarchical / recursive json - then perhaps use clojure.walk/prewalk
)
Please let me know if this doesn't make any sense! I'm not 100 % sure whether I know what you want to achieve.
@U06BE1L6T, I cannot but lets assume it contains a lot of ifs, modifications on the data, decisions about how many outputs are gonna be and most of the decisions are complex
@U3X7174KS, can you explain what i am trying to achieve by using keys and union? I am not sure how to use these for this goal
You return some data. You want to know what keys are present. A way to solve that is to iterate collect a set of keys. In the shallow case, you can perhaps (reduce set/union (set) (map keys objects)), where objects is a list of objects. In the nested case it gets harder, but not impossible.
Like jumar suggested - can you assume there's a function magic
that does what you need, and provide an example call to magic for us?
(magic ,,,)
;; => ,,,
the input could be {:a 1}
and the output could be [{:b 5}, {:c 7}]
or []
it is not really a magic function, the prgoram does a lot of calculations, I need to know which fields it used in the calculation. (regardless of what got passed to the output) let's say my service is something like this:
(defn foo [input-map] [{:b 3} {:c 5}])
then magic
should tell me "nothing was used in the calculation"
lets say the service does this:
(defn foo [input-map] (if {:a input-map}
[{:b (+ 1 (:a input-mmap))} {:c 5}]
[{:b (* 9999 (:c input-mmap))} {:c 5}])
then magic
should say:
• :a is used in line 1
• :a is used in line 2
• :c is used in line 3You could try to use typed Clojure's inference or instrumentation, but I haven't managed to get it to work yet
Perhaps you could use metadata for that but I feel like it's mostly about how do you construct the descriptions of what has been used in the function.
I think what you want is a custom implementation of a map which has a hook for spying on accesses
(def-map-type LazyMap [m mta]
(get [_ k default-value]
(if (contains? m k)
(let [v (get m k)]
(if (instance? clojure.lang.Delay v)
@v
v))
default-value))
(assoc [_ k v]
(LazyMap. (assoc m k v) mta))
(dissoc [_ k]
(LazyMap. (dissoc m k) mta))
(keys [_]
(keys m))
(meta [_]
mta)
(with-meta [_ mta]
(LazyMap. m mta)))
seems like you could use this library to do what you want https://github.com/clj-commons/potemkincan use a stack walker to get the line number of the usage too https://stackoverflow.com/questions/17473148/dynamically-get-the-current-line-number
hi, I'm having an issue getting a shadow-cljs app to run.
here's the stacktrace that prints out when I try to run "npm run":
{:clojure.main/message "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).\n-M (No such file or directory)\n", :clojure.main/triage {:clojure.error/class java.io.FileNotFoundException, :clojure.error/line -2, :clojure.error/cause "-M (No such file or directory)", :clojure.error/symbol java.io.FileInputStream/open0, :clojure.error/source "FileInputStream.java", :clojure.error/phase :execution}, :clojure.main/trace {:via [{:type java.io.FileNotFoundException, :message "-M (No such file or directory)", :at [java.io.FileInputStream open0 "FileInputStream.java" -2]}], :trace [[java.io.FileInputStream open0 "FileInputStream.java" -2] [java.io.FileInputStream open "FileInputStream.java" 216] [java.io.FileInputStream <init> "FileInputStream.java" 157] [java.io.FileInputStream <init> "FileInputStream.java" 111] [clojure.lang.Compiler loadFile "Compiler.java" 7575] [clojure.main$load_script invokeStatic "main.clj" 475] [clojure.main$script_opt invokeStatic "main.clj" 535] [clojure.main$script_opt invoke "main.clj" 530] [clojure.main$main invokeStatic "main.clj" 664] [clojure.main$main doInvoke "main.clj" 616] [clojure.lang.RestFn applyTo "RestFn.java" 137] [clojure.lang.Var applyTo "Var.java" 705] [clojure.main main "main.java" 40]], :cause "-M (No such file or directory)"}}
it looks like the filenotfound in question is related to java itself?here's my shadow-cljs.edn
:
{:deps true :builds {:backend {:target :node-script :main com.apogenius.backend.dev-server/main :output-dir "out/backend/" :output-to "out/backend/main.js" :devtools {:before-load-async com.apogenius.backend.dev-server/stop :after-load com.apogenius.backend.dev-server/start}} :frontend {:target :browser :output-dir "frontend/public/js" :asset-path "/js" :modules {:app {:entries [com.apogenius.frontend.core]}} :devtools {:http-root "frontend/public" :http-port 8888 :reload-strategy :full}}}}
here's package.json
:
{ "name": "pathom", "version": "1.0.0", "description": "This project can test both front-end and back-end capabilities. It uses `pathom3` running on `nodejs` (very similar to our production environment).", "main": "index.js", "scripts": { "start": "npm-run-all --parallel start:*", "start:repl": "node ./scripts/repl.js", "start:shadow": "shadow-cljs watch backend frontend", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "devDependencies": { "npm-run-all": "^4.1.5", "shadow-cljs": "^2.15.10" }, "dependencies": { "react": "17.0.1", "react-dom": "17.0.1" } }
and here's deps.edn
:
{:deps {applied-science/js-interop {:mvn/version "0.2.7"} bidi/bidi {:mvn/version "2.1.6"} cider/cider-nrepl {:mvn/version "0.25.5"} cider/piggieback {:mvn/version "0.5.2"} cljs-bean/cljs-bean {:mvn/version "1.7.0"} cljs-ajax/cljs-ajax {:mvn/version "0.8.3"} com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"} com.cognitect/transit-cljs {:mvn/version "0.8.269"} com.wsscode/pathom3 {:mvn/version "2021.08.14-alpha"} kibu/pushy {:mvn/version "0.3.8"} metosin/potpuri {:mvn/version "0.5.3"} re-frame/re-frame {:mvn/version "0.10.6"} reagent/reagent {:mvn/version "1.0.0" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/create-react-class]} thheller/shadow-cljs {:mvn/version "2.15.10"}} :paths ["backend/main/src" "frontend/main/src" "shared/main/src"] :aliases {:test {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}} :main-opts ["--main" "cljs-test-runner.main" "--dir" "backend/main/test" "--dir" "shared/main/test"] :extra-paths ["backend/main/test" "shared/main/test"]}}}
Yea, as I was saying in the other thread, it looks like stacktrace you're getting is from running clojure
or clj
rather than npm
how are you running the command?
$ java -version openjdk version "17.0.4" 2022-07-19 OpenJDK Runtime Environment (build 17.0.4+8-Raspbian-1deb11u1rpt1) OpenJDK Client VM (build 17.0.4+8-Raspbian-1deb11u1rpt1, mixed mode, emulated-client)
npm doesn't rely on java
you're right
$ git --version git version 2.30.2
$ node --version v19.3.0
$ npm --version 9.2.0
oh ok. it looks like there's an extra new line somewhere
I could be wrong about the backend
also, I'm not sure it's a great idea to post a company's code challenge publicly.
unless it was already public
I've made it private
what version of the clojure
command do you have?
clojure --version
$ clj --version Clojure CLI version 1.11.1.1208
$ clojure --version Execution error (FileNotFoundException) at http://java.io.FileInputStream/open0 (FileInputStream.java:-2). --version (No such file or directory) Full report at: /tmp/clojure-17190885051890988348.edn
also, I am apogenius
when I follow /tmp/clojure-17190885051890988348.edn the stacktrace looks just like the one I get for trying to run npm start
weird though it's running now. could have been a version issue with clojure
If clojure --version
is giving you a file not found error then it is not the correct script (although clj
seems to be) -- so I suspect you have an old, unofficial clojure
command installed on your system which is going to mess a lot of things up.
What is the output of which clj
and which clojure
@U03HD1DNGDP?
here's the stacktrace that prints out when I try to run "npm run":
{:clojure.main/message "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).\n-M (No such file or directory)\n", :clojure.main/triage {:clojure.error/class java.io.FileNotFoundException, :clojure.error/line -2, :clojure.error/cause "-M (No such file or directory)", :clojure.error/symbol java.io.FileInputStream/open0, :clojure.error/source "FileInputStream.java", :clojure.error/phase :execution}, :clojure.main/trace {:via [{:type java.io.FileNotFoundException, :message "-M (No such file or directory)", :at [java.io.FileInputStream open0 "FileInputStream.java" -2]}], :trace [[java.io.FileInputStream open0 "FileInputStream.java" -2] [java.io.FileInputStream open "FileInputStream.java" 216] [java.io.FileInputStream <init> "FileInputStream.java" 157] [java.io.FileInputStream <init> "FileInputStream.java" 111] [clojure.lang.Compiler loadFile "Compiler.java" 7575] [clojure.main$load_script invokeStatic "main.clj" 475] [clojure.main$script_opt invokeStatic "main.clj" 535] [clojure.main$script_opt invoke "main.clj" 530] [clojure.main$main invokeStatic "main.clj" 664] [clojure.main$main doInvoke "main.clj" 616] [clojure.lang.RestFn applyTo "RestFn.java" 137] [clojure.lang.Var applyTo "Var.java" 705] [clojure.main main "main.java" 40]], :cause "-M (No such file or directory)"}}
it looks like the filenotfound in question is related to java itself?Where are you typing "npm run"? This output looks like the output from running the clojure
or clj
commands.
As a side note, if you have a long question, it can be helpful to summarize in a top-level message and post the details in a thread 🧵 .
I have a shadow-cljs app that somehow is running out of java heap space when I try to run it using npm start
. can I increase the heap size in my shadow-cljs.edn?
You should look at shadow-cljs.edn
to see if it is using deps.edn
or keeping all config in shadow-cljs.edn
Either way you can probably fix the issue by adding :jvm-opts
but where it goes will depend on the shadow-cljs config.
https://shadow-cljs.github.io/docs/UsersGuide.html#jvm-opts
I had a similar issue where it was blowing the stack size and adding :jvm-opts ["-Xss2m"]
fixed my issue. For the heap size I believe the flags are Xms
and Xmx
https://alvinalexander.com/blog/post/java/java-xmx-xms-memory-heap-size-control/
Meta-thought: support is pretty decent over at #C6N245JGG. hth.