This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-18
Channels
- # architecture (14)
- # beginners (89)
- # cider (336)
- # cljsrn (2)
- # clojure (181)
- # clojure-berlin (1)
- # clojure-dusseldorf (3)
- # clojure-finland (4)
- # clojure-germany (5)
- # clojure-italy (18)
- # clojure-norway (10)
- # clojure-spec (9)
- # clojure-uk (94)
- # clojurescript (84)
- # cursive (3)
- # data-science (4)
- # datomic (82)
- # emacs (2)
- # events (4)
- # figwheel (1)
- # fulcro (6)
- # graphql (2)
- # hoplon (46)
- # instaparse (24)
- # jobs (9)
- # lein-figwheel (2)
- # luminus (18)
- # lumo (3)
- # mount (1)
- # off-topic (14)
- # onyx (17)
- # parinfer (22)
- # planck (1)
- # protorepl (1)
- # re-frame (50)
- # reagent (7)
- # ring-swagger (6)
- # rum (4)
- # shadow-cljs (94)
- # spacemacs (9)
- # specter (7)
- # tools-deps (2)
- # uncomplicate (4)
- # vim (33)
Is it possible for me to have a spec: s/cat
regex where latter parts of the regex use predicates that depend on the conform of prior parts?
@ghopper Can you be a bit more specific about what you're trying to achieve? My first reaction is to suggest s/and
wrapped around s/cat
and use the predicates there.
no, and what Sean said
Whoops, sorry. I guess I only sent this on #clojure-spec.
(s/and (s/cat :starts-with string? :values (s/* string?)) (fn [{:keys [starts-with values]}] ...))
Oh, nice! I didn't realize s/and
would pass the conformed value to the second function.
That's awesome. 🙂 Thanks, @seancorfield!
@seancorfield I don't suppose there's a way to do this without it starting a new scope?
(s/conform (s/+ (s/and (s/cat :a string?
:b string?)
(constantly true)))
["testa1" "testb1" "testa2" "testb2"])
=>
:clojure.spec.alpha/invalid
I'm not sure what you're asking...
Is there a way to make the above work while keeping the s/and
?
I don't understand what you're trying to do, sorry.
(that spec makes no sense to me)
And not requiring [["testa1" "testb1"] ["testa2" "testb2"]]
.
That's alright. I'm not understanding this very well myself.
Take a step back, and explain what is it you're trying to write a spec for -- explain it in words, not code.
I want to have pairs of things in a list and an arbitrary predicate that's dependent on both values.
I'm attempting to spec out a macro to create proxying proxies.
(defproxy menu
Object
[func1 func2])
The spec for [func1 func2]
is dependent on what Object
is.However, I don't want to have Object
and [func1 func2]
inside their own wrapper.
(s/+ (s/cat :a string? :b string?))
will accept a collection of strings and conform to a collection of maps (each map containing :a
and :b
).
Yeah, that works fine. The issue is when I add in the s/and
it then requires a wrapper.
So write the spec for the collection of things, then wrap the whole spec in s/and
and have it process all the conformed values.
I didn't expect that. I thought s/and
with a single argument was basically a passthru.
Oh, that makes sense. I'll create a predicate for everything instead of for each pair.
That predicate would be #(every? pair-predicate %)
I think...?
Yeah, that makes sense. I just wasn't thinking about it that way.
I'm still trying to get into the spec mindset.
Thank you
A key thing to "get" with spec is to not over-specify things: write "just enough" spec for the structure and then tighten the screws with additional predicates.
Thanks for the tip
It's a stupid example, but it works great.
(s/conform (s/and (s/+ (s/cat :a string?
:b string?))
(partial every? (fn [{:keys [a b]}] (= a b))))
["testa1" "testa1" "testa2" "testa2"])
Thanksthere are lots of good talks on youtube if you want to know more, here’s one: https://www.youtube.com/watch?v=mMmOntDWSgw
Are there some good tips and tricks for retaining the collection type when performing operations on a collection?
All they need to do is get graalvm compiling into webassembly, and we'll have reached the singularity
1.0 not necessarily means production-ready, kafka was production ready long before the 1.0 release.
the Python implementation is quite new, I don’t think it was around when that slide was made
As far as I understand you can run GraalVM on top of Node.js or standalone as well
"It can run either standalone or in the context of OpenJDK, Node.js, Oracle Database, or MySQL. "
Is there a chance for official TruffleClojure?
could maybe get clojure working on android at significantly lower instantiation times if it can be baked into a native executable
or most of them are at least, I think the persistentlist is probably O(1) for removal and insertion
and aget/aset map to standard java array lookup so performance expectations should match
Hi! i'm about to start a personal web project, and i wonder which server should i use, aleph, http-kit or immutant, knowing that it will be (mostly) a real time app?
My advice: most "real time" apps are primarily request/response driven with one component that requires live updates
So optimize for the former, then add a simple component that handles only the minimum, i.e. the push part (SSE or websockets)
There's even a SaaS that does this for you: https://pusher.com/ Great way to simplify your architecture if it fits your app
They use an OSS daemon under the hood, can't find the name ATM
Basically what I'm saying is don't let get distracted by the real-time part or let it infect your project with incidental complexity if you can help it
@pesterhazy thanks man, you saved me a day of search, i'm not an experienced programmer though, i just have an idea and wanted to see if it's worth building
There are some differences between primitive and object type hints
ah, so primitive type hints (long, integer, ... maybe string?) are only for fn args, but custom object hints could be more liberally used?
But you can generally use either of them in many places
in cases where I have locals bound in loops, i'll often do (loop [^Integer x ...
appropriate?
It depends
the problem is I am working on a data set that is about 10 million integers, so I'm trying to figure out how best to keep it from taking a few minutes to do its thing. The equivalent C++ code is at least 100 times faster for me at the moment.
You really want to avoid boxed numbers, which is particularly challenging in Clojure for ints
part of it also confusion over syntax and how they work, for example if i know the result of a function call is a long, where do I put this? In the function definition itself, in the local I am binding to the result, or both, and in the latter case, would you also ever do something like (let [x ^Long (some-fn-returns-long)...
or only in front of the var/local name?
In general you should put in the place where it has an effect on the most places possible
So in this case I’d put it on the return type of the function
No, put it before the arg vector
In that placement you’re type hinting the var
At the repl both seem to have the same effect of enforcing via cast exception that the return is a long
There is no casting here
I gotta run, sorry
thanks for the help, by casting i just meant the exception from this (defn ^long f [] :hi)
it there an easy to use clojure library to manipulate git repos available? I’ve used clj-jgit in the past, but found it pretty complicated. I’m looking for something that supports the basic git commands (reset, pull, commit)
> it there an easy to use clojure library
No. Lots of simple ones though
</just-kidding>
Seriously though, maybe JGit? http://www.eclipse.org/jgit/ I haven't used it at all, but for this sort of niche problem I tend to look for Java libs and use interop
i found https://github.com/zcaudate/lucidity/tree/master/src/lucid/git, which looks promising
with deftype, is there a fundamental limitation of "members of type = members passed to constructor" ?
not only that, but the declaration order determines the order the constructor takes them
I was hoping there was some black magicery where we define a specialy named method, which then overrides the default constructor, but I guess that is not supported
@qqq there's such a thing for defrecord (not for deftype though), are you familiar with it?
cljs.user=> (defrecord Foo [a])
cljs.user/Foo
cljs.user=> (map->Foo {:a 2 :b 3})
#cljs.user.Foo{:a 2, :b 3}
cljs.user=> (Foo. 2 )
#cljs.user.Foo{:a 2}
I'm lookinat at https://clojuredocs.org/clojure.core/defrecord is there a way to do custom constructors?
the other tools I know about are using (into (empty my-coll) (....some transforrm of my-coll....))
@foobar Is this a "cannot find class" error when you try and import it or a "when I try to use it it cant be resolved in that place"
Has anyone here been part of a Scala shop that transitioned to Clojure, or started using Clojure?
Had the opposite experience - took a role that was for "Clojure", and then once there was told to pull it apart and make Scala micro-services. Not there anymore 🙂
How did you help those who depended on types to get over that hump?
Is there a way to extend clojure.core’s functionality? For example, have the function range
also work on strings?
Now: (range "foo")
throws
>1. Unhandled java.lang.ClassCastException
> java.lang.String cannot be cast to java.lang.Number
> Numbers.java: 96 clojure.lang.Numbers/isPos
> Range.java: 80 clojure.lang.Range/create
Is there a way to extend range
so that when you call it with a string as first argument it does something different?
I guess it would be dangerous, but I am curious.
Yes I figured. Is it possible in ClojureScript? Since there are different protocols there?
Disclaimer: I still need some education on protocols.
hi everyone. I’m trying to do something like this - I have a vector of maps and I’m trying to pick certain values from each map (specifically strings) and concat them afterwards with a white space inbetween
(def users [{:first "John"
:last "Smith"
:age 33}
{:first "Jane"
:last "Smith"
:age 22}
{:first "James"
:last "Smith"
:age 2}])
(->> users
(map (juxt :first :last))
(map (interpose " " %)))
and I’m stuck there :d basically I want the result to be ["John Smith" "Jane Smith" "James Smith"]
almost!
bear in mind, that doing two passes over a seq when you could do one, is not very desirable
will it actually iterate twice though? will it not create a lazy sequence in that case and iterate once?
versus
look for transducers if you want that optimization
thanks @joelsanchez. I was missing the transducers piece
Hi all, has anyone used clojure during typical algorithm interviews? Was wondering if it's a bad choice because space complexity will be hard to analyze
but honestly you'll probably run into an issue of your interviewer not knowing clojure
@squarenegative space complexity is still knowable though - yes laziness and chunked allocs change things but they are managable
but they aren't
I thought an interesting exercise was to use clj-memory-meter while repeatedly updating and conj
ing a data structure onto itself. While this would break things in other languages, you can create synthetically large structures in clj that are too big to actually realize if you were to try to read the whole thing.
allowing you to operate incrementally over data domains that essentially don't fit in your memory
@squarenegative I used it in my interviews with intuit and it worked out fine
If we are talking the ratio of interviewer understanding to space on a whiteboard the winner is still probably python
My friend was asked to explicitly not use it. Maybe ask your interviewer if it's ok beforehand. Takes a bit of a shift if you can't
Is there a nice standard function in clojure to generate a sequence from a seed value by, at each point, generating the next value by applying some function on the seed, and either carrying on with a new seed value or ending the sequence
thanks @hiredman 🙂 I wanted to write a function to get the digits of a number in a list. Do you think that makes sense:
(defn digits [n]
(take-while pos? (map #(rem % 10) (iterate #(quot % 10) n))))
?(defn digits [n] (map #(Long/parseLong (str %)) (str n)))
? :)
(defn digits [n] (map #(- (int %) 48) (str n)))
;; ascii power
@alexmiller haha well, I wanted to try to avoid the conversion to string
if you rewrite into a loop / recur it should be easy. and then your pos?
check makes sense.
If I’m making a library that connects to a server and upon establishing a connection receives an api version number, and this version number is used throughout a ton of single threaded boundry transformation multimethods (ie parsing the native representations of various types into clojure maps), but only used in about half of the total transformation multimethods, might this be a good use case for using a dynamic var for the version number and just wrapping the transformation calls in a binding
?
just started getting an odd emacs/CIDER issue today… when i evaluate a cljs buffer, i get an error stating there’s no CLJS repl open (even though there is) When I try to evaluate a CLJ buffer, it loads it into the CLJS repl…. Anyone run into this issue before?
@soosool12 there was a bug with a cider-nrepl snapshot released today. try lein -U deps
to pull this new version or blow away ~/.m2/repository/cider
and then crank it back up and all should be well
the problem is that the cljs repl never got correctly created. so you are just left with two clj repls. more in #cider if you want 🙂
@dpsutton ahhhh thank you so much. i had no idea there was a #cider channel. Will post in the correct place next time. Really appreciate the quick reply!