Fork me on GitHub
#beginners
<
2019-08-27
>
alexmiller00:08:41

I think the version on the site is an older version of Clojure, like 1.4 or 1.5 so you may find a few differences like this

noisesmith00:08:42

oh right you can't use transducing arities on 4clojure, I always forget

gonzalo.romano00:08:12

I suspected that, but it doens’t say which version is using, do you guys have any good vids for transducers, read the docs, and watched rich’s video, but i’m having a hard time wrapping my head around how to use/implement them

sy_borg15:08:18

:+1::skin-tone-2:

alexmiller00:08:16

the 95% use case is chaining transducers together with into and comp

alexmiller00:08:17

such that (->> (range 100) (filter odd?) (map inc) (take 10)) can be rewritten w/transducers as (into [] (comp (filter odd?) (map inc) (take 10)) (range 100))

alexmiller00:08:01

the former is lazy, potentially infinite, and makes 3 intermediate sequences

alexmiller00:08:16

the latter is eager (and thus can't be infinite), and does the work in a single pass

alexmiller00:08:06

if you get that much, you can probably defer understanding other uses or how it works for much later down the line

alexmiller00:08:33

and I would not worry at all about implementing your own, that's rarely needed

gonzalo.romano00:08:42

ok, in that sentence the transducer would be this part right? (comp (filter odd?) (map inc) (take 10))

alexmiller00:08:53

yeah - that's just a function, which has the same shape as (filter odd?) or (map inc)

alexmiller00:08:23

that is, essentially a fancy reducing function

gonzalo.romano01:08:00

cool thx, another question, a “stateful transducer” would be a fn like the one on reduce which accumulates the state ??

noisesmith01:08:00

a stateful transducer holds some mutable object (often a volatile) to track internal state that isn't pure / reflected in args and return values

alexmiller01:08:06

for example, partition-all will collect state until it can build and emit a partition

htarashion05:08:42

hi, how can i make two websocket with different path and same port in with http-kit?

badod08:08:26

what JVM supports REBL? I tried to install many with SDKMan but does not work with Caused by: java.lang.ClassNotFoundException: javafx.application.Platform

borkdude09:08:30

Maybe javafx doesn’t come with non-Oracle JVM?

badod09:08:23

It has

================================================================================
Available Java Versions
================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 AdoptOpenJDK  | >>> | 12.0.1.j9    | adpt    | installed  | 12.0.1.j9-adpt      
               |     | 12.0.1.hs    | adpt    |            | 12.0.1.hs-adpt      
               |     | 11.0.4.j9    | adpt    |            | 11.0.4.j9-adpt      
               |     | 11.0.4.hs    | adpt    |            | 11.0.4.hs-adpt      
               |     | 8.0.222.j9   | adpt    |            | 8.0.222.j9-adpt     
               |     | 8.0.222.hs   | adpt    |            | 8.0.222.hs-adpt     
 Amazon        |     | 11.0.4       | amzn    |            | 11.0.4-amzn         
               |     | 8.0.222      | amzn    |            | 8.0.222-amzn        
 Azul Zulu     |     | 12.0.2       | zulu    |            | 12.0.2-zulu         
               |     | 11.0.4       | zulu    |            | 11.0.4-zulu         
               |     | 10.0.2       | zulu    |            | 10.0.2-zulu         
               |     | 9.0.7        | zulu    |            | 9.0.7-zulu          
               |     | 8.0.222      | zulu    |            | 8.0.222-zulu        
               |     | 7.0.232      | zulu    |            | 7.0.232-zulu        
               |     | 6.0.119      | zulu    |            | 6.0.119-zulu        
 Azul ZuluFX   |     | 11.0.2       | zulufx  |            | 11.0.2-zulufx       
               |     | 8.0.202      | zulufx  |            | 8.0.202-zulufx      
 BellSoft      |     | 12.0.2       | librca  |            | 12.0.2-librca       
               |     | 11.0.4       | librca  |            | 11.0.4-librca       
               |     | 8.0.222      | librca  |            | 8.0.222-librca      
 GraalVM       |     | 19.2.0       | grl     |            | 19.2.0-grl          
               |     | 19.1.1       | grl     |            | 19.1.1-grl          
               |     | 19.0.2       | grl     |            | 19.0.2-grl          
               |     | 1.0.0        | grl     |            | 1.0.0-rc-16-grl     
       |     | 14.ea.10     | open    |            | 14.ea.10-open       
               |     | 13.ea.33     | open    |            | 13.ea.33-open       
               |     | 12.0.2       | open    |            | 12.0.2-open         
               |     | 11.0.2       | open    |            | 11.0.2-open         
               |     | 10.0.2       | open    |            | 10.0.2-open         
               |     | 9.0.4        | open    |            | 9.0.4-open          
 SAP           |     | 12.0.2       | sapmchn |            | 12.0.2-sapmchn      
               |     | 11.0.4       | sapmchn |            | 11.0.4-sapmchn      
================================================================================

ghadi09:08:55

Javafx isn't packaged on Java 8 that isn't Oracle or Zulu

ghadi09:08:33

If you want to use REBL on 8, try Zulu

ghadi09:08:51

Otherwise I recommend AdoptOpenJDK 11

badod09:08:54

tried all - the same 🐛

badod09:08:45

So Oracle java 8 should do?

ghadi09:08:35

Did you read the wiki? @badod I'll find a link

ghadi09:08:46

On Java 11 there are a couple add'l steps

badod09:08:11

RTFM worked :face_with_hand_over_mouth: Thank you :relaxed:

badod10:08:49

REBL does not even have *ns* defined. altho in-ns worked...

restenb11:08:36

can anybody help me with clojurescript interop for this? `myElement.attr({ x: position_x, y: position_y });`

gonzalo.romano13:08:12

(.attr myElement (clj->js {:x position_x :y position_y}))

godwin.ko14:08:26

how can I solve “manifest type not detected” error when I try to load a github dependency in my deps.edn?

dpsutton14:08:45

do you control the dependency on github?

godwin.ko14:08:21

nop, but I need the latest commits which fixed a bug that I encounter

godwin.ko14:08:13

there’s no deps.edn nor pom file in the project…

dpsutton14:08:25

tools.deps needs to statically understand the project you're referencing. It needs either deps.edn or a pom file I believe

godwin.ko14:08:55

so the only choice I have is fork it and add deps.edn myself 🤔

dpsutton14:08:14

if its a lein project you can run lein pom i think.

godwin.ko14:08:53

let me try it out, thx a lot

godwin.ko14:08:22

solve the manifest problem after adding a pom file, but still can’t locate the file in classpath 😢

alexmiller14:08:30

you could clone it and refer to it as a local dep

alexmiller14:08:46

and use lein pom to make it workable

alexmiller14:08:06

just a temporary approach, short of cloning

godwin.ko14:08:31

add a deps.edn works

godwin.ko14:08:52

add a pom instead can solve the manifest detection issue, but still can’t find the class

alexmiller15:08:56

class, or namespace?

godwin.ko15:08:25

it complains can’t find xxx.class, xxx.clj, xxx.cljc in the classpath

alexmiller15:08:54

clj -Spath will tell you what your classpath is if that helps track it down

godwin.ko15:08:47

can’t spot anything strange in the classpath, project did checkout under ~/.gitlibs and included in classpath

godwin.ko15:08:13

but since deps.edn works, I’ll stick to it at the moment, many thanks 🙇:skin-tone-2:

gonzalo.romano17:08:45

hi, what should be used to update a map if update is not available?

dpsutton17:08:23

Assoc. or you could copy and defn update

noisesmith17:08:57

the idiom before update existed: (assoc m k (f (m k)))

noisesmith17:08:37

bonus, you can operate on multiple keys in one assoc call

gonzalo.romano17:08:03

right, though I see that update-in does exist, weird, I guess the shorthand was added later

gonzalo.romano17:08:54

question with assoc i need to get the value before if I want to manipulate it right??

gonzalo.romano17:08:07

(f (m k)) right!!!!

noisesmith17:08:10

no, it's immutable

noisesmith17:08:16

so the order doesn't matter

gonzalo.romano17:08:52

I know, but I meant if I'm producing the new value from what was in the key before

noisesmith17:08:31

right, sure, but it's not like you have to order the operations - you want the old value, you read it in the function producing the new one

gonzalo.romano18:08:46

cool, yeah!! thanks!!

ragil.rynaldo19:08:29

hello all, I just curious to know, is it a bad thing if i interop java? is there any best practice to do it (more idiomatic)?

alexmiller19:08:33

interop exists because it is a useful and pragmatic way to leverage the host ecosystem, so IT'S ALL GOOD

ragil.rynaldo19:08:57

wow, thats great! i worried about it sometimes. when some library isn't enough for my purpose, i interop some java library to achieve it, and the big question getting on my head "am i doing good or bad?"

alexmiller19:08:16

you are using Clojure in the way Rich intended :)

