Fork me on GitHub
#beginners
<
2021-12-19
>
Filip Strajnar02:12:30

how do i get more debug info

emccue02:12:32

if you are using IntelliJ and cursive there is a stepper when you run in debug mode

emccue02:12:58

i’d imagine there are similar options in other situations

emccue02:12:48

other than that println debugging

R.A. Porter02:12:42

You might also want to add a tap viewer. See for example, https://github.com/djblue/portal

Pukar Giri03:12:52

can someone guide me to a good tutorial / book to learn Clojure and functional programming in general?

andy.fingerhut03:12:02

I have not read it myself, but have heard others found that "Getting Clojure" by Russ Olsen was a good start.

1
andy.fingerhut03:12:26

(the book was published after I already knew Clojure well, and I wasn't looking for an introductory book)

Cora (she/her)04:12:15

it's an awesome book

Filip Strajnar11:12:45

is there a macro for Calva that inserts parentheses for me?

Sophie11:12:52

Calva has paredit - what exactly do you mean?

Filip Strajnar11:12:50

to write a new pair of parens

Sophie11:12:40

Around something or without content? The latter should happen automatically when you type an opening parenthesis.

Sophie11:12:17

Have a look at this for an overview on paredit: https://calva.io/paredit/

pez15:12:20

Check your Editor Auto-closing brackets settings, @filip.strajnar. it should be languageDefined and in the [clojure] scope it should be set to always. In fact I recommend removing any [clojure] scope things from settings.json. With that fixed any time you type an opening bracket, a closing one should be added to match it. If something is selected when you do it, it will get wrapped. There are also some wrap and re-wrap paredit commands that you’ll find in the guide. that @U02MWDCU3U6 linked.

Anders Persson12:12:54

Howto think about databases in Clojure! maby en strange question, but normaly when i develop it starts with the database, build and, and then the code around. Is this the normal flow to when it comes to Clojure, or is there a better way?

phronmophobic12:12:24

Clojure is used in a wide variety of domains so starting with a db isn't always common, but it's definitely a very reasonable way to write a clojure program.

👍 1
emccue15:12:58

Can you describe more about what you mean by that?

emccue15:12:44

do you mean you start by making your sql/“relational” tables and then write the code to work with them? If so, yeah in web dev thats pretty common

Anders Persson16:12:03

Yes that was my question.

mister_m17:12:43

I've been messing around with common lisp a little bit lately and using SBCL I have the ability to "replay" stack frames when I've entered the debugger. Does clojure offer any similar functionality in the debugger? For example, maybe I call a function A that internally calls some function with too few arguments and I get a stack trace - is there any notion of being dropped into an interactive debugger at that stack frame, where I then could correct the problem, recompile A , then restart whatever prior frame.

Noah Bogart18:12:06

Sadly, no. Clojure doesn't have the concept of a condition system like Common Lisp. That can be achieved with libraries like #farolero but because it's not built into the language, you'll only achieve support in your own code

Sam Ritchie20:12:18

Cc @U01D37REZHP who has done great work here

Filip Strajnar19:12:52

My friend was able to do really really compact code in python, and i wish to do really short implementation equivilent in clojure

R.A. Porter19:12:26

There's an #adventofcode channel you might consider instead for AOC-related questions. You can also skim back through daily pinned threads to find others' solutions.

☝️ 1
Filip Strajnar19:12:56

which functions should i use instead

mister_m19:12:17

Check out the partition function

ghadi19:12:36

try to describe the goal, that's too much to read

seancorfield19:12:30

Also, if this is Advent of Code, there's a specific channel for that @filip.strajnar #adventofcode so that people don't post spoilers in other channels.

Filip Strajnar19:12:02

I'll move there

seancorfield20:12:12

I deleted both the Python code screenshot and your big Clojure code block. Good luck with the AOC problems!

Filip Strajnar20:12:04

thanks and sorry for messing the chat with those

Antonio Bibiano20:12:17

Today I noticed something a bit odd, I was running some code that's essentially a (for ...) with an expensive calculation (but no IO or something else) and while it takes a reasonable amount of time my CPU barely hits 40%, isn't it a bit strange?

andy.fingerhut20:12:19

That can depend a lot on what the body of the for is doing, as it does for any iterative code in any programming language.

andy.fingerhut20:12:16

If the code is public, posting a link to the particular for you are seeing this for would allow someone to try it out, see if they get the same result, and perhaps know an explanation. (no promises that this will happen).

andy.fingerhut20:12:37

But there isn't anything specifically about forthat is known to prevent full CPU utilization that I have heard of.

Antonio Bibiano20:12:37

yeah I figured there must be something about my loop body

Antonio Bibiano20:12:56

I was wondering if there is any operation that comes to mind, but I can definitely point to the code. It's an AoC thing so i didn't want to spam

emccue00:12:00

memory intensive operations wouldn’t use much cpu but still take a lot of time

andy.fingerhut01:12:58

I am not sure, but I think that perhaps memory intensive operations, e.g. ones that gets lots of cache misses, still account for CPU time consumes while waiting for cache misses?

andy.fingerhut01:12:26

I seem to recall doing some Linux performance measurements, at least, a couple of years ago, with one program that frequently hit in the CPU's on-chip cache, and another that frequently missed, and IIRC they both showed near 100% CPU utilization, but the one that frequently hit in the cache completed many more memory accesses per second.

noisesmith20:12:17

my first guess is that it's spending more time allocating more heap from the OS than it is calculating values - try running multiple times and looking at heap usage in eg. visualvm or yourkit

noisesmith20:12:57

either that or it's waiting on coordination with another thread(?)

Antonio Bibiano23:12:25

Thanks I'll try to run it again and see if I can get more info

Dmitrii Pisarenko22:12:03

Hello! I want to use ClojureScript for structural work on writing projects in the following way: 1. I define the data in a ClojureScript file with Emacs or Cursive. 2. Another piece of ClojureScript code renders those data in text, table, or graphic (Graphviz-like way. 3. The results this code produces are displayed in a browser. 4. Whenever I modify some data (item 1), the pages currently open in the browser are automatically updated. That is, I can see the textual, table, or graphic representation of data from item 1 in the browser almost instantaneously (depending on how long it takes for the browser to re-render the page). 5. It must be possible to create separate pages. For example, it must be possible to create a page like which displays the details of scene sc065. 6. Nobody except me will ever read or modify this code. 7. This application will always run on localhost (will never ever be deployed to a real server and will never be accessible from the internet). 8. Performance is not an issue because the amount of data will be quite small (but still overwhelming for human brain). 9. This system must be compatible with MacOS. What libraries/frameworks can I use for it? So far, I am aware of three options: 1. Figwheel 2. ShadowCljs 3. Develop everything from scratch Questions: 1. Are there other options? 2. Given my requirements, which option is better and why? Thanks!

Andrew Brown23:12:13

Hey @U02A6THCMBK - I might check out https://reagent-project.github.io/ if I were you. I just got started with it myself but you should be able to define HTML in terms of ClojureScript and have your changes reflected in near real-time. I was especially thankful for the https://github.com/reagent-project/reagent-template which immediately gave me some valuable insight into how the framework can be leveraged and understood.

Andrew Brown23:12:02

I'm guessing the folks on #reagent are able to field any questions.

emccue00:12:04

Depending on what you are doing exactly, clerk might be an option

Dmitrii Pisarenko21:12:29

@U3JH98J4R Thanks for your answer. Clerk looks very interesting, almost like Jupyter Notebook in Clojure.

Sam Ritchie23:12:43

With the major bonus of not having to use the UI interface as a text editor - so you can bring your full emacs / cursive along with you

sova-soars-the-sora22:12:48

So this sounds like you want to go from edn data to visualizations, is that right?

Dmitrii Pisarenko00:12:07

@U3ES97LAC Not only visualizations. For example: Imagine you are outlining a novel in a Clojure structure. You have a list of 60+ scenes there with locations, characters and other details. To make sense of these data you want to display them in different forms such as: 1. Giant page where all scenes are on one page. 2. A view of scenes which occur at a particular location. 3. A view of scenes where a particular character appears. The point is to have all data as Clojure text so that I can use 1. text editing facilities that work "at a speed of thought" (Vim or Emacs in evil mode) and 2. Git's diffing to enter and modify the data, and output them in any form that I need (different tables and graphs, if necessary).

sova-soars-the-sora02:12:10

(Clojure / Cljs project)

rmxm22:12:45

Is there a good way, to obtain part of a map, via qualified key (namespace) , to the tune of...

(select-keys {:x/a 2 :x/b 3 :y/a 1} [:x/*])
Obtaining a particular part of the map by namespace.

Martin Půda23:12:33

Something like this?

(->> {:x/a 2 :x/b 3 :y/a 1}
     (filter (fn [[k v]] (re-matches #":x/.*" (str k))))
     (into {}))
=> #:x{:a 2, :b 3}

rmxm23:12:44

thanks, diy 🙂

emccue00:12:22

i would go with (= (namespace k) "x")

👍 1