Fork me on GitHub
#clojure
<
2018-03-25
>
etherfuse00:03:08

Is there a recommended channel to find Clojure contractors?

Josh Horwitz00:03:58

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

lwhorton02:03:16

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?

lwhorton02:03:28

(without flatten, which feels like cheating)

lwhorton02:03:56

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

the2bears02:03:55

(assoc v 0 new-val)?

the2bears02:03:28

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

benzap02:03:46

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

noisesmith02:03:55

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

noisesmith02:03:17

and so does assoc

benzap02:03:35

yeah, the assoc one is probably the best

noisesmith02:03:05

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
lwhorton02:03:00

thanks guys--

emccue05:03:48

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

👍 12
sundarj19:03:32

i would say: https://purelyfunctional.tv Programming Clojure Joy of Clojure

emccue05:03:02

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

matan08:03:20

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

matan08:03:46

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

qqq08:03:49

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

matan08:03:04

it's line by line processing

matan08:03:24

so there's no deep algorithmic parsing concern..

matan08:03:44

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

matan08:03:05

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

qqq08:03:09

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

qqq08:03:07

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

benzap09:03:01

@emccue For styling conventions, this helps: https://github.com/bbatsov/clojure-style-guide 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
benzap09:03:50

If I were to recommend a book, i'd check out https://pragprog.com/book/vmclojeco/clojure-applied

siva09:03:21

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

siva09:03:34

Can anyone help me understand what . does here?

siva09:03:48

Learning core.logic here

benzap09:03:22

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

benzap09:03:21

but it's logic programming 😉

👍 8
triss09:03:30

hah just realised that !

triss09:03:45

thought it was some other dialect

benzap10:03:42

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

triss10:03:20

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

triss10:03:39

Are there other alternatives I haven’t spotted?

benzap10:03:44

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

benzap10:03:37

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

👍 4
benzap10:03:53

clojure.walk is somewhat similar, but not as powerful

triss10:03:16

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

triss10:03:36

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

triss11:03:02

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

triss11:03:43

which library should I grab this functionality from?

ackerleytng12:03:52

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?

siva13:03:59

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

qqq13:03:18

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]

siva13:03:45

@benzap The scheme version of miniKanren looking minimal. Recursion feels natural and therefore logic programming feels natural. Take a look at this https://www.rosettacode.org/wiki/Zebra_puzzle#Clojure . 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

qqq13:03:46

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 🙂

benzap13:03:11

@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

benzap13:03:50

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

benzap13:03:53

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

benzap13:03:58

thanks for the link 🙂

bronsa13:03:40

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

bronsa13:03:48

I did a talk on this at a pwl meetup https://www.youtube.com/watch?v=Dm7_DiNxFNk

👍 4
jcr14:03:29

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

jcr15:03:29

Here: https://dev.clojure.org/jira/browse/CLJ-2339 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

https://www.youtube.com/watch?v=7CWEPRKOwgI is really good too, the series walks through an implementation of logic programming

👍 4
arulpugazh14:03:26

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
[keyword]
(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
    }
  }
}

noisesmith14:03:07

@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

noisesmith14:03:15

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

arulpugazh15:03:31

@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?

noisesmith15:03:29

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

noisesmith15:03:44

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

noisesmith15:03:04

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

arulpugazh15:03:45

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

hlolli17:03:19

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?

hlolli17:03:50

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

gonewest81820:03:52

Postal has a sample Nginx config. perhaps that’s a place to start... ? https://github.com/atech/postal/blob/master/resource/nginx.cfg

hlolli22:03:03

Ah, there are two Postals out there https://github.com/drewr/postal 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.

qqq20:03:50

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 ?

qqq21:03:22

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"

MegaMatt21:03:36

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

cfleming21:03:38

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

cfleming21:03:15

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

MegaMatt21:03:16

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

cfleming21:03:36

Right, dashes have to be converted to underscores.

rajesh22:03:06

why the file name should have underscore ?

rajesh22:03:12

any specific reason ?

schmee22:03:33

it's required by Java

rajesh22:03:06

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

schmee22:03:45

exactly 🙂

schmee22:03:58

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

rajesh22:03:05

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

schmee22:03:14

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

rajesh22:03:05

i see.. np thanks !

mfikes22:03:11

It has to do with legal package names in Java

mfikes22:03:49

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

mfikes22:03:29

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

rajesh22:03:19

and now it makes sense..

frenata23:03:55

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
ghadi23:03:28

Old classic about JVM symbols

jcr15:03:29

Here: https://dev.clojure.org/jira/browse/CLJ-2339 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.