Fork me on GitHub
#clojure
<
2016-12-01
>
hiredman00:12:28

lein uberjar or running a jar create via lein uberjar?

hiredman00:12:16

DYLD_LIBRARY_PATH is an osx only thing, so lein almost certainly doesn't do anything with it

hiredman00:12:28

are you setting it?

tbaldridge00:12:05

@oliv think about slicing up the problem a bit differently. Currently you've coupled creation of a pipeline add with the execution of the pipeline evaluate. Not a bad design but it is a pattern that already exists in Clojure. In my example, add becomes comp and evaluate becomes into but it could also be transduce or something else like a core.async channel.

tbaldridge00:12:10

With core.async you could do (chan 1 chain-instance-once), which would create a channel that would run your chain of functions against every value that flows through it.

tbaldridge00:12:11

In addition you can now leverage all of the clojure standard library. For example if you only want the first 4 results, you could do:

tbaldridge00:12:43

(into []
     (comp chain-instance-one
                    (take 4))
     (range))

tbaldridge00:12:35

And you could easily mix in, distinct, partition-all, map-cat, etc. All that to say, what you're building isn't "wrong" it's just duplication of effort.

tdantas00:12:35

I see what you are saying. I;m just trying to port my JS solution to clojure. and the usage define how I have to implement. the ideia ( on js ) is to create a Chain instance and append functions inside. once you want to run the Chain you call the evaluate function with the parameters the api is add and evaluate

tdantas00:12:13

var chain = new Chain();
var result = chain
  .add(function timesFour(a) { return a * 4 })
  .add(function timesFive(a) { return a * 5 })
  .evaluate([1,2,3,4]);

tbaldridge00:12:12

exactly, and that's a pattern that exists in JS because in JS you don't have transducers, and JS emphasizes OOP.

johnnyillinois00:12:55

Anyone know of a good plugin to speed up lein boot time?

etherfuse02:12:12

That worked.

lvh04:12:40

@hiredman I’m not setting DYLD_LIBRARY_PATH or expecting it to change, no

lvh04:12:01

you can see the error failing in CI here: https://github.com/lvh/caesium/pull/18

lvh04:12:28

The library I’m getting out of jnr-ffi can — sometimes, and only when creating an uberjar, and only in one particular namespace — not be cast to the interface it’s supposed to be castable to

lvh04:12:31

which makes no sense, I know

lvh04:12:23

It doesn’t break when I eval the same thing in a different ns

lvh04:12:20

the expanded version is:

(do (def bytes "Constant returned by `crypto_scalarmult_bytes`. See libsodium docs." (.crypto_scalarmult_bytes caesium.binding/sodium)) (def scalarbytes "Constant returned by `crypto_scalarmult_scalarbytes`. See libsodium docs." (.crypto_scalarmult_scalarbytes caesium.binding/sodium)) (def primitive "Constant returned by `crypto_scalarmult_primitive`. See libsodium docs." (.crypto_scalarmult_primitive caesium.binding/sodium)))
The final exception is:
Caused by: java.lang.ClassCastException: caesium.binding.Sodium$jnr$ffi$0 cannot be cast to caesium.binding.Sodium

lvh04:12:38

You get that because the sodium var it’s calling that on is annotated to implement that interface

lvh04:12:50

and, of course, it works fine in lein repl or cider

lvh04:12:04

the good news is I might not have to care about this; I tried to build an uberjar by accident

lvh04:12:10

I’d still like to know what’s going on

cjmurphy04:12:34

@etherfuse: How come assoc* rather than assoc? Some special macro meaning for the *, or a different function (to assoc) altogether?

lvh04:12:11

Also, of course, if I remove the type hint it works fine

etherfuse04:12:32

It is essential assoc but with a partial

etherfuse04:12:45

in code unseen

etherfuse04:12:14

(defn assoc*
  [keyw hsh value] 
  (assoc hsh keyw value))

etherfuse04:12:30

I guess I should say, it enables me to use a parital

bbloom05:12:36

is it possible to get the :keys destructuring syntax to do direct field lookup when using record types with hints?

bbloom05:12:56

i’d love for there to be some getfield opcodes instead of calls to KeywordLookupSite, etc

