Fork me on GitHub
#beginners
<
2019-04-23
>
pythonjokeun03:04:41

If i understand correctly comp can be substituted with ->, so when to use comp?

seancorfield04:04:06

@pythonjokeun comp produces a function. So (comp str/lower-case name) is a function that would convert a keyword to a lower-case string.

seancorfield04:04:28

So it can be passed around and treated just like any other function.

seancorfield04:04:53

(-> s name str/lower-case) works when you have a series of functions to apply to a value.

seancorfield04:04:29

(let [lower-key (comp str/lower-case name)]
  (lower-key s))
Does that help show the difference?

pythonjokeun04:04:53

@seancorfield yes! so comp useful when you need to produce a function, right?

noisesmith17:04:17

another thing to consider when comparing, is that -> takes a form as input, and produces a new form as output, before compilation happens

noisesmith17:04:26

comp operates on functions, which are already compiled

seancorfield04:04:20

Also, when you get to transducers, you'll see comp used to produce a transforming function from multiple functions... https://clojure.org/reference/transducers -- shows how threading and composition compare as well.

pythonjokeun04:04:57

noted, thanks!

Joel05:04:16

this gives me a map: (meta (resolve 'has-email)) however, this does not work, even though the list contains has-email: (map #(meta (resolve (symbol %))) (dir clararules.core))

arbscht05:04:39

probably because dir returns nil, it prints the values you're interested in as a side effect

arbscht05:04:57

if you want data to inspect about a ns, look into the ns-* fns

Joel05:04:13

dir-fn ... that helps

šŸ‘ 4
Joel05:04:53

i maybe going about this wrong... if i do load/load-string, how do i know what got loaded? like a list of functions

Joel05:04:09

(or defs or whatever)

didibus05:04:21

What are you using load for?

Joel05:04:49

to store clojure logic in DB and be able to use dynamically.

didibus05:04:21

I see. So you're using load-str then?

Joel05:04:22

clojure newbie--- my experience is lisp more than clojure fwiw

Joel05:04:40

i thought that appropriate

arbscht05:04:54

load can have arbitrary effects, I can't think of a reliable way to measure it

Joel05:04:50

i'm probably thinking about this wrong... possibly i need to have expected functions to call or protocol... not sure what's appropriate.

arbscht05:04:58

if you're only interested in a certain subset of possible effects, I'd try capturing prior and posterior values around the load and diffing them

Joel05:04:14

yeah, that makes it sounds like i'm thiking about this wrong.

Joel05:04:16

in java i guess i'd be expecting some instance of a class w/methods i call, with load-string, not sure how i should go about calling into loaded functions.

arbscht05:04:09

ah, you want to dispatch to the fns you load

Joel05:04:09

like technically i wouldn't know the namespace even.

arbscht05:04:17

perhaps multimethods?

Joel05:04:47

i think i need a good example of calling from Java into Clojure.

Joel05:04:03

but in a dynamic case (using load-string)

arbscht05:04:34

so you're loading code from db, and then dispatching to it from java?

Joel05:04:06

yes, just prototyping at this point.

Joel05:04:31

really i'm trying to see how to use Clara rules instead of Drools is the high-level.

arbscht05:04:02

I'd experiment with multimethods. defmulti first, then put your defmethods in db

arbscht05:04:32

then you can invoke the multimethod from java using clojure interop (there are examples)

Joel05:04:37

ok, ill do some googling around that....

Joel05:04:47

wouldn't protocol be similar in that regard?

arbscht05:04:24

similar but if you don't need the perf benefits of protocol or you want multiple dispatch etc, multimethods are fine (and more general)

arbscht05:04:45

if you're prototyping and don't have a need to use protocols, start with multimethods

arbscht05:04:51

you can always convert them later if you need to

Joel05:04:57

ok, that's helpful. thanks.

Marcos Silva07:04:51

It happens when I run heroku local

seancorfield07:04:20

Sounds like your JAR file doesn't include Clojure. How was it built?

Marcos Silva08:04:40

i thought this would include everything it needs to make the jar run

seancorfield16:04:37

@UD4M6JN49 Hmm, I would have expected that to work. Can you run it locally -- not on Heroku?

Marcos Silva11:04:12

this problem is local

eskemojoe00713:04:56

Hey team. Relatively new to Clojure from a python/django background. Trying to develop with unit tests for everything, but trying to lock down some best practices and overall testing resources. Do you have any useful links?

eskemojoe00713:04:12

I read an article that recommended test suites such a Kaocha. Just don't wanna go down a rabbit hole.

bmaddy15:04:49

On the project I'm on we just use clojure.test. I'm sure others do it differently, but the main thing I do is have a repl open on the other side of my screen and run the (editor specific) command for running the tests in this namespace. As I'm writing the tests, I'll regularly be defining top level vars and sending forms over to the repl to see how things are working.

seancorfield16:04:07

clojure.test is a fine place to start. Many Clojure-aware editors have shortcut keys to run tests directly from your source files or test files. That makes a huge difference in productivity. Also check out Stuart Halloway's talks about "REPL-Driven Development" and "Running With Scissors" for good practices around REPL usage (and testing code via the REPL).

eskemojoe00717:04:50

Perfect...Thank you!

ok15:04:50

How to update-in - drop one in nested vector?

Ivan Koz15:04:41

@twaima explain on sample data

ok15:04:35

I have an atom with {:id 1 :vector [1 2 3]} - So I need to update it to drop 1 (first one).

Mno15:04:21

Iā€™m not very good at this yet but you could use update?

Mno15:04:27

(update {:id 1 :vector [1 2 3]} :vector #(drop 1 %1))

šŸ‘ 4
alexmiller15:04:10

you can, but this is a very inefficient operation

alexmiller15:04:19

if you used a list/seq, you could just use rest

alexmiller15:04:53

the big point is - decide what operations you need on a data structure, then pick the data structure on which those exist + are fast

alexmiller15:04:38

(and btw Clojure generally only implements the ops for data structures where it can meet some perf expectations, so if they exist, it's prob fast)

šŸ‘ 8
Mno15:04:34

Yeah what he said. šŸ˜…

Ivan Koz15:04:08

@twaima

(def item (atom {:id 1 :v '(1 2 3)}))
=> #'junk.core/item
(swap! item update-in [:v] rest)
=> {:id 1, :v (2 3)}

šŸ‘ 4
ok15:04:43

It is right. thanks šŸ˜‰

kakoc19:04:52

Hello! I want to try interactively develop in tty application, particularly a want to achieve the following: I run from the clojure code "/bin/sh" "-c" "stty -echo raw </dev/tty" -> I expect to see runned empty console, after that I want to add different key press handlers etc, etc. I am confused how I can do that in interactively manner. Thank you in advance!!

manutter5119:04:39

@k.matush this might not be exactly what you asked for, but it might be of interest anyway: https://github.com/MultiMUD/clojure-lanterna

eskemojoe00720:04:40

I'm reading through a pretty big fancy code. they have these giant maps that they pass to every function. I struggle to see what each map is supposed to look like, especially when messing with the REPL. I've been reading about specs. Is a proper application of spec to define how large map and data structures should look like? It seems as though I can define the spec of key values that must be there, and the values that should be present for my critical data.

eskemojoe00720:04:51

Concise...I love it. Thanks.

alexmiller20:04:21

that's exactly it. if you spec your attributes/maps/functions with fspecs then you get those specs via doc on the function, gen arg examples, instrument to check incoming values match your spec in dev, and test with check that your function operates correctly

eskemojoe00720:04:58

Thanks. Coming from a python/fortran background, clojure has been tough for me to learn, but I'm trying to set up my project right! So I'll right some spec's for the most important stuff.

alexmiller20:04:19

when you run into questions - head to #clojure-spec :)

šŸ‘ 4
Denis G20:04:06

need a framework to work with tcp sockets. any ideas?

hiredman20:04:50

framework for what?

Denis G20:04:29

working with tcp sockets connection. client, server, sending, getting data from it

hiredman20:04:49

java.net.\ is a thing, as is java.nio.\

noisesmith20:04:06

java comes with that stuff, I don't know why you'd need a framework. Aleph has some nice abstractions for async and data oriented stuff on top of that though

solf23:04:29

I'm reading the doseq docstring and there is a sentence I don't understand, could anyone explain what it means? > Does not retain the head of the sequence