Fork me on GitHub

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


eliminate it with type hints?


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?

Ngoc Khuat02:11:29

I use this lib : . 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 ..



  (apply juxt fns)) d)


ah sounds good

Lennart Buit09:11:28

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.

👍 1
Lennart Buit09:11:15

(why is it always fire-missles!, who would write a function like that lol)


fire-missiles is good because it can’t be safely retried 😁


...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, 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


is there a way to instantly check if a channel has items? aka <!! returns


with future:

  (future (Thread/sleep 0) :ok)
=> :ok
  (future (Thread/sleep 1500) :ok)
=> :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 "])


interop calls are different from normal functions


oh. Is their a "normal" function for parsing ints from strings?


I think your second code is fine

Alex Miller (Clojure team)14:11:12

Not yet, but it's coming in 1.11!

clojure-spin 8
😍 4
Alex Miller (Clojure team)14:11:31

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

Alex Miller (Clojure team)14:11:54

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?

Alex Miller (Clojure team)16:11:45

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)
;(set! *unchecked-math* false)

;(let [v times-v]
;  (dotimes [_ 30] (time (unrolled v))))

(let [v times-v]
  (cc/quick-bench (unrolled v)))

Alex Miller (Clojure team)16:11:34

I find quick-bench is often unreliable for "fast" operations

Alex Miller (Clojure team)16:11:10

not long enough for jit effects to sort themselves out, same for shorter time operations


(dotimes... report the same

Alex Miller (Clojure team)16:11:19

I often use something like (dotimes [_ 20] (time (dotimes [_ 10000] (op ...))))

Alex Miller (Clojure team)16:11:10

with whatever number for 10000 make something take something in the seconds


so the JIT not kicking in some runs? let me try that

Alex Miller (Clojure team)16:11:22

JIT can take 10000 evals before you get to the final stage of compilation

Alex Miller (Clojure team)16:11:45

and Java clock is maybe only microsecond level resolution (depends on your OS and java version)

Alex Miller (Clojure team)16:11:16

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


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.


Virtualization and other tenants may well affect this too

Dmitrii Pisarenko16:11:33

Hello! I am reading the fascinating book "On LISP" by Paul Graham (available for download at ). 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?

Bob B16:11:38

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


> 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: > ... 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——that teaches LOP as a technique, and Racket as a tool.


the reframe thing wraps cljs-ajax which says it doesn't support files not sure how that manifests, etc


although this shows someone using it to upload files


Hey y'all, I'm a Clojure(and Lisp) newbie, and I'm trying out Clojure using trying to solve: problem_001.clj and I'm getting the following error trying to evaluate the following form:

  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.


How do I "load file"? Do load-file in the repl?


Ah the 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


Ah Load current file and depencies !

👍 1

I see a nil returned too, I'm not sure what that's from tho?


It’s the return value of (tests …)


should that be nil or also a green checkmark?


I’m not sure what you mean?


Thanks for the feedback about load file. I’ve updated 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!


You are welcome!


I'll add the nil to the instructions. 🙏

❤️ 2

did you evaluate the ns form at the top of the file?


I did not 😛


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?


I've tried (quote v) and a few other bits with no avail


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 '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.


I know, I reduced my actual example to the part I was having trouble with 🙂


thanks so much


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)

👍 1

Thanks, I should have been more specific 🙂 I've tried asking in #clojurescript as well, and am making some progress with help there!