Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    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.

    Guillermo Martín
    hi everybody
    i'm getting this clj-kondo warning: inline def
    i'd like to do it more idomatic can someone point me in a direction?
    i have a buch of function that share a parameter so i have a def
    but the def depends on the project so i have a (defn set-param [p] (def my-param p))
    which seems a bad idea just don't know how to do it right
    Eugene Pakhomov
    @willemsh_gitlab You can either set! the var created by a def at the NS scope or you can use a dynamic variable if that makes sense. More details: https://clojure.org/reference/vars
    Jorge Tovar
    Hello everybody ... Im exploring Clojure and I really love it
    but whats the best practice for error Handling in clojure???
    try catch?
    Eugene Pakhomov
    That's an incorrect question. Some good insights here: https://clojureverse.org/t/is-error-throwing-bad-functional-programming/2188
    Viet Vu
    Eugene Pakhomov
    It's used within the metabase.util/prog1 macro which defines that symbol: https://github.com/metabase/metabase/blob/master/src/metabase/util.clj#L173
    Viet Vu
    Thanks Eugene, I got it!
    Aviraj Khare
    Clojure is very hard :(
    I am unable to pick it up
    Eugene Pakhomov
    Try reading the second edition of SICP.
    Aviraj Khare

    Hey everyone, I'm trying to create a function that will download stuff based on the link its given. I wonder if its better to use multimethod over protocols.

    Req: I want to extend that function in the future, each link has its unique process and set of argument as well as the output it produces.

    Benjamin Marwell
    Hi everyone! Just stumbled over https://clojure.atlassian.net/browse/CLJ-2609.
    I think I can push the IBM support to look for a cause. Do you have a mve (minimal viable example)? And how can IBM support or me comment on that issue? Thanks!
    @bmarwell I would ask here:
    I think most of the Clojure community/developers are on slack
    Benjamin Marwell
    cannot access that link @leobm_twitter
    Jonathan Beebe
    does anyone have experience with luminus?
    re: application profiles, can those be added to existing projects? If say later you want to add something
    oh, not so hot as scala does
    does anyone have experience with vertx?

    hello everyone.

    Can anyone list me the pros and cons of designing a language(say clojure) that works on top of JVM.


    Jim Newton
    Can someone help me understand the documentation for = ? https://clojuredocs.org/search?q=%3D
    it says numbers are compared in a type independent way. However, experimentation shows numbers are compute type-DEPENDENT. (= 1 1.0) returns false. I don't understand the claim in the documentation.
    Ian Wilson
    @jimka2001 yeah it seems weird, i'm just learning about clojure, i was surprised by that, but I think maybe they meant something like this (= [1] '(1)) being true
    @jimka2001 came up when trying to work the examples in the learn clojure docs and comparing to -1, but the Math libraries return -1.0
    Or the fact that the same operator works for both lists/vectors as well as integers
    Peter Morris
    Hi all
    I am doing some benchmarking on the .net Immutable classes. Long story short, I noticed that ImmutableList<T> is a binary tree. I've read that Clojure uses an N-ary tree for immutable lists/arrays and this gives an almost O(1) access time.
    Peter Morris
    I would really love to know what kind of benchmark time Clojure gives for adding/removing etc
    Peter Morris
    I suspect .net is going to perform poorly. Would anyone be willing to give it a try so we can compare?