This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-25
Channels
- # beginners (152)
- # boot (4)
- # bristol-clojurians (1)
- # cider (1)
- # cljs-dev (176)
- # clojure (104)
- # clojure-china (2)
- # clojure-uk (6)
- # clojurescript (6)
- # core-async (23)
- # cursive (4)
- # datomic (3)
- # devops (1)
- # duct (32)
- # events (1)
- # fulcro (9)
- # hoplon (2)
- # jobs-discuss (9)
- # lein-figwheel (2)
- # leiningen (3)
- # off-topic (19)
- # pedestal (2)
- # portkey (14)
- # re-frame (20)
- # reagent (41)
- # rum (4)
- # shadow-cljs (26)
- # tools-deps (1)
- # unrepl (5)
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?@benzap (into [1] (rest v))
works also
and so does assoc
yeah - it's easy to forget into accepts a collection that already has contents, which is why I shared my variation on the into
i would say: https://purelyfunctional.tv 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 the concurrency and streaming that hurts a little, or is just very interesting to explore
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: 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.
If I were to recommend a book, i'd check out https://pragprog.com/book/vmclojeco/clojure-applied
I think the equivalent in prolog is something like match2(A, B) :- A = [ X1, X2 | XS1 ], B = [ X2, X1 | XS2 ].
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
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
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 https://www.rosettacode.org/wiki/Zebra_puzzle#Clojure . The Scheme version looks much more natural
@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
usually you don’t create these directly, however there are cases where it would be a useful tool, particularly for map modification optimization
if you wanted to make a jira for it, I think that would be reasonable
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.
https://www.youtube.com/watch?v=7CWEPRKOwgI is really good too, the series walks through an implementation of logic programming
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
}
}
}
@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?
Postal has a sample Nginx config. perhaps that’s a place to start... ? https://github.com/atech/postal/blob/master/resource/nginx.cfg
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.
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 http://clojure.org - 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
yeah, I just looked at my reference for this and it didn't say it was from Java, so I actually don't know
(Character/isJavaIdentifierPart \-)
=> false
(Character/isJavaIdentifierPart \_)
=> true
I'm sure you've seen this when debugging Java code:
(Character/isJavaIdentifierPart \$)
=> true
🙂
It's typical (at least in leiningen-managed projects) to have the namespace foo-bar
in the file foo_bar.clj
.
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.
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.