Fork me on GitHub
#clojure
<
2019-06-24
>
didibus00:06:04

Hum.. it appears I'm failing to make any of them break

didibus00:06:22

Is Xmx respected? or would the JVM go above it if it needed too

andy.fingerhut00:06:28

I am pretty sure that if you exceed the Xmx limit that the JVM will eventually fail a new call, if the process needs that much non-garbage data all at one time.

didibus00:06:57

Hum... I think its because I'm not able to generate distinct fns. It seams this: (repeat 10000 (partial io 10 (rand-str 5000))) will just generate 10000 times the same fn

andy.fingerhut00:06:58

It may very well do GC more often than otherwise for some time before that allocation failure occurs.

didibus00:06:21

Anyway I can create a collection of unique fns ?

didibus00:06:33

So they consume more memory šŸ˜›

didibus00:06:39

I tried (repeatedly 10000 #(partial io 10 (rand-str 5))) but it also seem to generate the same fn

aisamu00:06:42

Consider:

(repeat 1000 (rand-int 10))
(repeatedly 1000 #(rand-int 10))
(race condition!)

didibus00:06:13

I need to generate a seq of FNs

andy.fingerhut00:06:20

repeat should return a sequence of the same object in memory, i.e. many references to one object.

didibus00:06:43

Ya, so I need many reference to copies šŸ˜›

andy.fingerhut00:06:34

The repeatedly expression above will probably only create one anonymous function object.

didibus00:06:03

Ya, that's what happening

didibus00:06:16

Maybe I need iterate

didibus00:06:09

nah, that doesn't make sense lol

didibus00:06:22

Wow, its hard to blow up memory šŸ˜›

andy.fingerhut00:06:34

user=> (map (fn [[x y]] (identical? x y)) (partition 2 1 (repeatedly 5 #(vector 1 2 3))))
(false false false false)

andy.fingerhut00:06:08

The anonymous function returning a vector of 3 elements should be creating fresh vectors each time it is called, according to the results of calling identical? on pairs of them.

andy.fingerhut00:06:53

This variant does return the same object each time:

user=> (map (fn [[x y]] (identical? x y)) (partition 2 1 (repeatedly 5 (fn [] [1 2 3]))))
(true true true true)

didibus00:06:39

Hum.. ya, but the thing is I need to repatedly return a vector returning fn

didibus00:06:22

So I want to end up with a lazy-seq like: [#(io 10 "asdasd") #(io 10 "qqqq") ...]

aisamu00:06:47

I was surprised to see the fn's sharing the underlying class... the closures just became another parameter (a const, but still)!

didibus01:06:07

It seems wtv variant I use, the anonymous function gets shared

didibus01:06:59

You can try it with: (repeatedly 3 #(partial rand-int 5))

didibus01:06:14

I'd like something like that, but each entry returned should be a unique fn

didibus01:06:23

Not pointing to the same memory location

aisamu01:06:41

Repeatedly is not pointing to the same memory location, just sharing the same base class!

didibus01:06:07

Are you sure, because its also not changing the memory profiling at all

andy.fingerhut01:06:41

Because you believe that is what your original problematic code may be doing?

andy.fingerhut01:06:42

You mean, you want a unique fn in order to create a test case that uses more memory, for testing purposes?

aisamu01:06:47

;; (repeat 2 (partial str "fn-" (rand-int 1000)))
Class: clojure.lang.Repeat
Contents: 
  0. clojure.core$partial$fn__5841@4b70e79a
  1. clojure.core$partial$fn__5841@4b70e79a

;; (repeatedly 2 #(partial str "fn-" (rand-int 1000)))
Class: clojure.lang.LazySeq
Contents: 
  0. clojure.core$partial$fn__5841@40a3a985
  1. clojure.core$partial$fn__5841@3a46439e

didibus01:06:04

Oh you're right

didibus01:06:22

ok, so because they shared the same base class, they print the same fn_####

ā˜ļø 4
didibus01:06:23

interesting

didibus01:06:46

Well, it seems I'm failing to make any of them fail. I was pretty sure that a fixedSizedThreadPool would eventually out of memory if you queued up too many tasks since its queue is unbounded

didibus01:06:06

I can't seem to make it happen though

didibus01:06:11

Even with 50mb of Xmx

didibus01:06:37

Hum... maybe my tasks finish quicker then they queue up..

didibus01:06:50

Somehow achieving GC harmony

andy.fingerhut01:06:56

Could be. You could try sticking a sleep 1 second inside of them.

theeternalpulse04:06:30

Using deps.edn, If I don't have a "main" class, how can I run an arbitrary function in my classpath? In my case in my app namespace (not a genclassed namespace) I have two functions, one for "run-server" and "run-dev-server" and I want one alias to run my-ns/run-dev-server and the other run my-ns/run-server

seancorfield04:06:24

@theeternalpulse You can use the -e option to run any Clojure expressions.

theeternalpulse04:06:08

I have something like this in my alias :dev-server {:main-opts ["-e" "()"]}

seancorfield04:06:32

clj -e "((requiring-resolve '))"

seancorfield04:06:52

You need to require the ns before you can use it.

theeternalpulse04:06:08

ok got it workign with :dev-server {:main-opts ["-e" "(require,'[,:refer,[run-dev-server]]),(run-dev-server)"]}

seancorfield04:06:18

@theeternalpulse Are you not on Clojure 1.10?

seancorfield04:06:54

What I suggested above will work on Clojure 1.10.

theeternalpulse04:06:24

let me update my deps, i'm using RELEASE

seancorfield04:06:24

(but wonā€™t work on earlier versions)

seancorfield04:06:48

"RELEASE" should bring in 1.10.1 at this point.

theeternalpulse04:06:49

I htought resolving-require was your way of saying to use the require statement šŸ™‚

seancorfield04:06:01

requiring-resolve is a core function.

theeternalpulse04:06:16

let me see what's going on

seancorfield04:06:05

:dev-server {:main-opts ["-e" "((requiring-resolve,'))"]}
to match what youā€™re actually trying to do.

theeternalpulse04:06:41

ah, earlier you wrote resolving-require

seancorfield04:06:03

The nice thing about requiring-resolve is that a) itā€™s all-in-one b) itā€™s thread safe. Oh, sorry, was typing on the small screen.

seancorfield04:06:07

Will edit that. Fixed.

theeternalpulse04:06:58

very nice works like a charm

theeternalpulse04:06:09

glad I watched your deps video or the commas would have got me

seancorfield04:06:18

The ā€œCorfield Commaā€? šŸ™‚

theeternalpulse04:06:26

in the future will it accept regular edn?

seancorfield04:06:41

, is whitespace ā€” even in EDN I believe?

seancorfield04:06:12

At some point I expect a fix will be figured out. Itā€™s a hard problem. You should see what you have to do on Windowsā€¦ :shocked_face_with_exploding_head:

seancorfield04:06:34

Found the cmd-invoking-powershell example ā€¦

powershell -command 'clj -Sdeps "{:deps {viebel/klipse-repl {:mvn/version """"0.2.3""""}}}" -m klipse-repl.main'

theeternalpulse04:06:50

it's not too bad, since I can just make a task function

seancorfield04:06:14

Ah, yeah, here we go ā€œCommas , are also considered whitespaceā€ ā€” https://github.com/edn-format/edn#general-considerations

seancorfield04:06:44

So it is regular EDN already šŸ™‚

theeternalpulse04:06:36

true, I guess I meant something that could be parsed inline wiht edn so you can do :dev-server {:main-opts ["-e" '((requiring-resolve '))]}

theeternalpulse04:06:50

no biggie, just curious

pinkfrog06:06:23

iā€™d like to build a website. is there any battery-included framework so I can reduce the development time?

gklijs17:06:35

I'm kind of busy with something as a pet project. The idea is to run the app locally, you can log in, upload photo's, create documents. And it can spit html in such a way it integrates nicely with Netlify. It's mostly on hold now because it's using spec a lot, also to generate the HTML/js. So want spec 2 to stabilize before going further.

Lennart Buit06:06:54

there are a few

Lennart Buit06:06:27

depends a bit on what you want, do you want to do a single page app, and therefore want a way to build APIs, or do you want a html-spitting webserver šŸ™‚

pinkfrog06:06:29

for example, the framework provides an admin panel by default

pinkfrog06:06:36

an spa may suffice.

Lennart Buit06:06:52

Iā€™ve seen this being recommended: https://github.com/coast-framework/coast, but I donā€™t think that provides an admin, its also of the ā€˜htmlā€™-spitting kind (although you are free to not do that)

seancorfield06:06:06

@i Clojure really isn't about "battery-included framework" websites. I don't think Coast or Edge will be close to what you're looking for -- but that's not Clojure's strength TBH.

pinkfrog06:06:24

i am in search of something like django but is in the clojure land.

seancorfield06:06:28

There are some fairly comprehensive templates tho'...

pinkfrog06:06:41

is luminus a general way to go?

seancorfield06:06:43

There's no CMS systems in Clojure, as far as I know.

Lennart Buit06:06:45

ah yeah, I was instantly reminded of django when you asked

seancorfield06:06:28

Luminus might be the closest, in terms of templates. Uses Selmer by default (inspired by Django). Still not anything close to a CMS tho'.

pinkfrog06:06:27

do you mean i have to build an admin panel from scratch? no such component exists?

seancorfield06:06:57

I would not expect to find such pre-built components in the Clojure world.

pinkfrog06:06:43

i see. Iā€™d first go with luminus.

seancorfield06:06:25

If I wanted a CMS for a site, I'd go with Wordpress/Django/Joomla/etc as a packaged solution. I see no point in building such a thing myself...

šŸ‘ 4
p4ulcristian11:06:59

hello guys, how do I convert curl -d 'measurement,tag1=value1,tag2=value2 field1=123,field2=1.23' -X POST '' to the clj-http library (client/post "" ...) ?

helios11:06:06

you can write the params as the body or using form-params, check: https://github.com/dakrone/clj-http#post

p4ulcristian11:06:28

I tried it like this (client/post "" {:body "measurement,sensor=hello paul=45 1560969836000000000"}) but I got Execution error (ExceptionInfo) at slingshot.support/stack-trace (support.clj:201).clj-http: status 400

helios12:06:32

As a clojure map šŸ™‚ {:body {:sensor "hello"}}

helios12:06:52

Try with :measurement true

p4ulcristian13:06:23

the problem is, that it's influx inline protocol, every comma count, and the timestamp at the end aswell. So I would need to send this in string, is this possible?

tavistock14:06:40

the urls are different in your curl and clj-http example

šŸ‘ 4
p4ulcristian14:06:13

yes, this is right, I forgot my timestamp from the first example. But anyway, is it possible to send my request in a string form, without using a map?

helios14:06:01

the 400 seems to suggest an error sent by the server, rather than stemming from the client. I'd suggest you print out the request from the server and compare the request from curl vs the one from clj-http. As a tip you can add :throw-entire-message? true to the options map of the request to see if the response had more of a message for that 400

p4ulcristian15:06:54

Thank you very much, tavistock saw my real problem, I mistyped the url... so amateur mistake. (http/post "" {:body "this is a test"}) this was the good solution, thank you very much.

Eric Scott16:06:25

Hey is there a standard nomenclature for the function that gets passed into reduce? 'Aggregator' doesn't seem quite right.

Alex Miller (Clojure team)16:06:42

it's usually called a reducing function :)

Suni Masuno16:06:14

In the greater functional world I hear "reducer" a lot. ĀÆ\(惄)/ĀÆ

noisesmith16:06:56

in clojure, reducers are a specific thing https://clojure.org/reference/reducers

Suni Masuno16:06:27

Neato, thanks! ^_^

noisesmith16:06:40

both clojure.core/reduce and the clojure.core.reducers are about doing the thing general fp calls "reducers", but inevitably we have more specific concrete details beyond what that implies in the theory world

Eric Scott17:06:34

Actually 'aggregator' seems to me like a better description of what a reducing function does, but it's good to know the standard terminology.

ghadi17:06:32

Java's Stream calls it the accumulator function

ghadi17:06:13

(Clojure's reduce precedes Streams though)

Eric Scott17:06:29

I thought the accumulator was the value that's returned by reduce

ghadi17:06:32

and "accumulator" is often the first argument to the reducing function

ghadi17:06:43

(fn [acc input] ....)

noisesmith17:06:44

if we were to be pedants about grammar, it's surely the accumulated object, not the thing performing the accumulation

Eric Scott17:06:18

Yeah, but isn't there part of a CPU called the accumulator? My sense is that it's a call-back to that.

noisesmith17:06:33

yeah - it's a historical name