alexmiller19:08:34

I will leave you to judge that as good or bad :)

ragil.rynaldo19:08:50

thanks for the feedback 😁

mzavarella19:08:31

@ragil.rynaldo I think you might like this too https://gist.github.com/plexus/645f133fc4c154d1b7497c1b63efdf24 Call it like

(import my.java.thing)

(defwrapper my.java.thing "my-pred")

(apropos "my-pred-") ;; to find the functions now available

ragil.rynaldo01:08:45

awesome! what i've done just plain , no wrapper. but this is good advice to do some interop

mzavarella19:08:50

I do a ton of java interop for my job, we have a futures trading platform written in Java that I interop with a ton. defwrapper has saved me a ton of time

ragil.rynaldo01:08:40

so the point is not "good or bad", but most likely how we achieve our need, am i right?

mzavarella19:08:01

However, I'm very comfortable with the . special form, which I think is important to know so that your fundamentals can still be leaned on when you need them

kevin.zemon22:08:52

Hey guys, in other languages I would avoid doing:

return 5;
preferring instead:
return UNABLE_TO_CONNECT;
The clojure code base I'm currently working in has cases of the former strewn about. Since I prefer not to perpetuate bad habits, is just leaving in a constant value like that the norm for clojure? What is the typical naming convention for const values and where do you put them (separate file, top or bottom of the same file, etc)?

