Fork me on GitHub
#beginners
<
2017-12-19
>
mcall2504:12:59

HEllO. thanks everyone for being on this channel. Does anyone know how to install leiningen on a ec2 instance? I need to set it on its path, import the script, and then make is executable. the help would be appreciated. (i am running linux, ec2 t2 mirco)

jumar06:12:23

I guess it's the same as for every other system. Either follow the instructions (https://leiningen.org/) manually or using some kind of configuration management (puppet, ansible, etc.).

akiroz08:12:02

leiningen is probably available for your linux distro's package manager if you're not using anything too exotic.

Joaco09:12:23

Also you can use SDKman for install/manage differents versions http://sdkman.io/

joshkh12:12:29

i have a clj(s) library that handles the construction and execution of scientific queries via web services. the vast majority of the functions require a data model as their first argument, and the assumption is that the parent application using my library fetches the data model (using the library itself), stores it somewhere, and passes it back to the library with every call. is it entirely against the spirit of clojure to let the library itself fetch the data model and store it in a big honking atom at the top of the namespace? my worry is that every function that references the atom would become impure. reference: https://github.com/intermine/imcljs/blob/master/src/cljc/imcljs/path.cljc#L37

joshkh13:12:47

functions would first check to see if the atom is populated. if not, fetch the asset, then continue.

schmee13:12:56

your worry is justified I’d say. In my experience, having the fetches like that as a side effect makes interactive development harder, it makes testing harder, and it makes reasoning about the code harder

schmee13:12:02

just imagine if you want to run multiple fetches in parallel. with explicit passing another chunk of code can handle the fetching and then pass it to the functions, no problem. how would you solve that with fetching as a side effect?

joshkh13:12:25

good question! i don't know. if func-a and func-b both require the asset, and both are called one after another, then func-b would probably also fetch the model before func-a returned it.

joshkh13:12:05

the library could have a core function that fetches all the assets when called, perhaps.

schmee13:12:36

the question is: what happens when you want to use multiple assets at the same time?

joshkh13:12:49

maybe i'm not understanding the question then. if the atom doesn't contain the key for all needed assets (and yup, there are many assets) then the primary purpose of the function gets paused and a call to fetch the assets is made?

joshkh13:12:40

i think there are advantages and disadvantages for both scenarios. tough call.

schmee13:12:37

@joshkh there always is 🙂 what do you see as the advantages of the atom method?

schmee13:12:03

and to explain what I meant about multiple assets: I understand that there are many assets, but what if you want to use an entirely different set of assets? For instance, you might want to run the code with test or staging assets. Or you might need to use multiple sets of assets at the same time for different parts of the application. If you store all the assets in an atom and fetch them in the functions, you tie these functions to a specific dataset which makes them less flexible.

joshkh13:12:35

i have a much larger re-frame application that connects to many different servers, each with its own data model. those data models end up getting passed all over the place just so they can make their way back to the library that fetched them. there are even cases where the model comes from a dereferenced subscription within a handler (gross, but i guess no different from the library/atom idea). i could make the library itself more complex in exchange for making the larger application less complex. i also want to get some data scientists excited about using the library from a repl, and i'm worried that manually prefetching and managing the assets might scare them away.

joshkh13:12:29

oh, i see what you mean now. that sounds like a nightmare too.

schmee13:12:31

If you want to make it easy for use for your data scientist, you can build the easy-to-use interface with automatic data fetching on top of the functional implementation. you can have a different namespace that wraps the functional one. that way you get the best of both worlds.

joshkh13:12:23

good point. i think you've stopped me from doing a bad thing. thanks for the input. 🙂

schmee13:12:13

anyway, those are my two cents 🙂 as I said earlier, in my experience I have rarely regretted being more functional and more explicit. On the other hand, I have ended up regretting being implicit and relying on too much on side effects for the reasons mentioned

schmee13:12:44

anytime! 👍

joshkh13:12:44

doc strings for anonymous functions. useful?

joshkh13:12:47

(thinking of form 2 reagent components where arguments are collected within the returning function)

joshkh13:12:32

i guess what i really mean is that defn accepts a docstring where as fn does not. i'm assuming that defn's docstring isn't included when the code is compiled, but a string used as a docstring in fn probably would.

manutter5114:12:46

I’m tempted to say a simple comment would work just as well. I know IDEs like Cursive can pick up the docstring and display it when you use a named function, but that’s tied to the name of the function, which of course an anonymous fn won’t have.

