Fork me on GitHub

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.

Joshua Suskalo02:12:25

You can set a breakpoint with a #break reader macro when using CIDER

👍 1
Joshua Suskalo02:12:32

and then re-evaluate the form

Jim Strieter13:12:26

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?

Noah Bogart14:12:25

caveat, this is to the best of my knowledge: luminus uses an http server (i don’t know which one) that conforms to the , 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

Jim Strieter18:12:50

That makes sense. Maybe this is a dumb question, but how do I view a map to see what's in it?

Jim Strieter18:12:45

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/" io/resource slurp)})))

Jim Strieter18:12:51

but I don't get any output at the repl

Noah Bogart18:12:03

first, you can just do (println request) cuz println calls str on the args

Noah Bogart18:12:16

second, are you sure that it’s hitting that function?

Noah Bogart18:12:46

did you reload it in your repl? i don’t know how compojure works, but you might have to reload the endpoint as well

Jim Strieter18:12:39

I did reload. I have not written any handler for the submit button. I suspect that may be part of the problem

Noah Bogart18:12:28

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

☝️ 1
Noah Bogart16:12:59

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.

Ben Sless16:12:48

Spacemacs with cua mode, possibility?


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.


> beginner-friendly > emacs no

😄 3
Alex Miller (Clojure team)17:12:35

I think VS Code with Calva and IntelliJ with Cursive are both options to try

Alex Miller (Clojure team)17:12:34

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

Muhammad Hamza Chippa21:12:59

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 ?


Specifically iteration? Otherwise this is fairly recursive

Muhammad Hamza Chippa22:12:01

I am having a hard time understanding recursion in clojure, so I am not understanding how to achieve it using recursion


Give me a moment to type this out, on phone


(def data  [5 "missing" "missing" 7])
(reduce (fn [{:keys [previous acc]} value]
          (if (= "missing" value)
            {:previous previous
             :acc      (conj acc previous)}
            {:previous value
             :acc      (conj acc value)}))
        {:previous nil
         :acc      []}
{:previous 7, :acc [5 5 5 7]}


i’ll type out the equivalent with loop/recur

gratitude 1

(loop [acc      []
       previous nil
       data     data]
  (if (empty? data)
    (if (= (first data) "missing")
      (recur (conj acc previous)
             (rest data))
      (recur (conj acc (first data))
             (first data)
             (rest data)))))
[5 5 5 7]

Muhammad Hamza Chippa22:12:37

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)
               [5 "missing" "missing" 7])
[5 5 5 7]