This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-24
Channels
- # announcements (3)
- # beginners (128)
- # boot (2)
- # braveandtrue (97)
- # calva (13)
- # cider (4)
- # cljdoc (12)
- # cljs-dev (16)
- # clojure (78)
- # clojure-germany (8)
- # clojure-italy (5)
- # clojure-nl (1)
- # clojure-spec (59)
- # clojure-uk (29)
- # clojurescript (46)
- # core-async (9)
- # cursive (63)
- # data-science (3)
- # datomic (22)
- # devcards (1)
- # duct (7)
- # emacs (4)
- # flambo (2)
- # fulcro (37)
- # instaparse (6)
- # jobs-discuss (38)
- # juxt (1)
- # off-topic (35)
- # om-next (1)
- # parinfer (7)
- # re-frame (14)
- # reagent (6)
- # reitit (21)
- # rum (1)
- # shadow-cljs (74)
- # spacemacs (8)
- # specter (1)
- # sql (3)
- # testing (2)
- # unrepl (2)
- # yada (6)
Hi, what is the recommend way of setting things like print-length automatically at repl startup? I'm using deps.edn.
Hi. I just discovered Clojure (again). This time I really want to give it a try! I am comming from the front end and mostly work with TypeScript and Vue.js at the moment.
Which editor or IDE is good for beginners? At the moment I am am doing everything I can with VSCode.
Does it make sense to learn Clojure without having any knowledge of Java to speak of? Last time I got quite some tracebacks talking Javarish when someting did not work correctly.
As an also beginner, I’ve found lein and vs code good for me. My coworkers recommend spacemacs as an editor, but that seems like overkill for me rn.
A frequently-recommended tutorial would be Clojure for the Brave and True, available online (https://www.braveclojure.com/) and in book form. There’s also a #braveandtrue channel on this slack specifically for people working through that tutorial
There are several good editors: I use IntelliJ with the Cursive plugin, others are using Atom with the appropriate plugins, and I think there’s a Clojure plugin for VSCode? Maybe, not sure on that one.
For front end work I recommend re-frame, which is built on top of Reagent. https://github.com/Day8/re-frame. Re-frame has a fairly thorough README, but don’t let that fool you, the real docs are in the /docs
folder. Also be sure to read the todomvc example in the /examples
folder--there’s a bunch of extra documentation in the comments that’s worth having.
I use Leiningen for pretty much everything, never made the jump to Boot. I have heard some say that Boot is better for CLJS stuff, but I’ve never been motivated enough to try it out. One thing in Lein’s favor is that there’s a bunch of people who know it and can help out if you have issues.
If you’re mostly developing front end stuff, the Java side shouldn’t be too much of an issue (I have a site in production now that is CLJS exclusively, no Java anywhere). But if you do run into problems feel free to ask and to post stack dumps in snippets and someone will likely have a look and see if they can help out.
For VSCode, try @pez excellent Calva: https://marketplace.visualstudio.com/items?itemName=cospaia.clojure4vscode
I highly recommend trying out #parinfer if you haven’t already. It juggles brackets and indent levels for you using clever mathematics. The #parinfer devs are bumping into problems of inflexibility with VSCode that’s slowing down progress on the latest version of parinfer for VSCode (though an older version is available). Were it not for that, I would give VSCode a serious go.
If you’re willing to give Atom a go, proto repl is a very nice environment for exploring the output of functions. You can see a demo here: https://atom.io/packages/proto-repl
VS Code is where the issues reside. We have been working on it through out the month
@UB9RVULMA Kudos on the hard work! It’s a shame that VSCode isn’t more flexible than it is.
Thanks for the Calva shout-out! Anyone who does everything in VSCode should try it out. 😍 In waiting for Parinfer, the combo of Calva Formatter and Calva Paredit works pretty well (in my, biased, opinion).
with regard to the ^:private
metadata tag: it looks like this hides functions from unit tests. how do folks conventionally balance the need to unit test and the need to hide implementation details?
#'var-name
will let you grab the var. you can test it even though it is private. I think there are some languages that let the runtime know that the test code is privileged in some manner and you don't need to do this.
@michael740 Conventional wisdom for other languages is that you shouldn't be testing private implementation details in the first place, and I don't see why it would be different in Clojure.
that doesn't seem very wise to me. you should absolutely test private things that aren't shown to outsiders
if a public interface relies on an implementation of shortest path through a graph you can and should write some tests around your graph traversal
if there's lots of private functionality to get the public api to work, why leave it untested. and then if there is a bug in your graph traversal your unit test for the public api would just say some nonsense error and not help you. why wouldn't you want confidence in the edge cases of private implementations
further, the input to the api to hit edge cases in private functions might be quite annoying to put in the test but the input to the private functions could be trivial to probe the edge case
If those edge cases are never hit with the public code, why do you care? Test behavior, not implementation.
> if there is a bug in your graph traversal your unit test for the public api would just say some nonsense error This is the situation I find myself in now. I couldn't debug my main function, so that seemed like a sign I should decompose it
do you think having everything exposed publically could confuse clients of your package?
because there may be some helper functions there that don't make sense / aren't useful outside of the context of your implementation
maybe i'm decomposing too much
that could work
@pez Anything I should know to get ANSI colors in VSCode's terminal when running the REPL (or lein, for that matter)?
You mean syntax highlighting of clojure code? If so, no, that is not anything that Calva can help with atm. Do you have it working in done other terminal?
Lots of clojure tools output ANSI escape codes to colorize the output. For instance "lein cljsbuild once min" compiles your code and the last line it prints out is a "Successfully compiled" message in green. Or, it would be if the console supported ANSI escape codes.
I know Calva doesn't do anything with the console, but I figured if you work in VSCode you might know the answer here.
VSCode is supposed to handle ANSI escape codes according to some google searches, but they show up as funky characters in my output by default.
In Win10 the console also supports them, but I get the same result. But, to use them there a special mode needs to be entered by the application, and I guess lein doesn't bother with this.
The lein README suggests using ansicon, which is a bummer since the console should support it anyway, but I installed it.
Works fine in my PowerShell console, but it's messed up in VSCode. Does produce colors, but afterwards the colors are all out of whack (I get a pink background until I start to type... really ugly).
That "boolean?" warning is a different matter, but this shows how ansicon and VSCode aren't playing nice for me.
I am getting an error No reader function for tag object
when I call this function
(read-string my-str)
. Does anyone know why I am getting this error?
that might be a record literal vs a tag literal, I forget exactly how the reader discriminates between the two
but the reader might first attempt the record literal, then tag literal, so the error you get for a missing record literal is that tag literal error
A philosophical question: to pass atoms and channels down my functions? or to lift values out into monads? or have a stream topology, where information flows and triggers callbacks?
Hi guys, any idea why this doesn’t work:
(def big-number-stream "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450")
(def number-list
(map #(Integer/parseInt %)
(map str big-number-stream)))
(map * (partition 4 number-list))
;; --> ClassCastException Cannot cast clojure.lang.LazySeq to java.lang.Number java.lang.Class.cast (Class.java:3578)
lazy data is realized by accessing it - this could be as simple as printing or counting it
@veix.q5 that error is not being caused by laziness
that's what I'd expect, yes
that's an accidental non-error
(reduce f [x]) returns x for all f and x
reduce doesn't call f if you supply no initial item and there's only one item in the coll
but I don’t get why if that mapping partial reduce works, then why doesn’t take 1 then reduce work
because reduce doesn't call your function if you supply no starting value and there's only one item in the coll
it steals the first item to make it the initial value
f doesn't get called because there's now nothing in your coll
so it returns the first item (the initial value)
(reduce * (take 2 (partition 4 number-list)))
ClassCastException clojure.lang.LazySeq cannot be cast to java.base/java.lang.Number clojure.lang.Numbers.multiply (Numbers.java:148)
right
because (* list list) is an error
* is one of those cases where partial and reduce do the same thing in the two argument case
(mostly)
simply mapping over a collection of collections does not work because does not work with collections
that's wrong
map makes it work
you maybe meant (map * [[1 2 3]])
(map * [1 2 3])
gives the same result as (list (* 1) (* 2) (* 3))
- although I may be fudging a bit with the list
part there
I was specifically talking about (map * [1 2 3]) - that returns the lazy-seq (1 2 3)
which is not what you want if your goal was to multiply 1 by 2 by 3
(apply * [1 2 3])
gives the same result as (* 1 2 3)
or 6
okay so is (map #(apply * %) (take 2 (partition 4 number-list)))
is the same as (map (partial apply *) (take 2 (partition 4 number-list)))
yes, that's how partial works
what’s the right idiom if I wanted to simulate a “moving-window” of 4 digits?
For example, thinking in non functional (’cause that’s where my brain is at), I would:
(partition 4 number-list)
(partition 4 (drop 1 number-list))
and so on until drop 3
then if I appended all that together my map apply * would give me the largest product of any 4 consecutive digits
or I could use tail recursion and an accumulator that eats another digit to make a 4 digit window
@jm.moreau partition
takes a step argument so you can do (partition 4 1 number-list)
boot.user=> (partition 4 1 (range 15))
((0 1 2 3) (1 2 3 4) (2 3 4 5) (3 4 5 6) (4 5 6 7) (5 6 7 8) (6 7 8 9) (7 8 9 10) (8 9 10 11) (9 10 11 12) (10 11 12 13) (11 12 13 14))
what would be the cons to using something like HugSQL vs just writing regular Clojure queries or having some other type of SQL query file?
@seancorfield Thank you