noisesmith22:08:56

all values are considered const unless explicitly shown otherwise

noisesmith22:08:12

if you mean magic numbers, sure, use a def

kevin.zemon22:08:37

Yeah, I mean things like magic numbers/strings

noisesmith22:08:51

(def code-unable-to-connect 5)

noisesmith22:08:01

that's the normal way to do it

noisesmith22:08:20

or (def error-codes {:unable-to-connect 5 ... ...})

noisesmith22:08:29

and then look up the code by name

noisesmith22:08:53

except I wouldn't bother with HTTP codes - I assume anyone qualified to work on http code either knows them or has them ready to look up

kevin.zemon22:08:01

Wouldn't you want (def ^:const unable-to-connect 5) instead? (or the obvious dictionary version)

noisesmith22:08:21

no, that's not what :const is for, and you probably don't want it

noisesmith22:08:44

this goes back to the first point, values are considered const

kevin.zemon22:08:02

In this case I'm wanting to set the return value of -main and I want to attach some meaning to the value instead of having it be a magic number.

noisesmith22:08:21

also there's no obvious dictionary version, the const annotation is not for values that are not primitives

kevin.zemon22:08:25

Right, but I don't need to look them up at run time, this is purely for the programmer.

dpsutton22:08:51

What’s wrong with just deffing the values?

noisesmith22:08:23

but you don't do math on a return value

kevin.zemon22:08:24

Nothing, though for minimal work it is faster.

noisesmith22:08:29

that optimization does nothing here

noisesmith22:08:51

the reason it's faster is the compiler avoids boxing, there's no such benefit for a signal value

kevin.zemon22:08:59

I didn't know if the compiler would already optimize out the reference.

noisesmith22:08:05

which is what I meant by "this isn't what :const is for"

noisesmith22:08:17

it doesn't and also that reference lookup is cheap

noisesmith22:08:28

it's the boxed math that makes things slow

noisesmith22:08:31

you aren't doing math

kevin.zemon22:08:51

It is, and in my current instance its an unnecessary micro optimization, just kind of wondering about best practices.

kevin.zemon22:08:04

So what is ^:const intended for?

noisesmith22:08:24

best practice is to put things in def, and not use unneeded metadata annotations

noisesmith22:08:41

const is meant for values that can be inlined and unboxed in math heavy code

kevin.zemon22:08:05

Is there a high cost for metadata annotations?

kevin.zemon22:08:14

(at compile time)

noisesmith22:08:17

it makes things harder to read

noisesmith22:08:24

(for humans)

kevin.zemon22:08:38

(lol, odd statement from 'noisesmith')

noisesmith22:08:02

TBH when I see ^:const I usually think "this person probably doesn't know what they are doing but wants their code to be faster", but in a perfect world it would be a signal that some value is being used extensively in numeric code

kevin.zemon22:08:53

ok, so I assume I should still avoid the magic numbers and put this in a def. Do you put magic number defs at the top or bottom?

dpsutton22:08:23

In general you need to have things defined before use. You can use a “declare” expression (statement?) but you can run the risk of getting an uninitialized value of the def is used in another def of some other situations. Better to put at the top or perhaps in a config namespace if there are many such values

dpsutton22:08:12

user> 
(declare x)
(def y {:a x})
(def x 3)
#'user/x#'user/y#'user/x
user> y
{:a #object[clojure.lang.Var$Unbound 0x4e3257c4 "Unbound: #'user/x"]}

noisesmith22:08:35

yeah - my usages would usually have a hash-map from name to numeric code in a config or other auxilliary namespace

kevin.zemon22:08:40

Awesome, thanks guys!

mario.cordova.86223:08:08

What is wrong with my project.clj file? I am not getting any errors per-se but I cannot figure out why lein-env is not building out a .lein-env file. None of my environment variables are in the env map. Here is my project.clj file.

mario.cordova.86223:08:20

I run the app with lein with-profile clj,dev

noisesmith23:08:47

I think you want +clj,+dev

noisesmith23:08:09

otherwise you use them instead of the task's target profile, and usually what you want is to merge not replace

mario.cordova.86223:08:37

I've tried running it with +clj,+dev but no .lein-env file is being created.