Fork me on GitHub

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


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


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


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


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


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


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


comp operates on functions, which are already compiled


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


noted, thanks!


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))


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


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


dir-fn ... that helps

šŸ‘ 4

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


(or defs or whatever)


What are you using load for?


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


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


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


i thought that appropriate


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


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


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


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


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.


ah, you want to dispatch to the fns you load


like technically i wouldn't know the namespace even.


perhaps multimethods?


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


but in a dynamic case (using load-string)


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


yes, just prototyping at this point.


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


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


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


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


wouldn't protocol be similar in that regard?


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


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


you can always convert them later if you need to


ok, that's helpful. thanks.

Marcos Silva07:04:51

It happens when I run heroku local


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


@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


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?


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


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.


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).


Perfect...Thank you!


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

Ivan Koz15:04:41

@twaima explain on sample data


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


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


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

šŸ‘ 4
Alex Miller (Clojure team)15:04:10

you can, but this is a very inefficient operation

Alex Miller (Clojure team)15:04:19

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

Alex Miller (Clojure team)15: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

Alex Miller (Clojure team)15: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

Yeah what he said. šŸ˜…

Ivan Koz15:04:08


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

šŸ‘ 4

It is right. thanks šŸ˜‰


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!!


@k.matush this might not be exactly what you asked for, but it might be of interest anyway:


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.


Concise...I love it. Thanks.

Alex Miller (Clojure team)20: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


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.

Alex Miller (Clojure team)20: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?


framework for what?

Denis G20:04:29

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

hiredman20:04:49\ is a thing, as is java.nio.\


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


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