Fork me on GitHub
#beginners
<
2019-05-08
>
bartuka02:05:38

I can't access the code standards for libraries in Clojure. There's any other link about that?

dpsutton03:05:06

what do you mean code standards @iagwanderson

bartuka03:05:43

something like the clojure style guide but for building libraries

bartuka03:05:02

there is a link inside the clojure style guide for that documentation but it's not working right now

bartuka03:05:20

503: This site is currently undergoing maintenance. We apologize for the inconvenience.

alexmiller03:05:03

If it’s the contrib style docs, that’s moved

dpsutton03:05:58

(that's the broken link i mean)

dpsutton04:05:25

I edited the page with their web UI and now there's a "proposed file change" somewhere ¯\(ツ)

dpsutton04:05:23

yeah i did my ui change and came back to see you had done it as well 🙂 except you used the anchor tag as well

dpsutton04:05:27

so its better

dpsutton04:05:40

i just don't know how to rescind mine lol

bartuka04:05:51

thanks for the directions

Mattias08:05:59

I find myself traveling without internet access - are there any downloadable documentation resources? I’m thinking api doc, cheat sheet, etc. I’m learning 😅

Mattias09:05:23

Looks fantastic, I’ll give it a go 😀

Mattias09:05:14

Very cool functionality. I’m confused on as how to download the Clojure 10.0 docs, any specific help there? 😋

art09:05:02

Better to go with Dash then, https://kapeli.com/dash

noisesmith17:05:30

also clojure.repl/doc clojure.repl/apropos clojure.repl/find-doc clojure.repl/source are all very useful - much of clojure and its library ecosystem are self-documenting in a repl

Jivago Alves09:05:57

Greetings, folks!

Jivago Alves09:05:34

Just curious about what’s the usual libs you use for mocking if any. I’m asking in the context of testing side-effects of code in an isolated manner (writing to DB or making http reqs). I found https://github.com/bguthrie/shrubbery which seems what I was looking for (not sure if it’s in active dev). Any other recommendations? Thanks!

Jivago Alves09:05:47

Please feel free to reply here. It’s easier to concentrate the answers.

art10:05:59

Not sure if you even need stubs. I simply reify what’s needed.

(defprotocol IDescriptive
  (-describe [this id]))

(defn describe
  [impl id]
  (-describe impl id))

(describe
  (reify IDescriptive
    (-describe
      [this id]
      {:user/id "foo"
       :user/email ""})))

Jivago Alves12:05:44

@UBUSQN7RQ Nice. I have used reify before for stubbing too but I’m interested in mocking in the sense I’d like to set expectations on fn calls and its args.

mloughlin10:05:08

is there an easy way to interrogate a dependency library for its namespaces, from the REPL? I just realised I've been going and looking it up the long way

noisesmith17:05:23

(System/getProperty "java.class.path") gives a string with all the currently available jars, a jar is a zip file that you can unpack and examine, many editors (arguably all ones worth using for code) can directly open a zip file and let you browse it like a directory

noisesmith17:05:23

from there you can find all the .clj files etc. in the artifact

noisesmith17:05:57

you can also use interop to get a stream of resource names that are in a jar; this isn't even complete because namespaces don't have to match up 1:1 with resources, but they should

mloughlin10:05:58

I'm using lein if that matters

jaihindhreddy11:05:43

^ Unfortunately no. There is no reliable way to get namespaces from artefacts. Rich even joked about it in Spec-ulation, "Somebody on the street tells you, did you try this jar? I has fred in it" There may be some programmatically accessible API somewhere that gives you this information but ultimately a human has to put it in.

mloughlin11:05:51

that's a shame but thanks for your help

alexmiller11:05:49

Rich and I have talked about this issue at length. I think it is one of the biggest gaps in the Maven repository story. At some point we may try to do something about it for Clojure but we have not found any easy answers.

skykanin11:05:27

So I'm trying to access a var in the namespace backend.core from a different namespace backend.routes.config but for some reason I get the error java.lang.RuntimeException: No such var: backend.core/config

dpsutton12:05:29

presumably backend.core starts with a (ns backend.core ...) form. Are you requiring [backend.core :as backend.core] in backend.routes.config?

skykanin12:05:11

no, and I can't either. It would cause a cyclic dependency

dpsutton12:05:47

maybe pull the config out into its own ns and have core and routes.config both depend on it?

skykanin12:05:52

I think I might have to intern the var instead

dpsutton12:05:10

i'm not sure i follow

skykanin13:05:42

ok, so I'm reading in cli options in -main and I need to expose that config file to other parts of the system. A way I could do that is by interning the var to backend.routes.config from -main

skykanin13:05:15

(intern 'backend.routes.config 'global-cfg cli-cfg) like this

dpsutton13:05:56

this doesn't seem like a good way to go

skykanin13:05:31

what should I do instead then

dpsutton13:05:50

make a separate ns with that info and have whichever namespaces depend on it do so

skykanin13:05:45

ok, I'll try that

skykanin13:05:33

It worked, thanks!

alexmiller12:05:58

I think it’s confusing to have aliases with .’s in them

dpsutton12:05:45

it looks like a fully qualified var at that point?

kari12:05:08

I guess there is no way to add environment variables to aliases in deps.edn as you can do in Leiningen since I didn't find anything like that in the deps.edn documentation? Can you recommend some Clojure library that reads configuration from some file (edn, properties...) and I can ask certain property and the library first checks if the environment variable exists, and if yes returns the value, if not then tries to read the property from the file.

kari12:05:46

Thanks. I read the README. How is maailma different from aero?

valtteri12:05:42

No idea, I’ve never used aero myself. It looks like almost every “bigger author” have their own environment variable lib. 😅

kari16:05:32

Yep. 🙂

kari13:05:11

Environ README says nothing about reading config from file and merging it with environment variables.

valtteri13:05:24

Yep, sorry I remembered wrong that environ could read EDN config files as well. My bad.

ben13:05:00

iirc, luminus uses cprop for this:

(ns my-project.config
  (:require [cprop.core :refer [load-config]]
            [cprop.source :as source]
            [mount.core :refer [args defstate]]))

(defstate env
  :start
  (load-config
    :merge
    [(args)
     (source/from-system-props)
     (source/from-env)]))

kari13:05:21

Thanks. Maybe I check cprop as well.

kvlt17:05:51

Stupid question. Using CLJS i'm trying to send a file to my server using transit. I'm getting the following error:

Uncaught Error: Cannot write File
Cannot write File
    at Object.writer.marshal (writer.js:447)
    at Object.writer.emitMap (writer.js:319)
    at Object.writer.marshal (writer.js:439)
    at Object.writer.marshalTop (writer.js:471)
    at Transit$Writer.writer.Writer.write (writer.js:501)
    at cognitect$transit$write (transit.cljs?rel=1557151648550:278)
    at ajax$transit$transit_write_fn_$_transit_write_params (transit.cljc?rel=1557151648575:17)
    at ajax$interceptors$apply_request_format (interceptors.cljc?rel=1557151648359:150)
    at Object.ajax$protocols$Interceptor$_process_request$arity$2 (interceptors.cljc?rel=1557151648359:161)
    at ajax$protocols$_process_request (protocols.cljc?rel=1557151648127:32)
I think its down to how the file object is being encoded but I cannot find much information around this

hiredman17:05:52

transit doesn't know how to encode the File object you are passing it

hiredman17:05:45

https://github.com/cognitect/transit-cljs#default-type-mapping are the types transit-cljs knows how to encode out of the box

kvlt17:05:38

@hiredman: thank you. I did actually see that, essentially I'd need to figure out my own way of encoding/decoding this?

hiredman17:05:06

I would start by not trying to serialize a File

hiredman17:05:44

a file is sort of a pair of some data and some name for that data on some filesystem

hiredman17:05:37

the place when you send the data likely doesn't have the filesystem context there, so sending a file is kind of meh

hiredman17:05:01

so instead send a pair of a name and some data (maybe some kind of array, I don't really do much js or cljs so I don't know what the best type for a collection of binary data is)

kvlt17:05:26

Oh man, I had expected that this would be a pretty typical usecase. I'm surprised at how much is about to be involved

john19:05:54

I don't think you'd serialize a file in the JS either though. Just send it off as binary.

kvlt16:05:39

I mean, I'm not suggesting serialization. Binary makes more sense. I think lots of objects wouldn't have serialization methods. I think I am more disappointed that it doesn't come out of the box with support for a really common usecase

gklijs17:05:14

https://github.com/nginx-clojure/nginx-clojure has a websocket allowing text or binary, was real easy to set up, and get images from the front-end to the back end.

kari18:05:47

I used mount (https://github.com/tolitius/mount) and cprop (https://github.com/tolitius/cprop) to implement the application state and configuration handling in my new Clojure study project. I was amazed how incredibly easy and clean the implementation was. I can strongly recommend both libraries for beginners. I only now realized that both libraries are made by the same person. Thanks @tolitius!

joelsanchez18:05:22

just realized that mount and cprop have the same author. I use them, too. thanks 🙂

dadair22:05:25

Hi, I have what should be a fairly simple macro question (man I really struggle to actually understand how to construct macros…). I have the following code:

(defmacro defx
  [id form]
  `(defmethod x ~id [_]
     (quote ~form)))

(defx "foo" (s/keys :req-un [::a ::b]))
;; Call to clojure.core/fn did not conform to spec (reason: "Extra input")
The macro is silly for now, but I’m going to extend it. I believe the error is due to the _ in the arglist, but I can’t seem to make it work. Can anyone see what I’m doing wrong here?

mtkp22:05:20

i think you might need _# for the arg in your macro

andy.fingerhut22:05:26

I believe that something like that is true for any parameters inside of a syntax-quoted expression -- if you do not do something like name# it will be qualified with the name of the current namespace, e.g. , and I don't think Clojure supports that for a parameter name.

mtkp22:05:37

name# is shorthand for gensym, and is almost always what you want (so you don’t shadow or redef any existing vars). however you can explicitly specify a symbol if you really want to (e.g. ~'_)

dadair22:05:04

Yep, that did the trick! Thanks 🙂

dpsutton23:05:23

can't you do '_ as well?

noisesmith23:05:38

that gives you (defmethod x id [(quote _)] ...) which is an error

noisesmith23:05:52

nested quotes are not idempotent, thus the quote/unquote combo

yuhan23:05:40

Generally you can always use macroexpand to see the expanded form, that usually gives a better clue of what the error is

yuhan23:05:02

user=> (macroexpand '(defx "foo" (s/keys :req-un [::a ::b])))

(. user/x clojure.core/addMethod "foo" (clojure.core/fn [user/_] (quote (s/keys :req-un [:user/a :user/b]))))

seancorfield23:05:44

(defmacro defx
  [id form]
  `(defmethod x ~id [~'_]
     (quote ~form)))
~'_ will macro-expand to the raw _ symbol.

seancorfield23:05:37

Oh, hah... @matt.kipps already edited his answer to mention that.

seancorfield23:05:48

What I saw in Zulip:

**matt.kipps:** not necessarily. `name#` is shorthand for gensym, and is almost always what you want (so you don’t shadow or redef any existing vars). however you can explicitly specify a symbol if you really want to…
🙂

😁 4