This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-09
Channels
- # announcements (3)
- # asami (1)
- # babashka (19)
- # beginners (84)
- # calva (3)
- # cider (5)
- # clj-commons (22)
- # clj-kondo (31)
- # cljdoc (4)
- # cljs-dev (5)
- # clojure (65)
- # clojure-australia (1)
- # clojure-europe (44)
- # clojure-nl (2)
- # clojure-uk (2)
- # clojurescript (18)
- # code-reviews (12)
- # conjure (2)
- # core-async (12)
- # data-science (1)
- # datomic (47)
- # deps-new (1)
- # emacs (2)
- # events (4)
- # fulcro (35)
- # integrant (1)
- # jobs (5)
- # jobs-discuss (10)
- # london-clojurians (1)
- # lsp (13)
- # music (1)
- # nextjournal (1)
- # off-topic (11)
- # parinfer (3)
- # pathom (6)
- # polylith (11)
- # portal (41)
- # re-frame (4)
- # reagent (13)
- # reitit (8)
- # remote-jobs (3)
- # sci (18)
- # shadow-cljs (34)
- # spacemacs (3)
- # tools-build (12)
- # tools-deps (6)
- # vim (2)
- # xtdb (7)
@hiredman yep, that seems to be the most overhead (returns of Object)., the price of dynamism
if you haven't done as @alexmiller suggested yet, you can turn on boxed math warnings and go through an eliminate it, likely to the same degree java would be able to (numbers in an arraylist will box there as well)
coercing the subtraction operands with long eliminated the warnings and seemed to help a bit
What would be the best way to handle url parameters, for example /widgets?color=blue&sort=newest
on frontend/ClojureSript? I'm writing my app with re-frame and using "bidi" + "pushy" which allow me to handle routes just fine but I don't see a way to parse url params nor assign them back in url? What is your prefered way of doing so?
I use this lib : https://github.com/lambdaisland/uri . curious what others ppl use
(and (f1 data)
(f2 data)
(f3 data))
what is a nice way to compose predicates. It's a bit like I'd like to say apply and ..
your own suggestion has different short circuit behaviour: If f3 was like #(fire-missles!)
but f1 was (constantly false)
, with and
and every-pred?
no missles would be fired, but with your juxt
I think they would.
(why is it always fire-missles!
, who would write a function like that lol)
fire ze missiles!
...but i am le tired
I am currently documenting the tests i have in my project. Is there a way i can generate an API documentation of all my tests? I've tried https://github.com/weavejester/codox, but it seems to only generate for everything in src.
what is a simple way to implement a timeout (the only thing I want to do is throttle some behaviour)? Storing a date in an atom?
Simplest way is probably to create a timeout channel and block the thread on it https://clojuredocs.org/clojure.core.async/timeout
with future
:
(deref
(future (Thread/sleep 0) :ok)
1000
:timed-out)
=> :ok
(deref
(future (Thread/sleep 1500) :ok)
1000
:timed-out)
=> :timed-out
Why cant I do this?
(map (comp Integer/parseInt str/trim) ["1 " " 2" "3" " 4 "])
?
It doesn't like Integer/parseInt
, but this works
(map (comp #(Integer/parseInt %) str/trim) ["1 " " 2" "3" " 4 "])
??One of the things I'm working through right now…
It will be really cool. Could you consider built-in trimming and parsing doubles as well : ) ?
doubles will be covered. trimming is a clojure.string/trim away
I'm bechmarking a function, what could cause isolated runs (with either criterium or time
with dotimes
) to report a 30ms mean in some runs and 90ms in others?
garbage collection
or lots of other things that you haven't told us enough to guess at :)
this is all the code
(ns unrolled-benchmark-2
(:require [criterium.core :as cc]))
(def times-v (into [] (take 1e6) (iterate #(+ % (rand-int 1000)) 0)))
;(set! *unchecked-math* true)
(defn unrolled [v]
(loop [idx 0 agg ()]
(if (< idx (- (count v) 7))
(recur (inc idx)
(if (> 1000 (- (long (nth v (+ idx 7)))
(long (nth v idx))))
(cons idx agg)
agg))
agg)))
;(set! *unchecked-math* false)
;(let [v times-v]
; (dotimes [_ 30] (time (unrolled v))))
(let [v times-v]
(cc/quick-bench (unrolled v)))
I find quick-bench is often unreliable for "fast" operations
not long enough for jit effects to sort themselves out, same for shorter time operations
I often use something like (dotimes [_ 20] (time (dotimes [_ 10000] (op ...))))
with whatever number for 10000 make something take something in the seconds
JIT can take 10000 evals before you get to the final stage of compilation
and Java clock is maybe only microsecond level resolution (depends on your OS and java version)
quick-bench is ok on chunkier tests but not enough runs for fast tests
Ok, the weird part is sometimes optimizations kick in and somteimes not, with your method optimizations kicked in the first result, it's taking its time 😉
it's a linux vm with a dedicated CPU (supposedly), no idea if that affects the Java clock
likely so
same results, if it takes 30ms each call would take 30ms for the whole run, same if each call takes ~90ms. Would try again later with real hardware, thanks.
Hello! I am reading the fascinating book "On LISP" by Paul Graham (available for download at http://www.paulgraham.com/onlisp.html ). One of the key ideas is that with LISP you can build a language for your domain, and then build you application using that language. All examples in the book are in Common LISP. Is there a book like this with a "translation" from Common LISP to Clojure?
I'm not aware of a whole book that's 'translated' to Clojure, but Stuart Halloway did a few blog articles where he translates some specific bits from OL: <https://cognitect.com/blog/2008/12/12/on-lisp-clojure>
woo for DSL
> you can build a language for your domain, and then build you application using that language @U02A6THCMBK The book Beautiful Racket is all about such "language-oriented programming". The book's author explains it this way: https://beautifulracket.com/appendix/why-lop-why-racket.html > ... language-oriented programming has risen to become my favorite part of Racket. Along the way, I converted my enthusiasm into action. In addition to making languages, I wrote this online book—https://beautifulracket.com/—that teaches LOP as a technique, and Racket as a tool.
the reframe thing wraps cljs-ajax which says it doesn't support files https://github.com/JulianBirch/cljs-ajax/blob/830b4de47908536ab66c233931d2ca4a4256f576/README.md#formdata-support not sure how that manifests, etc
although this https://github.com/JulianBirch/cljs-ajax/issues/122 shows someone using it to upload files
Hey y'all, I'm a Clojure(and Lisp) newbie, and I'm trying out Clojure using https://github.com/PEZ/rich4clojure trying to solve: problem_001.clj
and I'm getting the following error trying to evaluate the following form:
(tests
solution := true)
; Syntax error compiling at (src/rich4clojure/elementary/problem_001.clj:25:1).
; Unable to resolve symbol: tests in this context
I'm using the Calva Jack-In option with the Rich 4Clojure project type, anyone have an idea what might be going wrong?With Calva, always start with loading the file. Evaluating the ns form should also work, but “load file” is a bit more complete, I think.
Ah the INSTRUCTIONS.md also mention it and I've seen it mentioned a few times too, but I'm not sure what command runs the load-file
or reloads a file
Thanks for the feedback about load file. I’ve updated INSTRUCTIONS.md now. Will have to think about where else this should be made clearer.
> I’m not sure what you mean? So loading the file or evaluating the form gives me a green checkmark and a nil, but from the INSTRUCTIONS, there is no nil, so I don't know if seeing a nil returned is a good 😛:
Also thank you for making an awesome getting started experience, if it wasn't for the lowest entry to trying out clojure ever I probably wouldn't be playing around with it!
I am trying to write a fn to do some introspection to build a map using metadata, and I can't seem to get the symbol passed in correctly :
(defn test1 [v] (ns-publics 'v))
yields no results for :
(test1 'namespace.with.public.fns) yields {}
but in repl
(ns-publics 'namespace.with.public.fns) yields {fn1 #'namespace.with.public.fns, fn2 #'namespace.with.public.fns}
Any clues what I'm doing wrong?When you say (ns-publics 'v)
you are passing a literal symbol v
so you are asking for public vars in a namespace called v
.
You want v
evaluated there so whatever symbol you actually pass in to test1
is used.
dev=> (defn test1 [v] (ns-publics v))
#'dev/test1
dev=> (test1 'honey.sql)
{format-entity #'honey.sql/format-entity, format-expr #'honey.sql/format-expr, ...}
And at this point, you don't need test1
since it is simply calling another function.
hmm, my cljs repl is giving me grief about this:
(defn test1 [v] (ns-publics v))
Encountered error when macroexpanding cljs.core/ns-publics.
AssertionError: Assert failed: Argument to ns-publics must be a quoted symbol
Ah, I didn't realize you're using ClojureScript. I've no idea about that. Namespaces behave differently in cljs.
(even with cljs, macros essentially run as Clojure during the compiler -- I've no idea how cljs REPLs handle macros)