This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-27
Channels
- # announcements (16)
- # architecture (19)
- # beginners (31)
- # calva (2)
- # cider (1)
- # clerk (4)
- # clj-yaml (58)
- # cljdoc (2)
- # cljs-dev (10)
- # clojure (77)
- # clojure-europe (108)
- # clojure-norway (26)
- # clojure-sanfrancisco (2)
- # conjure (1)
- # cursive (2)
- # datahike (5)
- # datomic (13)
- # emacs (7)
- # etaoin (3)
- # hyperfiddle (15)
- # introduce-yourself (3)
- # kaocha (1)
- # off-topic (21)
- # reagent (4)
- # releases (1)
- # shadow-cljs (41)
- # spacemacs (28)
- # specter (8)
- # squint (30)
- # yamlscript (2)
Curious question. Just today my working project started to error out with:
Syntax error (ClassNotFoundException) compiling at (instant/scripts/analytics.clj:1:1).
instant.scripts.analytics
Looking at analytics.clj
, I realized I had leftover :gen-class
, but no -main
function. I removed gen-class
, and things are working fine.
(ns instant.scripts.analytics
(:require
...)
(:import
(java.time LocalDate Period Instant))
(:gen-class))
What puzzles me though is, why did it start throwing an error on my machine now? Maybe something quietly updated?that is the kind of error you get when you requiring the namespace foo.bar but the file that lives at foo/bar.clj has the namespace foo.baz
Clojure 1.11.1
user=> instant.scripts.analytics
Syntax error (ClassNotFoundException) compiling at (REPL:0:0).
instant.scripts.analytics
user=>
so I would check to make sure the source code you are editing is actually what is being loaded (you aren't working on a different second checkout, don't have another file with the same name on the classpath, etc)
Yesterday I started learning Clojure and I just wrote my first program solving Advent of Code 2022, day 1. I'd love some feedback on my https://gist.github.com/hovsater/b3c8bb0774a4f2a1c364c635027a631b. What can I improve?
Full disclosure: I've done programming in other functional languages such as Elm and OCaml.
Nice and simple, I like it. I've been learning Clojure slowly for a couple of months now, so I can't provide much feedback, sorry. I remember that I overcomplicated my solution by using 'split-lines,' which gave me empty strings. Then, I had to use 'partition-by blank?' to group the values. So... yeah, I prefer your approach.
day 1 is often a straightforward enough problem that there isn't a ton of nuance to critique - I happened to be focusing on generalizing in the 2022 AOC, so not necessarily an improvement, but a thing that might be interesting to play with, is to solve both with one function that takes a number of elves
i guess it would help to have the question and expected answer (test) in the example code. i have no idea what is going on
(defn parse-input [s]
(->>
(str/split s #"\n\n")
(map #(->> (str/split % #"\n") (map parse-long) (reduce +)))))
put threaded transformations on new lines to improve readabilityif my map function is complicated, i like to give it a name (defn). it's easier to tag with a debugger, and it's easier to quickly right some tests against it (when a map -> map fails then you have to write more code to debug/test)
(defn parse-input [s]
(->>
(str/split s #"\n\n")
(map #(->> (str/split % #"\n")
(map parse-long)
(reduce +)))))
i ran you code, and i was surprised that this function didn't just parse the input. it turned all the lines of the input into a single number.if parse-input always returns a single number (wrapped in a vector for some reason), why is the code for part-1 and part-2 so complicated?
when i run your sample data on part-1 and part-2 i get the same answer, is that supposed to happen?
(defn parse-input [s]
(->>
(str/split s #"\n+")
(map parse-long)
(reduce +)))
#_(parse-input sample-input)
(defn part-1 [input]
(parse-input input))
(defn part-2 [input]
(parse-input input))
(part-1 sample-input)
(part-2 sample-input)
using your sample data, i am able to get the same behaviour with this code. i'm really confused as to what the objective of the code is or how to test it@U0LAJQLQ1 your implementations of part1
and part2
above is not correct. The first part should return the biggest number. The second part should return the sum of three biggest numbers. Not sure how you end up with the same number. I’ve tested my code multiple times.
I do appreciate the feedback regarding breaking out into a separate function to ease debugging. I can also see how reducing within parse-input
is weird. I did that to save repeating myself in part-1
and part-2
, but it should most likely just be repeated.
checkout #adventofcode for comparative solutions. Each day has a thread pinned, here’s https://clojurians.slack.com/archives/C0GLTDB2T/p1669870809772339
Your code is nice!
Have a look at http://clojuredocs.org for more regex based functions. They typically start with re-
I'm half sure you can do more in fewer steps (computations). It's sometimes interesting to do the same thing in different ways.
@U05JP9PDU75 how am i supposed to know what these function are supposed to do? when posting code for other people to look at it really matters that you do some work to help them understand the goal. i ran these 2 functions with your sample-data and they produced the same output, so i changed my code as if those were the tests that needed to be passed.
@U0LAJQLQ1 they don’t produce the same output for the sample data either, so I’m not sure what you did wrong. :man-shrugging:
But I’ll make sure to make the expectations of program more clear the next time around.
@U01EFUL1A8M thanks! Will do. 🙂
@U05JP9PDU75 you are running different code than the one you posted in the gist, if that is the case
Yeah, I was about to say, the new lines are quite important. 😅