joshkh14:12:54

it sure would be nice for an idea to tell me what parameters a reagent component accepts .

New To Clojure17:12:43

What is the recommended logging library for Clojure? https://github.com/clojure/tools.logging seems to be a bit outdated

admay17:12:42

Timbre for me

tbaldridge17:12:37

(it's available as a library separate from pedestal)

admay17:12:09

Pedestal log dependency for those who are looking [io.pedestal/pedestal.log "0.5.3"]

danm17:12:19

I thought pedestal was a webserver?

danm17:12:50

It's certainly timbre that we use

tbaldridge17:12:37

@carr0t Pedestal is primarily a web server library, but there's a lot of useful things that have been broken out into other libraries. For example logging, interceptors, and the routing library. The prefix routing tree in that library is pretty much the fastest routing algorithm in the Clojure ecosystem.

donaldball17:12:28

I use the pedestal logging api as well, and use unilog to configure the logback upon which it runs underneath

debamitro19:12:59

What’s the best beginner-friendly library for desktop GUIs in Clojure?

donaldball19:12:56

seesaw is fairly popular

jedahan20:12:31

I have a single file with two namespaces - is.jonathan.metapng and is.jonathan.metapng.tests. its in the root of this directory. Do I need it to be src/is/jonathan/metapng.clj or define something in deps? what is the current best practice for making my first module

noisesmith21:12:36

@slack1478 in order for require to work, you need the classpath relative path to match the namespace

noisesmith21:12:57

typically src is on classpath (leiningen calls this :source-paths)

noisesmith21:12:48

@slack1478 also the typical convention is to have two classpath entries one for source code and one for tests, which simplifies packaging source separate from tests for example

noisesmith21:12:39

so the typical clojure project with what you have would look kind of like this:

src
  | is
     | jonathan
      | metapng.clj
test
  | is
    | jonathan
      | metapng
        | tests.clj

noisesmith21:12:24

though it would be more common to name the test file metapng_tests.clj and have it in the same relative path (from test vs. src though)

noisesmith21:12:04

then if you run clojure as something like java -cp clojure.jar:src:test:{other-deps} clojure.main you would get a repl where you can require both your primary code and your test file

noisesmith21:12:32

leiningen and boot are tools that automate a lot of this setup by creating a project from a template and auto-calculating your classpath

jedahan21:12:50

yeah i made a boot template for a quil project recently, but after seeing 1.9.0 using deps.edn and packaging clj, I wanted to see what would be the simplist for new users

jedahan21:12:56

especially because this library is so small

jedahan21:12:18

it seems weird to have all those nested folders

noisesmith21:12:38

it’s the only way for libraries to work together reliably

jedahan21:12:41

but the metapng and metapng_tests.clj seem fine

noisesmith21:12:49

how would require know where to look for your namespace?

noisesmith21:12:47

nothing says you can’t use load-file but that’s kind of hostile to anybody else that might try to build on top of your code

noisesmith21:12:07

if you are making a top level tool that you don’t intend for people to extend… it might be worth it maybe

jedahan21:12:12

all it does is have a function to extract metadata from a png filename, and a function to add/modify png chunk metadata

jedahan21:12:26

seems pretty standalone, though maybe thats because i haven't designed it to be composable

noisesmith21:12:26

so, with load-file you can give your file any name or location you like, as long as you can reliably pass the right path to load to clojure on startup

noisesmith21:12:37

usually though one would make a self-contained uberjar that can just be executed directly with java, including all your deps, and in that case it’s still more convenient to make sure your code is findable in an automated way based on the namespace

jedahan21:12:32

So what I would like, ideally, is something like is.jonathan/metapng for what people require

jedahan21:12:41

since it seems that is what I do with other people's libraries

jedahan21:12:56

like quil, then using quil.core and quil.middleware

noisesmith21:12:04

right, and in that case you need a project structure like the tree I described above

noisesmith21:12:14

that’s the only way require knows how to find things

jedahan21:12:27

so whats the difference between . and / ? Anything else change?

noisesmith21:12:41

to call is.jonathan/metapng there needs to be an is/jonathan.clj file, with a defintion of metapng in it, probably a defn

noisesmith21:12:54

for example you can call clojure.core/conj and there’s a file clojure/core.clj on your classpath, with (defn conj ...) in it somewhere