This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-10
Channels
- # aleph (3)
- # architecture (3)
- # bangalore-clj (5)
- # beginners (75)
- # boot (75)
- # cider (2)
- # cljs-dev (48)
- # cljsjs (3)
- # cljsrn (17)
- # clojure (125)
- # clojure-belgium (1)
- # clojure-boston (1)
- # clojure-italy (20)
- # clojure-losangeles (2)
- # clojure-spec (73)
- # clojure-uk (34)
- # clojurescript (127)
- # cursive (8)
- # data-science (5)
- # datascript (128)
- # datomic (5)
- # emacs (4)
- # events (3)
- # fulcro (1)
- # jobs (1)
- # jobs-discuss (4)
- # jobs-rus (9)
- # keechma (79)
- # lein-figwheel (2)
- # leiningen (2)
- # lumo (31)
- # om (1)
- # parinfer (61)
- # pedestal (1)
- # planck (1)
- # portkey (31)
- # re-frame (34)
- # reagent (53)
- # ring (3)
- # ring-swagger (13)
- # rum (1)
- # spacemacs (14)
- # testing (1)
- # yada (2)
Hi everyone ! I am new to clojure. Have read clojure for brave and true. Want to do a web based project in clojure. Any suggestions ??
@sobiaadil you may want to check "Web development with clojure 2nd ed." book - it uses Luminus which is a pretty decent web app template combining multiple useful libraries.
Hi, I'm looking for something like NCurses for a Clojure console application. I basically want to use raw keypresses in the console. Any suggestions on how to get them or what library to use? The only thing I've found is JCurses, but not sure how to use that from Clojure. Thanks!
Check out clojure-lanterna https://github.com/MultiMUD/clojure-lanterna
@U5JPZFFR6 another alternative would be to write in cljs and use a nodejs ncurses lib. example: https://www.reddit.com/r/Clojure/comments/6qd05a/what_other_platform_would_you_most_like_to_see/dkwtzw5/ obviously this option is very dependent on your other requirements and how comfortable you are with cljs
@U06CM8C3V thanks, that looks exactly like what I need
I'd thought about cljs just because I'm more familiar with JS than Java, but don't care either way
@sobiaadil not got any web based projects but you might want to check out the 4clojure website if you havent before http://www.4clojure.com/. There are about 150 problems there where you need to write a simple function to pass the given questions. Great for learning and great fun too
@daedelus1982 I'm already doing the 4clojure problems. Thanks!!!
cool, š
I ran into something I cant explain. A function I wrote ran without throwing an exception whereas there was a mistake in it and there should have been an Arity exception. The question was about finding anagrams on the 4clojure site: http://www.4clojure.com/problem/77. And here was my solution: (fn [c] (let [anagram? #(and (= (count %1) (count %2)) (empty? (clojure.set/difference (set %1) (set %2)))) anagrams #(set (conj (filter (partial anagram? %2) %1)))] (set (remove #(= 1 (count %)) (distinct (map (partial anagrams c) c)))))) In my local REPL there was no exception but in a separate REPL the expected exception was thrown because there is a missing argument to conj function in the anagrams binding. Presumably my local REPL was using an older working 'let anagrams' binding and not the new broken one. Are let bindings memoized or something?
I've sometimes found that my local REPL and the 4clojure one slightly differed. Maybe Clojure versions.
I don't recall what problem it was, but a few times I had to use slightly different stlib functions to make something work
thanks, I just tried the same broken function in a rebooted REPL with different arguments and it worked fine. no expected exception
@daedelus1982 I think older versions of Clojure throw an arity exception if you call conj
with only a single arg, but I just looked up the source for conj
in Clojure 1.8.0, and it now accepts zero or more args.
Also, if you go to the main 4clojure page, thereās a link to the github repo. I did a quick clone and checked the project.clj, and 4clojure is still on clojure 1.4.0, so thatās probably why your code throws an exception on 4clojure but not in your local REPL.
thanks for the help. yes, the clojure version does seem to be the cause here. FYI im using 1.8.0
Hi,
how can I set use-context-classloader to false?
I have a problem that classes from my clojure lib (compiled with gen-class) and added to war are not observable. I have to do ugly thing like
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
so the questions: can I change the default clojure classloader and where should I do it?
documentation is not very helpful https://clojuredocs.org/clojure.core/*use-context-classloader*
Iāve been trying to use maps in my programs vs creating new types but iām wondering what the best way to achieve polymorphism is? When everything is a map I canāt dispatch on type, so protocols arenāt that useful. Iām struggling to see how multimethods can be used, and right now my best solution is to add a :type
to my data and dispatch on that. Iām wondering if this is a good pattern to adopt.
If you need polymorphism then itās legit to start defining Records. If youāre new to functional programming, though, itās possible youāre reaching for polymorphism prematurely, if youāre used to doing things the OOP way. It might be worth describing the bigger picture of what youāre trying to do that you want polymorphism for.
Iām not assuming that youāre necessarily doing it wrong, but just thought Iād mention the possibility, since this is the beginners channel.
@sundarj I was considering using Records kind of the same as defining my own type in this case. Trying to see if I can just use plain maps.
although what @U06CM8C3V said is very good
@U06CM8C3V Iām just thinking about how to design my app where I might have different data, like users, movies, movie clips etc, and I want to do similar operations on them without necessarily needing to know the shape of the data (keys)
@sundarj yeah, using :type
didnāt feel right, so at least I know that much now š
@sundarj I was saying that ādo similar operations without know the keysā might be un-Clojure
saying that, the Om Next guide uses a :type
key here: https://github.com/omcljs/om/wiki/Queries-With-Unions#heterogeneous-data
yeah, good example, Iāve seen others, and Iād assume that sort of pattern is what hierarchies are meant for: https://clojure.org/reference/multimethods
Often though what you would normally use polymorphism for can be divined from the data itself, and multimethods work great for that
For example you could assume that a map with :width and :height calculates its area via width * height. While a map with :radius would calculate it differently.
@U07TDTQNL that seems more in the spirit of keeping it all data
Whatās nice about functional programming is that you often donāt need polymorphism, because all youāre interested in is one or two keys in the map. Movies, actors, directors, and studios might all have a :name key, and you might have a function that, I dunno, translates names into pig-latin. All the function needs to do is grab the :name, transform it, and return the result. It doesnāt care if itās a movie name or an actor name or whatever.
There are perfectly legit uses for Records and polymorphism in Clojure, but thereās also a lot of cases where itās not needed, and we just reach for it out of habit. Or at least I did when I was first learning.
i guess the solution is to force yourself to use maps, and then if/when that breaks down you can look at Records and whatnot
pretty much, maps are almost always the right option, sometimes records are faster, that sometimes is a lot less often than people would assume
https://stackoverflow.com/questions/45619969/clojure-future-agent-or-core-async-for-io Agents for IO really bothers me since I read Clojure Programming
@fominok agents are best for the case where you need to accumulate results from these asynchronous operations, but they should happen one at a time
if you want to run them in parallel, and still merge results, Iād use futures that call swap! on an atom only after they get their result (so that only the data modification is retried, and not the http request)
a single agent will only run one action at a time
and using a single agent for a request that doesnāt rely on the data in other requests doesnāt really make much sense
for more complex interactions Iād look into core.async (putting IO into core.async/thread invocations, and reading the result from the channel returned) or possibly a mix of futures for IO and refs for state coordination - really depends on what kind of coordination needs you have
Yes and no. Iām not having a problem reading On Lisp and the little schemer while studying clojure.
Yes and no. Iām not having a problem reading On Lisp and the little schemer while studying clojure.
some people like that one, but thereās also Joy of Clojure and Clojure Programming and Clojure Applied - depends on your tolerance for silliness
because Brave and True is definitely silly
i'm part-way into the brave and true book and enjoying it, but got a little stuck on one of the exercises and haven't gotten back to it for a while. hopefully i'll find some time in the near future to go back to it and get some help from here
@noisesmith thank you!
I would like to run this (merge-with union {1 [1]} {1 [3]})
code and I have ({1 [1]} {1 [3]})
format. How can I change in easy way to use with merge-with union
? flatten not works.. any idea? maybe Iām tired š
@sb Iād expect (merge-with into ...)
to work
@noisesmith thanks I try it now!
@sb clojure.set has many functions that quietly accept things that are not sets but also donāt quite do the right thing (though Iām not sure union is one of them, I think into has the correct collection-independent behavior)
use apply