Fork me on GitHub
#beginners
<
2020-05-16
>
Timofey Sitnikov12:05:48

Hello Clojurians, do all of the :aliases function calls in deps.clj have to dispatch through -main via :main-opts, or is it possible to add a function in the namespace and call that function directly. I see that it is possible using lein something like;

{:aliases {"migrate"  ["run" "-m" "investtrack.scripts.migration/migrate"]
            "rollback" ["run" "-m" "investtrack.scripts.migration/rollback"]}}
Can something like that be done in deps.clj :aliases map? Or you just have to live with dispatching via a -main function?

Alex Miller (Clojure team)14:05:19

You can pass the name of a clj file to just load it and run the top level or use -e to evaluate an arbitrary expression

Alex Miller (Clojure team)14:05:56

The latter can be combined with requiring-reslolve to do what you want

Alex Miller (Clojure team)14:05:10

clj -e “((requiring-resolve ‘some-ns/some-fn) some-args)”

Alex Miller (Clojure team)15:05:03

You can put that in an alias but if you do, replace the spaces with commas in the expression (commas are white space but won’t get messed up by bash word splitting)

mauricelc9218:05:53

Hey all 👋 Begun learning Clojure last week……Starting off with the Brave book and a few 4clojure problems…..Wanting to contribute to #athens in a few weeks

👋 20
Adrian Smith19:05:50

any troubles let us know, athens seems like a really cool project

mauricelc9219:05:52

Awesome, thanks Adrian 🙂

practicalli-johnny10:05:39

Be careful if you use the Emacs setup it definites, it's quite out of date now. https://docs.cider.mx/cider/index.html is an up to date guide for Clojure in Emacs. If you want a curated Emacs setup, then try https://practicalli.github.io/spacemacs/ Or there are several other editors you can use https://practicalli.github.io/clojure/development-tools/

mauricelc9214:05:02

Thanks @U05254DQM! I am currently using Cursive and have my VS Code set up with Calva

Cas Shun21:05:29

I need to utilize an InputStream to .read a number bytes, a fixed (large) number of times, to a clojure vector. I'm aware of a number of ways to do this, but I'm curious if there's a particular idiom and/or a method with the least overhead. I've been benchmarking various solutions and it's driving me crazy.

hiredman22:05:00

Don't read a byte at a time, use the arity that takes a buffer to fill

hiredman22:05:01

I am not sure exactly what you mean by reading bytes to a clojure vector

hiredman22:05:28

A clojure vector is not the most natural place to put individual bytes because of boxing. Depending on what is being done a nio bytebuffer or netty bytebuf can be very nice if mutable. There are some specialized versions of clojure vectors that avoid boxing

Cas Shun23:05:57

@hiredman which 'specialized versions of vectors'?

hiredman23:05:57

Look for gvec and vector-of

hiredman23:05:58

I have never used those

hiredman23:05:12

I have used various bytebuffer things a fair bit, and sometimes even used bitsets or byte arraya wrapped in bigintegers

hiredman23:05:03

It depends a lot on what you are ultimately doing with the bytes

hiredman23:05:12

You can also use randomaccessfile to memory map files, where those memory mapped views act like bytebuffers

hiredman23:05:54

(which may be the fastest way to get bytes from disk into memory, not sure)

Cas Shun23:05:37

ok, cool. This is more info than I had before

Cas Shun23:05:53

I wasn't aware of boxing as a concept at all, so that's going to be a good start 🙂

hiredman23:05:23

(actually you need a filechannel to map, which you can get a few places not just a randomaccessfile)

hiredman23:05:11

The jvm has some small number of built in types (called primitives) that are not reference types, and everything else is a reference type. So any kind of generic code will usually deal in reference types, which means the primitives need to get boxed (turned into instances of a reference type).

hiredman23:05:20

So for example the default way functions work in clojure is generic, which means it is defined in terms of a reference type, which means passing a primitive as an argument will box it.

Cas Shun23:05:44

I see, thanks. I'll research more about it