This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-23
Channels
- # adventofcode (21)
- # announcements (4)
- # babashka (35)
- # beginners (36)
- # calva (76)
- # cider (16)
- # clj-kondo (24)
- # clj-on-windows (12)
- # clojure (70)
- # clojure-europe (7)
- # clojure-nl (13)
- # clojure-spec (3)
- # clojure-uk (3)
- # clojurescript (34)
- # conjure (11)
- # cursive (22)
- # datomic (30)
- # deps-new (2)
- # emacs (36)
- # fulcro (28)
- # gratitude (4)
- # honeysql (16)
- # hugsql (8)
- # introduce-yourself (6)
- # jobs (1)
- # malli (4)
- # missionary (6)
- # off-topic (129)
- # other-languages (34)
- # polylith (3)
- # reagent (9)
- # reitit (27)
- # releases (13)
- # remote-jobs (1)
- # reveal (1)
- # shadow-cljs (2)
- # tools-build (3)
- # tools-deps (18)
- # web-security (7)
- # xtdb (4)
does clojure have something like a common lisp (break)
statement, or a JS debugger;
statement that will allow me to drop into the debugger at a certain point in the code? I am developing in CIDER in emacs and so far I have only been debugging top level forms (`C-u C-M-x`) but I'd like to add a break inside a conditional embedded in a loop that I can stop at instead of stepping my way there.
In addition to #break
, you can also evaluate the defn
with ctrl+u ctrl-meta-x
and it will set a breakpoint on the whole function and then you can step through it using the debugger. You can do this to multiple functions as necessary. When no longer want to drop into the debugger, re-evaluate the defn
with just ctrl-meta-x
(no ctrl-u
), and it will remove it. See the CIDER debugger documentation for more.
and then re-evaluate the form
I am wondering how Compojure passes contents of a text box back to Luminus. I wrote an HTML form with input boxes like this: <input type="text" name="whatever"> After user clicks Submit, how will user input arrive in Clojure? I assume in some map, but Luminus has a lot of those. Is there anywhere I should look first?
caveat, this is to the best of my knowledge: luminus uses an http server (i donât know which one) that conforms to the https://github.com/ring-clojure/ring , meaning that it listens to a given port for a ârequestâ, aka data from the internet, and then converts that request into a hashmap of a specific shape that other libraries understand and work with. Then it passes that map to compojure, which understands the ring abstraction too, and reads the keys/values in the request map to determine which route function to pass the request map to
That makes sense. Maybe this is a dumb question, but how do I view a map to see what's in it?
I tried changing a route handler to print out the request, like this: (defn home-page [request] (do (println (apply str request)) (layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)})))
but I don't get any output at the repl
first, you can just do (println request)
cuz println
calls str on the args
second, are you sure that itâs hitting that function?
did you reload it in your repl? i donât know how compojure works, but you might have to reload the endpoint as well
I did reload. I have not written any handler for the submit button. I suspect that may be part of the problem
yeah, thereâs 2 parts: the handler function (as you wrote above), and the endpoint defined in compojure that points to your handler function: (GET "/some/endpoint" [] home-page)
specifically a form submit will be an http request that is a specific shape with a body that is form data https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data
good point, thank you
Is there currently beginner-friendly emacs Clojure setup with these properties? 1) cross-platform Mac/Windows, 2) trivial setup/config on both platforms, 3) bracket matching and re-indentation that works on incomplete expressions, 4) all basic functionality (incl buffer management, editing, repl interaction) accessible via menus or other standard UI elements, without requiring understanding emacs-specific concepts or key chords, etc.
There is also #emacs channel that might have better target audience for the question.
Thanks @UK0810AQ2. It looks possible. From first glance I'm not sure about the triviality of the setup/config, and until I get beyond those I'm not sure about the rest. Do you know which are clearly yesses?
Thanks @U0CMVHBL2. I'll ask also in the #emacs channel.
I think VS Code with Calva and IntelliJ with Cursive are both options to try
depending on how light you want to go on setup, the Calva / Gitpod thing is basically NO install but still gives you basically the same functionality running in a browser
I have data like this [5 "missing" "missing" 7] and I want to get answer something like [5 5 5 7] i.e. get the previous element of a vector until I get non missing data, how can I access the previous element in a vector through iteration ?
I am having a hard time understanding recursion in clojure, so I am not understanding how to achieve it using recursion
cljęuserę>Â
(def data [5 "missing" "missing" 7])
#'user/data
cljęuserę>Â
(reduce (fn [{:keys [previous acc]} value]
(if (= "missing" value)
{:previous previous
:acc (conj acc previous)}
{:previous value
:acc (conj acc value)}))
{:previous nil
:acc []}
data)
{:previous 7, :acc [5 5 5 7]}
(loop [acc []
previous nil
data data]
(if (empty? data)
acc
(if (= (first data) "missing")
(recur (conj acc previous)
previous
(rest data))
(recur (conj acc (first data))
(first data)
(rest data)))))
[5 5 5 7]
Thanks a lot brothers
@mhamzachippa basically what @emccue did but simplified since it's easy to find the last value without needing a composite accumulator
user=> (reduce (fn [acc v]
(conj acc (if (= v "missing")
(peek acc)
v)))
[]
[5 "missing" "missing" 7])
[5 5 5 7]