Fork me on GitHub

Is there a recommended channel to find Clojure contractors?

Josh Horwitz00:03:58

I would guess #jobs , #jobs-discuss or #remote-jobs


can someone help me through my brain fart? I have a vec of args and what I want to do is replace the first arg in the vec with my own, then continue passing the rest of the args (no matter how many) as a vector:

in -> [:a {} [] ... etc]
out -> [:replaced {} [] ... etc]
I can (rest args) to grab everything but the first, but now i’m dealing with a sequence; how do I get that sequence back into a vector with after inserting to the front?


(without flatten, which feels like cheating)


would it be into [:replaced] (rest args)? that seems iffy, too


(assoc v 0 new-val)?


I'm honestly not sure, as I don't have a REPL open 🙂


could do something like (into [] (concat [1] (rest [0 2 3 4])))


@benzap (into [1] (rest v)) works also


and so does assoc


yeah, the assoc one is probably the best


yeah - it's easy to forget into accepts a collection that already has contents, which is why I shared my variation on the into

👍 4

thanks guys--


Is there any good resource for learning some common design patterns for clojure

👍 12

i would say: Programming Clojure Joy of Clojure


not just the "this is how you do the equivalent java" but like, what the community considers best practie


Hey, I was hacking on a program for processing a huge file and deriving content from it into another. Reading the huge file in streaming mode (to not bring it into memory beyond a constant size), processing the file concurrently, and writing the content being derived from it into a file without contention on the file. It kind of works... but I don't like the structure I ended up with...


Do you happen to know any open-source that does exactly this in clojure, which I can compare my implementation with?


I think this depends alot on the format of the input file, as you need to have something that can produce a partial parse from a partial input


it's line by line processing


so there's no deep algorithmic parsing concern..


... gets a line, parse, filter, transform, queue to write as output ...


it's the concurrency and streaming that hurts a little, or is just very interesting to explore


is the output just (map some-func input-lines) ?


you can possibly refactor out a pattern of a func which does: (line -> line) -> (large file -> large file), but besides that, without more info, it's not clear what else can be done


@emccue For styling conventions, this helps: For design patterns, clojure follows closely to functional programming design patterns. So think KISS and DRY. Less patterns, and more idioms, since you're only ever really dealing with data, and not objects.

👍 4

If I were to recommend a book, i'd check out


(defne match2 [x y]
  ([[a b . tail] [b a . tail]]))


Can anyone help me understand what . does here?


Learning core.logic here


I believe it's to separate the head values from the tail of an array


but it's logic programming 😉

👍 8

hah just realised that !


thought it was some other dialect


I think the equivalent in prolog is something like match2(A, B) :- A = [ X1, X2 | XS1 ], B = [ X2, X1 | XS2 ].


Is specter everyone’s favourite library for managing complex data structures?


Are there other alternatives I haven’t spotted?


is the defne supposed to be a goal to check if the first two elements of two arrays are matched at interchanged HEAD locations?


I think spectre became popular because it kind of filled that niche area that other libraries weren't able to fill

👍 4

clojure.walk is somewhat similar, but not as powerful


ah yes. didn’t think about that. thankyou.


I’m gonna go and squint at those lovely functions for a minute before jumping in with spectre


I’m busily constructing get requests from a map… so building strings that go URL?k1=v1&k2=v2


which library should I grab this functionality from?


there are a few points where errors could arise in the flow of my code. is it better to throw exceptions where necessary and catch them for reporting, or it is better to return a map, that is interpreted?


@benzap Thanks. . notation is no where documented. (run 1 [r] (match2 [1 2 3 'blah 'blah] r)) returns ((2 1 3 blah blah))


I realize this is terrible, but in this particular case (too long to explain) I need to use this hack: suppose I want to globally overwrite a function from another library (yes, I know this is terrible; trust me that I do want to do this) I can do (set! foo/bar (fn ...)) now, this becomes problematic if bar is a PRIVATE function in namespace foo. In this case, is it still possible to somehow overwrite? [yes, I know this is a terrible idea in general, but I really have to do this hack in this case]


@benzap The scheme version of miniKanren looking minimal. Recursion feels natural and therefore logic programming feels natural. Take a look at this . The Scheme version looks much more natural

Michael Fiano13:03:41

@qqq I don't know if this is useful in your case, but you can still access a private symbol using @#'foo/bar


It's not reading that is the problem, it's writing that is causing the problem. Turns out though, alter-var-root appears to work 🙂


@konanki.sivaram Interesting, I think miniKanren was originally based off of the scheme version, i've been meaning to pick up The Reasoned Schemer, which goes over the scheme version


I'm planning on putting some time into learning core.logic, I feel like it might be useful for some code i'm doing with time scheduling


This is an awesome reference for all of the different logic programming implementations


thanks for the link 🙂


read the microkanren paper, if you want to understand how core.logic/miniKanren work


