Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Eugene Pakhomov
    @p-himik

    @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

    Answers:

    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
    YuriMostardeiro
    @YuriMostardeiro
    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
    @p-himik
    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
    @mcferren
    how to reduce in reverse so to iterate from the last index and on through until the 0 index?
    Eugene Pakhomov
    @p-himik
    @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
    @beenotung

    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))

    1.png
    Beeno Tung
    @beenotung
    1.png
    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
    @p-himik

    @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
    @willemsh_gitlab
    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
    @p-himik
    @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
    @jorgetovar_gitlab
    Hello everybody ... Im exploring Clojure and I really love it
    but whats the best practice for error Handling in clojure???
    try catch?
    Eugene Pakhomov
    @p-himik
    That's an incorrect question. Some good insights here: https://clojureverse.org/t/is-error-throwing-bad-functional-programming/2188
    Viet Vu
    @vietvudanh
    Eugene Pakhomov
    @p-himik
    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
    @vietvudanh
    Thanks Eugene, I got it!
    Aviraj Khare
    @avirajkhare00
    Clojure is very hard :(
    I am unable to pick it up
    Eugene Pakhomov
    @p-himik
    Try reading the second edition of SICP.
    Aviraj Khare
    @avirajkhare00
    ok
    tami5
    @tami5

    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
    @bmarwell
    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!
    Felix
    @leobm_twitter
    @bmarwell I would ask here:
    https://clojurians.slack.com
    I think most of the Clojure community/developers are on slack
    Benjamin Marwell
    @bmarwell
    cannot access that link @leobm_twitter
    Jonathan Beebe
    @jonbeebe
    does anyone have experience with luminus?
    re: application profiles, can those be added to existing projects? If say later you want to add something
    littleworker
    @littlebot:privacytools.io
    [m]
    oh, not so hot as scala does
    does anyone have experience with vertx?
    alphataur
    @alphataur

    hello everyone.

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

    Thanks

    Jim Newton
    @jimka2001
    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
    @ianjosephwilson
    @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
    @mrpmorris
    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
    @mrpmorris
    I would really love to know what kind of benchmark time Clojure gives for adding/removing etc
    Peter Morris
    @mrpmorris
    I suspect .net is going to perform poorly. Would anyone be willing to give it a try so we can compare?