Fork me on GitHub
#clojure
<
2019-09-28
>
the2bears16:09:48

@veix.q5 try ((wrap dedupe) [1 1 2 3 3 4])

the2bears16:09:02

In your code you end up calling 'wrap' with the result of a no-arg call to dedupe.

quadron16:09:25

@the2bears wrap expects a transducer and returns a transducer

the2bears18:09:13

Ah, my bad, I hadn't had my coffee yet and was using my brain as a repl 🙂

leonoel17:09:54

@veix.q5 the reducing function returned by the dedupe transducer is stateful. The reducing function returned by wrap rebuilds a new transducing chain for each reducing step, so the previous state of dedupe is lost

✔️ 4
💡 4
emccue17:09:38

How would i test code like this with something like clojure.test?

emccue17:09:05

I want to spin up a socket server and actually try sending messages to it then shut it down

emccue17:09:22

but i cant kill a thread on command so im a bit at a loss on how to go about that

lukasz19:09:24

@emccue can you store the server-socket or (.accept server-socket) in an atom? Then you can start it, do tests and call (.close @socket) on it when done

lukasz19:09:24

alternatively, this is where things like Component make things easier, as you'd create a component for the socket server and your -main is only responsible for starting the system and holding on to it (or storing it in an atom in the core namespace)

lukasz19:09:28

@emccue also, this might be helpful - our Statsd client ships with a UDP server based on Aleph, and we're using it to verify that the client is sending the right metric data: https://github.com/nomnom-insights/nomnom.stature/blob/master/test/stature/statsd_test.clj#L13

emccue19:09:25

@lukaszkorecki at least in the way the code is, it's a blocking thing

emccue19:09:40

So if I run my socket accept then I can't do more

emccue19:09:57

And if I offload it to a thread then I don't know how to impl the stop

emccue19:09:10

Does that make sense?

emccue19:09:47

I could put the sockets into some global registry

emccue19:09:00

That does make sense

lukasz19:09:01

Yep, then your option would be to wrap the accept call in a future and use callbacks when receiving / writing to a socket

lukasz19:09:16

and then (.close @socket-future)) to close it

lukasz19:09:39

or use Aleph 🙂 it implements the socket server too and is slightly easier to manage than Java classes

kulminaator20:09:45

i think there's something off with the clojure package that is out there for ubuntu people .. running it just on it's sure does start the repl ... but it totally seems to ignore the deps.edn file and doesn't do any of the -A handling

kulminaator20:09:37

installing the clojure with the installation script from https://clojure.org/guides/getting_started however seems to behave in expected ways

kulminaator20:09:07

discovered the difference in behavior by accident, was checking out clojurl as a graalvm native-image example (as i had trouble getting native-image running with just snap of my fingers) and bashed my head for 5-10 minutes before i figured out that the "clojure" i had ... wasn't really the clojure that the readme examples expected it to be

seancorfield21:09:59

@kulminaator That predates the CLI/`deps.edn` stuff by quite a while and it's just a small wrapper to running scripts or starting a REPL.

seancorfield21:09:23

There's a few "rogue" packages out there on various platforms that are like that and predate the CLI/`deps.edn` from Cognitect. Windows has clojure on Chocolatey I think that is about the same as what you mention on Ubuntu...

kulminaator21:09:21

well ... can we help the package managers out with more up to date samples ?

kulminaator21:09:12

the weird part is that the clojure version in the package is new, it's just the shell wrapper build up that seems to be wrong

kulminaator21:09:43

it has clojure 1.10 under the hood but all the wrapper seems to do right now is end up with invoking this exec $rlwrap java -cp /usr/share/java/clojure-1.10.jar"$extra_classpath" clojure.main "$@"

seancorfield21:09:27

@ehashman Probably has some insight into how/when that package came into existence (the bionic/clojure page lists her as maintainer and I remember her talking about that work ages ago).

Alex Miller (Clojure team)21:09:47

I don’t think they’ve had time to integrate the new Clojure stuff yet in the Debian packages

Alex Miller (Clojure team)21:09:47

They build everything from source and there a ton of downstream deps (Maven) that all need to be bundled too

seancorfield21:09:17

Yeah, I recall Elana saying it was a very involved, elaborate, and slow process.