etherfuse06:12:28

can someone explain why the first example works, but the second doesn’t

(defmacro java-setter
  "Creates all the java setters for the java interface"
  [title]
    `(defn ~(symbol (str "-set" (hyphen->camel title))) 
      [this# value#] 
      (swap! (.state this#) ~(symbol (str "with-" title)) value#) this#))
this doesn’t
(defmacro java-setter
  "Creates all the java setters for the java interface"
  [title]
    `(defn ~(symbol (str "-set" (hyphen->camel title))) 
      [this value] 
      (swap! (.state this) ~(symbol (str "with-" title)) value) this))

bbloom06:12:06

@etherfuse syntax quote (the `) isn’t that smart

etherfuse06:12:27

I read about it https://osdir.com/ml/java.clojure.user/2008-03/msg00108.html but I feel like I’ve seen other examples without x#

bbloom06:12:29

it just takes every unadorned symbol and tries to resolve them

bbloom06:12:59

the # prevents resolution and generates a gensym

etherfuse06:12:23

so would adding '[this value] enable it to work. Is it more granular?

bbloom06:12:37

that won’t work either

etherfuse06:12:49

mo macros mo problems

bbloom06:12:59

‘ will just get translated to effectively (quote [this value])

bbloom06:12:25

the readme & linked blog post explain a bit too

bbloom06:12:40

basically, that’s a mini re-implementation of how the ` works

bbloom06:12:30

but the general guideline is that you use the # suffix on local variables that you don’t want resolved

bbloom06:12:01

you can explore this in your repl pretty easily

bbloom06:12:11

just write: `x

bbloom06:12:17

see what happens

etherfuse06:12:55

user=> `x
user/x
user=> `x#
x__1251__auto__
user=> `inc
clojure.core/inc

bbloom06:12:54

you can also break hygiene pretty easily

etherfuse06:12:21

That last one is interesting

achesnais09:12:31

Has anyone used clj-pdf for automatic report generation? It works very well but I’m finding the time to develop a new template involves a lot of iteration/trial error, and I was wondering if there were interesting alternative libraries/solutions/3rd party tools I could use for this?

knjname09:12:51

(defmacro java-setter
  "Creates all the java setters for the java interface"
  [title]
  `(defn ~(symbol (str "-set" (hyphen->camel title))) 
     [~'this ~'value] 
     (swap! (.state ~'this) ~(symbol (str "with-" title)) ~'value) ~‘this))
Ugly ~’.

saeidscorp09:12:43

@achesnais you can always retreat back to the java world!

achesnais10:12:33

😂 not sure if java will make me more productive 🙂 I think my question is more about going a bit more high level than the kind of granularity provided by clj-pdf

poooogles10:12:12

no, but you can use a java library and interop?

achesnais10:12:22

okay – any suggestions on the java library?

akiel10:12:57

I like to generate code with type hints from a macro. The java class is an arg of the macro. I can’t generate reader macro stuff like ^~class or ^{:tag ~class}. with-meta seams to do nothing regarding type hints. What can I do?

joost-diepenmaat10:12:55

with-meta or alter-meta works just fine in macros. your problem might be that you’re not actually seeing the metadata when inspecting the macro output

joost-diepenmaat10:12:03

since it’s not printed by default

kah0ona11:12:51

Question: I am writing a daemon that periodically downloads new csv-files from an S3 bucket. I now need some list that contains the csv-files already processed. This needs to be persisted, since a server restart should not mean that it will re-download already downloaded stuff. The downloaded stuff is merely processed, not stored, so i can't just check if the downloaded file exists. therefore i need some sort of cache/database/storage. Of course i could use some sql database of whatever, but I wonder if there is an idiomatic way in clojure to do this that i don't know of

kah0ona11:12:40

i basically need to be able to look up: has file '20160101.csv' been downloaded

kah0ona11:12:23

(it would be nice if dont need a separate rdbms installed on that box)

niwinz11:12:53

so, just store some plain file

kah0ona11:12:55

or should i just touch empty files and do a file lookup?:)

kah0ona11:12:06

or store it in a plain file indeed

niwinz11:12:43

I'm using something similar on one of my apps, just using a file to persist the atom encoded with transit

kah0ona11:12:45

but then; is it best to just store it in a simple list of filenames, or can i be a bit smarter and save it as some persisted tree

niwinz11:12:09

I can share you a sample code (incomplete) on how I do it

kah0ona11:12:13

because it can become quit a long list (filename is like 20160101_<siteid>&lt;somesubid>.csv

kah0ona11:12:21

aah nice !

kah0ona11:12:24

yeah please do 🙂

akiel12:12:02

@joost-diepenmaat my problem is that I get a reflection warning even if I use with-meta directly

akiel12:12:45

@joost-diepenmaat I solved my problem. I was doing something wrong in the macro.

acron13:12:58

kah0ona I don't think there's an 'idiomatic' way to do what you want; it depends very much on your environment. If having your server write to disk is reasonable then that's perfectly fine, so long as a restart of the server is guaranteed to have access to the same disk.

acron13:12:57

obviously, introducing an external DB insulates you against failure but is more overhead

Aron13:12:24

https://medium.com/chain-cloud-company-blog/a-first-look-at-r3-corda-released-yesterday-7a62a298c43f anyone familiar? does this mean one can write smart contracts in clojure too?

slipset13:12:47

Just got my head around to realise that (or (= “foo” val) (= “bar” val)) can be (better) expressed as (#{”foo” “baz”} val)

slipset13:12:21

Which makes me wonder, is there prior art on using sets as functions?

slipset13:12:34

I guess this something akin to java mySetOfFooAndBaz.contains(val);

slipset13:12:18

but that would probably be more directly translated to (contains? #{”foo” “baz”} val)

mpenet13:12:47

it's a bit everywhere in clojure yes

mpenet13:12:03

or you meant prior art in other languages

pesterhazy15:12:35

it looks like it may apply to your use case

pesterhazy16:12:24

Today I learned that you can force-reload a defmulti foo in a running repl by adding (def foo nil) before it

tbaldridge16:12:39

@kah0ona in the vein of keeping it simple, I'd recommend using EDN via (via clojure.edn) and then just use slurp/spit to read and write the file. Yes the file will get large, but it'll be faster than you expect, if it starts to get too big it's trivial to convert it to some sort of DB.

Aron17:12:38

i was sure this was the right place for my question

slipset17:12:34

@mpenet: I meant in other languages.

tbaldridge17:12:53

@slipset I think the set-as-a-function thing comes from Clojure's view of thinking about what .invoke would mean on almost every type.

tbaldridge17:12:32

For example you can do it with hashmaps ({:a 42} :a), keywords (:a {:a 42}), symbols ('a {'a 42}), etc.

tbaldridge17:12:26

for "prior art" about the only thing I can think of that comes close is Pythons use of .invoke on types being the constructor: ` class Foo(object): def init__(self, val): this.val = val

tbaldridge17:12:39

foo = Foo(42)

tbaldridge17:12:57

but that's not exactly the same.

tbaldridge17:12:35

When you squint at it though, it's a small step from python-esque some-dict[42] to some-dict(42) to (some-dict 42)

tbaldridge17:12:17

So all that to say, I don't think there is prior art in this area, just perhaps iteration on existing ideas.

slipset18:12:57

@tbaldridge: thanks. I guess I'm surprised by how useful this is, and wondering if this was thought of when the language was designed, or if it just a lucky coincidence.

devon18:12:14

Hey guys, noobish macro question, is it possible to define a macro in one ns that defines a -main function in another? eg.

(ns my-first-ns)

(defmacro defmain
  [& body]
  `(defn -main
     [& args]
     (println "I'm a main function that prints my args!" args)
     [email protected]))
(ns my-second-ns
  (:require [my-first-ns]))

(my-first-ns/defmain
  (println "hello world"))

jr18:12:39

You can alter-var-root to swap out the implementation but why do you want to do that?

jr18:12:55

multimethods can be extended from another namespace

devon18:12:31

I have lots of projects where their -main functions contain the same boiler plate and I'd like to have a macro that replaces that

jr18:12:24

(alter-var-root (var my-first-ns/-main)
(fn [args] ...))

jr19:12:06

personally I'd rather implement a :default multimethod that can be defined in the second ns

devon19:12:15

interesting, how would that work?

jr19:12:45

in first-ns

(defmulti -main identity)
in second-ns
(:require [first-ns :as first])
(defmethod first/-main :default [args]
  ....)

devon19:12:05

I'll play with that, thank you!

devon19:12:34

One other thing that seems to work is passing the -main symbol into the macro. eg.

(ns my-first-ns)

(defmacro defmain
  [fn-name & body]
  `(defn ~fn-name
     [& args]
     (println "I'm a main function that prints my args!" args)
     [email protected]))
(ns my-second-ns
  (:require [my-first-ns]))

(my-first-ns/defmain -main
  (println "hello world"))
Not beautiful, but for my use case (which is little less contrived, it works well enough.

jr19:12:01

did you try quoting '-main in the macro body?

roelofw19:12:58

Another question : is code who reads a api to get data that must be displayed also middleware ? or must this be placed in utils.clj ?

artyx20:12:27

Всем привет! Ищу человека, кто может меня научить программированию на Clojure, готов платить деньгами за уроки! Звоните 8 905 225 48 55 <mailto:[email protected]|[email protected]> Сам в Питере нахожусь, но можно и по скайпу .

dpsutton20:12:18

> Hello! Looking for someone who can teach me Programming Clojure's, ready to pay money for lessons! Call 8905225 48 55 <mailto:[email protected]|[email protected]> myself am in St. Petersburg, but it is possible and on Skype.

josh.freckleton20:12:21

how can I trigger a figwheel build of my assets from within (cljs-repl) (without first backing out using :cljs/quit?

futuro21:12:04

Does anyone know what was deficient in nREPL's to drive the creation of Socket Server in 1.8?

tbaldridge21:12:42

@futuro nREPL is a RPC protocol, the idea behind socket server being "just attach a REPL I/O streams to a TCP socket", that then morphed into "why a TCP socket, why not simplify even more?".

futuro21:12:51

@tbaldridge Yeah, nREPL looks to be both a specification for how to talk to a running clojure instance, but also the server implementation that listens for connections, a.k.a tools.nrepl

tbaldridge21:12:52

So the end result is the Socket Server provides a way (on the commandline even) to hook a repl up to anything that accepts an Input/OutputStream

futuro21:12:14

I'm trying to figure out what would need to be done to connect Lumo and Cider

futuro21:12:57

and part of that has been research into nREPL and Socket Server haven't been brought together in some fashion

futuro21:12:24

I've read most of the documentation and all of the source for Socket Server and now I'm going through the nREPL source

futuro21:12:52

It's in a similar vein as Planck

futuro21:12:59

(which I think also has socket server support, but I can't remember)

tbaldridge21:12:33

That may be likely. That's what I like about Socket Server, implementing it for a platform is as simple as opening a TCP connection.

futuro21:12:12

Yeah, it's dead simple

futuro21:12:37

Currently I'd like to see cider and clj-refactor/refactor-nrepl supporting socket servers

futuro21:12:58

Or, more accurately, I'd love to have cider and clj-refactor available for js hosted cljs vm's

futuro21:12:08

cljs host on js vm's*

futuro21:12:21

Anyways, I suspect you get what I mean

etherfuse21:12:43

Is there a favorite/notable HTML parser for clojure? ....subjective i know

futuro21:12:32

To read it in or to create it?

etherfuse21:12:53

in my case I’m testing that a tag in a file contains a certain value

etherfuse21:12:20

so open file, grab h3 class something…does it say pizza

etherfuse21:12:38

currently looking at reaver

futuro21:12:03

that's what I've used in the past

etherfuse21:12:08

great! thanks

futuro21:12:20

turns html into a clojure datastructure

futuro21:12:32

Yeah, it's pretty neat

hiron21:12:12

will parse html->hiccup

slipset21:12:19

@futuro: I know it's not what you're asking for, but inf-clojure-mode works fine with Planck, but of course without the refactoring support.

slipset21:12:08

I hate to admit it, but the static analysis of Cursive has its benefits.

noisesmith22:12:59

@slipset: a minor point from scrollback, (#{foo} x) isn't like contains, it's like get - eg if foo is nil it returns nil if it's found