beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
mbjarland 2020-11-05T06:00:35.253400Z

@smith.adriane doh, yes. Thanks for the reality check. You are of course right. Though to @hiredman s point, i went in at 100k and checked the stack and it had only 4 frames with my method...which i suspect is one call with the clojure shenanigans.

đź‘Ť 1
valerauko 2020-11-05T14:01:04.256800Z

I'm playing around with performance tuning and I don't know how to move forward. I'm load testing a script and it has a sensible min and mean. I don't really mind a high max because accidents happen. What I don't know how to deal with is a very high standard deviation. I'm seeing SD two to three times the mean, which considering these numbers are representing the script run time, doesn't sound good. How do I find out what part(s) of the code are prone to underperform in statistically significant ways like that? Clojure/JVM.

2020-11-05T14:38:01.256900Z

You can use a profiler, and/or appropriate Java APIs, to determine whether some of that variation is due to GC being run in some executions but not others.

valerauko 2020-11-05T16:06:42.259100Z

can you recommend a profiler that can show me the "victims" of gc runs?

2020-11-05T17:00:13.259500Z

The YourKit Java profiler can show you in real time when GCs are occurring. I'm not sure what you mean by "victims".

2020-11-05T17:01:11.259700Z

There are Java API calls you can make to query how much total GC time has been spent up to that point in time. You could call that at times in your program's execution that you care to know whether GC occurred between those two times, and subtract the results.

2020-11-05T17:03:51.259900Z

This is a namespace I created for a personal project that contains a macro time that collects elapsed time and elapsed GC time before and after evaluating some expression: https://github.com/jafingerhut/cljol/blob/master/src/clj/cljol/performance.clj

Jim Newton 2020-11-05T17:16:54.263Z

is there a syntax for explicitly prefixing a symbol with the current ns? for example. I have a ns named genus and I alias it to gns when I require it elsewhere. So outside of genus the symbols get prefixed as gns/foo. However, I would love sometimes to also use gns/foo INSIDE the file which defines the genus namespace. especially in rare cases when the project has two different functions of the same name but different namespaces. That would help when i'm navigating with M-. to avoid confusion.

Jim Newton 2020-11-06T10:24:53.272400Z

yes that's the problem I want to avoid.

Jim Newton 2020-11-06T10:28:09.272600Z

if there is a low level function like *, such as when doing low level with with spec. then there are 3 * 's floating around. the normal clojure.core/**, spec/** , and my-local/* ... I'd really like to prefix all three of them within my code. That way when I popping around the different files with the editor, every time i see *, I know exactly which one it is. And this is especially true in the file which defines my-local/*

Jim Newton 2020-11-06T10:29:34.273Z

I'll try out the alias trick. is what you're claiming, @andy.fingerhut, than whenever the ns is required elsewhere, then the alias will have no effect in the other ns?

Jim Newton 2020-11-06T10:40:21.273200Z

seems to work. Great! thanks.

Jim Newton 2020-11-06T13:12:44.278700Z

One small problem I've discovered with this approach is that the alias doesn't allow me to define a function using the / syntax.

(defn rte/match 
  "docstring"
  [a b c]
   ...)
the syntax checker with defn demands that the name be a simple symbol.
Syntax error macroexpanding clojure.core/defn at (rte_construct.clj:401:1).
rte/expand - failed: simple-symbol? at: [:fn-name] spec: :clojure.core.specs.alpha/defn-args

Jim Newton 2020-11-06T13:15:38.279Z

I wonder whether this is an over-ambitious syntax check, or wether it is really fundamentally important to prevent defn from working on qualified symbols. I've noticed that def doesn't have any such restriction. So I suppose I could use (def prefix/name ... (fn [a b c] ...)). I can live with the restriction, but just wondering whether there's really a good reason?

2020-11-06T14:33:12.283900Z

I am personally a bit surprised that def does not have the same restriction.

2020-11-06T14:34:21.284100Z

If you allow the alias or namespace qualifier for def or defn, but only allow it to be used for the current namespace, that is a strange thing to allow. If you allow it for other namespaces, then the idea of the "current namespace" is practically moot.

Jim Newton 2020-11-06T17:18:40.300800Z

@andy.fingerhut i really think it is just an overzealous syntax check. that's my gut feel.

2020-11-06T18:06:30.301700Z

What is the behavior you would expect if a namespace qualifier were permitted?

2020-11-06T18:26:54.301900Z

One implementation detail: defn is a macro in Clojure, and thus can have specs implemented for it do implement these kinds of checks. def is not a macro, and so I believe cannot have Clojure specs implemented for this kind of checking, only checks implemented in the Java implementation of the Clojure compiler. The spec restrictions were added in Clojure 1.9, I believe, about 2 years ago, and were I suspect pretty carefully reviewed by the three main Clojure core developers (Rich, Stu, Alex) before release. (That is my guess -- I wasn't there writing specs with them).

2020-11-06T18:27:33.302100Z

But best way to find out if defn's check is more restrictive than intended is probably to ask in #clojure-dev or #clojure-spec

dpsutton 2020-11-05T17:20:09.263300Z

clj
Clojure 1.10.1
user=> (require '[clojure.set :as set])
nil
user=> [`set/bob `bob]
[clojure.set/bob user/bob]
user=>

dpsutton 2020-11-05T17:20:33.263500Z

just addressing "is there a syntax for prefixing a symbol with the current ns?"

dpsutton 2020-11-05T17:20:50.263700Z

but then you talked about aliases so not sure which you want but this seems to be both

2020-11-05T17:29:41.263900Z

You can use something like (alias 'alias-for-myself 'the.current.full.ns.name) after the ns form. At least that seemed to work with a quick REPL test -- I did not try it within a multi-file project. The doc string for alias does not say that it supports creating an alias to the current namespace, but it seems to work.

đź‘Ť 1
2020-11-05T17:31:56.264100Z

Regarding the case when the current namespace has a function named foo, and another namespace has a function named foo, I think one workable solution used by some is never to use (:use ...), only (:require [full.ns :as alias]), so that whenever you want to call foo in another namespace, it must have either the full namespace or an alias qualifying it.

2020-11-05T17:32:12.264300Z

Then the local foo can always be named without a namespace or alias.

Daniel Ă–stling 2020-11-05T19:29:01.266600Z

Hello 🙂 I have a web page I wish to download, but it has a DOM-manipulating button for “give me all of the page” I need to “click” via code (clojure, not clojurescript), and I’m not sure how to do that best. Any suggestions?

Daniel Ă–stling 2020-11-06T09:47:17.271Z

Thanks, I’ll take a look at that. I also played around a bit with https://github.com/tatut/clj-chrome-devtools a bit

rakyi 2020-11-05T19:58:11.266700Z

maybe https://github.com/igrishaev/etaoin