Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    Sean Corfield
    @xialvjun ^^
    Mitch Robb
    not sure if this is a very active room but i was wondering if someone could help me understand lein-cljsbuild, specifically i'm having trouble understanding why lein is compiling my clojure code (same project, totally different namespace) when i run cljsbuild (and throwing errors related to it)
    https://github.com/olslash/bag/blob/master/project.clj#L65-L67-- i'm running lein cljsbuild once hello -- i expect hello.js to be output, but instead it throws errors related to the stuff in the clojure namespace/src folder
    Mitch Robb
    my understanding is that there shouldn't be any relationship between the two besides what you specify as crossover
    Wagner Amaral
    @olslash the slack community is far more active, there's a bigger chance you could get help there
    Mitch Robb
    thanks ^
    Jonathan Higdon
    what does it mean: "programs are increasingly more about code, decreasingly about the data" https://youtu.be/VSdnJDO-xdg?t=952
    @martabrzeszczyk it means people are increasingly writing complicated solutions they're not considering about the nature of the problems they're trying to solve
    clojure fails in addressing this by refusing to accept that static types would help people think about data rather than code
    @eyelidlessness OK, make sense!!
    @bendlas:matrix.org transducers really are awesome ...
    Alexander Pantyukhin
    Hello, I have a question about the Clojure CLR. Does it work for dotnet core?
    I'm using Arcadia right now
    It's clojureclr for unity which uses dotnet
    Yes, it does
    What is the best way to learn clojure very well. I like to solve adventforcode challenges and making websites.
    dead room?
    David Zhu
    i'm stepping through book called "Web Development with Clojure 2nd Ed"

    I'm a bit confused with the following:

    ​ (ns ring-app.core
    ​ (:require [ring.adapter.jetty :as jetty]
    ​ [ring.util.response :as response]
    ​ [ring.middleware.reload :refer [wrap-reload]]))

    ​ (​defn​ handler [request]
    ​ (response/response
    ​ (str ​"<html><body> your IP is: "​
    ​ (:remote-addr request)
    ​ ​"</body></html>"​)))

    ​ (​defn​ wrap-nocache [handler]
    ​ (​fn​ [request]
    ​ (-> request
    ​ handler
    ​ (assoc-in [:headers ​"Pragma"​] ​"no-cache"​))))

    ​ (​defn​ -main []
    ​ (jetty/run-jetty
    ​ (-> handler var wrap-nocache wrap-reload)
    ​ {:port 3000
    ​ :join? false}))

    in -main, threading -> handler var wrap-nocache wrap-reload
    why is var needed here?
    The book says "Note that we have to create a var from the handler in order for this middleware to work. This is necessary to ensure that the var object containing the current handler function is returned. If we used the handler instead, then the app would only see the original value of the function and changes would not be reflected. A more common way to create a var would be to use the #’ prefix as follows: (-> #’handler wrap-nocache wrap-reload)."
    i'm clueless as to what that means. Please help thank you
    Eugene Pakhomov
    @noblecraft I think it talks about the ring.middleware.reload/wrap-reload that reloads the code that you've changed upon a request. I don't know for sure but I think not using var would prevent such code from being reloaded. You can experiment a bit and confirm it yourself.
    James Sully
    (map rand-nth (replicate 5 (range 5)))
    How do I do this more efficiently, without writing the loop myself? (Using library functions) repeatedly was not quite what I wanted
    Eugene Pakhomov
    @sullyj3 Using repeat instead of replicate will be a bit faster (replicate is deprecated in any case). Apart from that - don't know really. I was surprised that using repeatedly results in a slower code.
    Hello. Sorry for noob questions, but I can't understand what I'm doing wrong.
    Here's code: https://pastebin.com/yBXMjGjy
    censor-word func works fine, and play is updated in play-with-word, but play-with-word only outputs all-censored word and game never ends.
    Eugene Pakhomov
    @GoldsteinE After a superficial look at your code, it seems that \* needs to be in the set of known letters by default.
    Hey all, Not sure of this is the right place to ask such a noob question.
    But in the docs for the reduce function says "...If val is not supplied,
    returns the result of applying f to the first 2 items in coll, then
    applying f to that result and the 3rd item, etc. ..."
    what is val?
    Eugene Pakhomov
    @cyberscientist The second signature of reduce is [f val coll].
    hello guys, im new in clojure and need to take some value defined on my filaA in my fileB, but when i use (println filaA/myDef) i got this: #object[clojure.lang.Atom 0x1edfe27 {:status :ready, :val {:parent {:childOne true, :childTwo true}, :errors []}}]
    how i can convert this #object to json ?
    Eugene Pakhomov

    @YuriMostardeiro Hey. You're asking two questions here:

    1. How to get a value from an atom (given what you provided, fileA/myDef is an atom and not a var)
    2. How to convert a value to JSON


    1. Just use (deref fileA/myDef) or @fileA/myDef. Or maybe don't use an atom at all, if you don't need to change its value
    2. Use this or something similar if you really need a JSON string: https://github.com/clojure/data.json
    ah ok cool.
    i used Atom becouse i need to read some file text and change my object values every line readed and put it on memory, then i need to convert this changes (after some business logic) to an output json
    ill try your suggests thx :)
    Eugene Pakhomov
    It still sounds like something that could be done in a immutable way that doesn't require any atoms. But since you're learning, that's OK.
    Benjamin McFerren
    how to reduce in reverse so to iterate from the last index and on through until the 0 index?
    Eugene Pakhomov
    @mcferren Just wrap the collection in reverse before you reduce it: https://clojuredocs.org/clojure.core/reverse
    Or maybe https://clojuredocs.org/clojure.core/rseq since it's lazy.
    Beeno Tung

    Hi everyone, I'm new to clojure, appreciate if you can point out how shall I implement this format-size function.

    I want to format byte size into human-friendly format.
    But I feel reduce isn't the right approach if the list is huge (I call format-size on a large list), is there a way to early return (without using exception) ?

    One approach I can think of is to use recursive function with, so I can stop iteration, but then I'll have to urgly decompose in each loop, like
    (first c) and (first (rest c))

    Beeno Tung
    This is how I would do it in 'erlang-style', not sure if there is better way in clojure.
    In the 'erlang-version' it doesn't need to construct and destruct the size and unit, instead they're passed as argument
    Eugene Pakhomov

    @beenotung There's no need for iteration at all. If you prepend an empty string to the vector of units, the index of that vector becomes a corresponding power of 1024 that corresponds to that unit (1024^0 - no unit, 1024^1 - KB, and so on).
    So, you need to just get the logarithm of the input number to the base of 1024, round it down, and get the unit from the units vector.
    Of course, you can still use iteration to actually find the logarithm. Or you could use the built-in math function.

    On a side note - you can stop a reduction early by using reduced.