I did a talk on this at a pwl meetup

👍 4

Why "map-entry?", but no "map-entry" ?

Alex Miller (Clojure team)15:03:05

usually you don’t create these directly, however there are cases where it would be a useful tool, particularly for map modification optimization

Alex Miller (Clojure team)15:03:26

if you wanted to make a jira for it, I think that would be reasonable


Here: By the way, I also use them when I need (a sequence of) key-value pairs, not necessarily in a map. A vector or a list could be used as well, but I find key\val to be more descriptive than first\second.Another plausible use case that comes to mind is variants (aka sum "types" aka tagged unions), although it seems people usually use [:tag val vals*] for that.

qqq14:03:24 is really good too, the series walks through an implementation of logic programming

👍 4

Hi, I’m trying to use lacinia’s resolver factory without much success. Hopefully somebody with similar experience can help. My intention is to mention the resolvers as keywords in schema file and resolve the keywords to functions in a factory. The factory code where I return the function literal

(defn ^:private keyword-factory
(fn [context arguments value]
(let [f (resolve (symbol (name keyword)))]
#(f context arguments value))))
One of my resolver functions:
(defn get-user
[context arguments value]
(let [{:keys [id pass]} arguments]
(db/get-user {:id id :pass pass})))
Issue is the resolved values are always null (no errors or stacktraces):
  "data": {
    "post": {
      "id": null


@arulpugazh this isn't your direct concern, but calling resolve to do dispatch is a bad idea if any of your data might come from an untrusted source. Instead, you can use a hash-map from string or symbol to function - that acts as a whitelist of which functions are safe to call based on the input provided


every function visible to your namespace is accessible via resolve, and that's a lot of potential gotchas


@noisesmith thanks, that’s an useful point for me think. But, in this case, in lacinia, the schema design and hence the resolver keywords are provided by me. So even if external source accesses the api, they won’t be able to access other functions, i guess?


oh, so it's always getting a keyword you had literally in your source, that's reasonable


but sometimes, even then, using a map instead of treating your namespace like a lookup map is simpler


good luck with your actual question (I don't know lacinia at all, I bet someone here does)


@noisesmith sure, I will keep that in mind. thanks 🙂


a general question about sending mail from server. I'm trying to send email with postal, works fine locally, but on my server, which is being proxy_forward-ed with nginx, I get this error relaying denied ip name lookup failed. Do I need to set up some mail server in nginx to allow outgoing email?


this may have arrived after I added ssl encrpytion with let's encrypt.


Postal has a sample Nginx config. perhaps that’s a place to start... ?


Ah, there are two Postals out there that's confuseing 🙂 I kind-a gave up on this for now, I would use gmail smtp if they didn't force one to log-in with browser for double authentication, hard to do on headless remote server in another country.


laptop = osx server = ubuntu 16 // jvm + clojure repl running on this machine what do I need to do to be able to forward awt/string GUIs from server to laptop ?


I figured out my problem: I was 1. running "boot repl" inside a tmux session 2. did a ssh -X ... ; tmux attach 3. unfortunately, my already running "boot repl" did not have DISPLAY setup because it was using old envs from before the "-X"


cursive is complaining that my namespace doesn't match my fs, is there a document on how to structure my namespace?


@matthewdaniel The quick fix is to put the caret on the error squiggle, hit alt-enter and then get Cursive to move the file to the right place.


But to answer your actual question, I’m not sure if that’s documented on - I assume it is, but I don’t know where.


ah, i think i found the problem. it doesn't like file names with - so views/batch-items.cljs to camel fixed it


Right, dashes have to be converted to underscores.


why the file name should have underscore ?


any specific reason ?


it's required by Java


you mean jvm used to read these files and they need be in underscore format..


exactly 🙂


so it's not Clojure's decision, it's necessary for it to work with Java


what about name space.. i think that is clojure requirement..


yeah, I just looked at my reference for this and it didn't say it was from Java, so I actually don't know


i see.. np thanks !


It has to do with legal package names in Java


(Character/isJavaIdentifierPart \-) => false (Character/isJavaIdentifierPart \_) => true


I'm sure you've seen this when debugging Java code: (Character/isJavaIdentifierPart \$) => true 🙂


and now it makes sense..


It's typical (at least in leiningen-managed projects) to have the namespace foo-bar in the file foo_bar.clj.

Russ Olsen23:03:29

The JVM has this tendency to map class names to file names. Which means that it wants the names of files to be legal class names and you can't have no dash in a Java class name.

👍 4

Old classic about JVM symbols


Here: By the way, I also use them when I need (a sequence of) key-value pairs, not necessarily in a map. A vector or a list could be used as well, but I find key\val to be more descriptive than first\second.Another plausible use case that comes to mind is variants (aka sum "types" aka tagged unions), although it seems people usually use [:tag val vals*] for that.