This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-16
Channels
- # beginners (7)
- # boot (63)
- # capetown (1)
- # cider (20)
- # clara (15)
- # cljs-dev (5)
- # clojure (195)
- # clojure-austria (2)
- # clojure-dev (46)
- # clojure-dusseldorf (9)
- # clojure-germany (6)
- # clojure-greece (36)
- # clojure-italy (5)
- # clojure-nl (4)
- # clojure-russia (173)
- # clojure-sg (1)
- # clojure-spec (93)
- # clojure-uk (65)
- # clojure-ukraine (2)
- # clojured (9)
- # clojureremote (1)
- # clojurescript (52)
- # core-async (14)
- # core-logic (5)
- # cursive (21)
- # data-science (8)
- # datomic (60)
- # emacs (83)
- # jobs (9)
- # jobs-discuss (7)
- # juxt (6)
- # klipse (2)
- # leiningen (1)
- # lumo (24)
- # mount (4)
- # numerical-computing (1)
- # off-topic (18)
- # om (37)
- # om-next (5)
- # onyx (13)
- # pedestal (1)
- # perun (44)
- # proton (2)
- # rdf (3)
- # re-frame (24)
- # reagent (4)
- # remote-jobs (3)
- # spacemacs (3)
- # testing (6)
- # vim (10)
- # yada (2)
Heyas. Is there a more succinct way of doing
(apply merge (map-indexed #(assoc {} %1 %2) ) ["a" "b" "c"])
?(zipmap (range) [...])
that's perdy 🙂
@bradford I should point out that for a lot of things, a vector is equivalent to such a map
Hey @ channel Where are the best places to post Clojure gigs?
Can I post in here?
I'll drop it in announcements
strike that, I dropped it in #jobs check it out!
is there an example somewhere for annotating and implementing an abstract class? does :gen-class
provide that?
@gfredericks Oh, I totally agree, but it's for a cranky bad API
Am I using :prep-tasks correctly to run sass4clj? :prep-tasks [["cljsbuild" "once"] "javac" "compile" ["sass4clj" "once"]]. When I add sass4clj ti keeps on rebuilding ClojureScript over and over.
@richiardiandrea it might, but it'll get messy. You're probably better off writing a small clojure friendly java wrapper for it
@borkdude once I needed this too
(defmacro ->map [& symbols]
`(hash-map ~@(interleave (map keyword symbols) symbols)))
I started playing with your previous example @residentsummer . Now I wonder why (zipmap (:a :b) '(1 2))
is an empty map
you lost a quote on the first list
another possibility is then:
(defmacro ->map [& symbols]
(let [keywords# (map keyword symbols)]
`(zipmap (list ~@keywords#) (list ~@symbols))))
yep. don’t need hash for keywords#
though
borkdude: it's just a list of symbols at compile time, so no evaluation happens
@residentsummer It’s a nice piece of code that fits in a tweet 🙂 https://twitter.com/borkdude/status/832269448539209733
spread the knowledge! 🙂
I’m trying to run a compiled C script in my resources folder, does anyone know why I can’t slurp it and run it using (sh “bash” :in (slurp (io/resource “mycprogram”)))
@ccann So bash expects a bash script but a compile C program will be machine code (ELF). I'm pretty sure you can't just run machine code that you have in java memory like this, unless you go very low level. Easiest would be to spit
it into a file (give it the executable bit) and then run it (sh "/tmp/your-program")
https://github.com/Raynes/conch has some interesting features
@borkdude isn't that just more syntax than {:a 1 😛 2}? What is the benefit of using ->map?
@thegeez I can now write:
(->map query-state
database
redis
body)
instead of:
{:query-state query-state
:database database
:redis redis
:body body}
Darn, now I wrote it by hand after all.@borkdude with next release of specter:
user=> (setval [ALL FIRST NAMESPACE] nil {:foo/a 1 :bar/b 2})
{:a 1, :b 2}
@bronsa the problems with that approach are that it's slow and it changes sorted maps to unsorted maps
Nested keys destructuring isn’t possible?
(let [{:keys [a {:keys [c] :as b}]} {:a {:c 2}}]
[a b c]) ;;=> [{:c 2} nil nil]
it'd be goofy because it'd only be allowed when you have :as
and when the value of :as
is a symbol
why not? I use that style all the time
I like nested destructuring, it's one my favorite parts of Clojure's design
does core.match
check for exhaustiveness? or at least is there a way to make it check for that?
is there a way to do something like this in clojure?
public class Foo {
private String bar;
public Foo(String bar) {
this.bar = bar;
}
}
and the constructor variables need to be private and only accessible indirectly w/ methods I'm exposing
actually it doesn't matter if it's deftype, just something that has that sort of functionality
So if this is really what you want then writing a custom Java class is probably the easy road. deftype
doesn’t give you machinery for private mutable fields.
@dpsutton Under pretty much any other circumstance I wouldn't care about it being private
@risto: how are you trying to consume this … structure whatever it may turn out to be?
Is it a value? Are you expecting to consume functions of this value? Are you trying to transform / alter it?
ideally it would be deftype
but it's okay if I have to encapsulate it in an inner class of some kind. I'm not sure a java class would work because it needs to be constructed dynamically
right no but what problem are you trying to solve that this appears to be the solution to you.
it needs to be private because I need to restrict how the developer interacts with arguments passed into the data type
the jvms private is easily overridable using reflection, it is really just a comment showing intent that the compiler checks
they can't just fetch the inner member because it would break the encapsulation that I need
If you really want a hidden value that can be accomplished… but this seems like the wrong way to do this.
well the difference between just a property access vs using something like wallhack is that, you know you're already that you're trying to access something you aren't supposed to
but if it's just something you can easily access then you can easily accidentally do that if you aren't aware
you could do like sicp, encapsulate a value and return a dispatch function that dispatches on keywords
if the user could access the data directly, then the abstraction I'm trying to write would be leaky in pretty horrible ways
user=> (def f (let [x 1] (fn [] (+ x 1))))
#'user/f
user=> (f)
2
user=> (->> (class f) (.getDeclaredFields) (map (fn [field] (.setAccessible field true) [(.getName field) (.get field f)])) (into {}))
{"const__0" #'clojure.core/+, "const__1" 1, "x" 1}
user=>
i don't think we're going for absolute secrecy but just a clear "don't touch that or else things can break" idea here
@zane > I use core.match for this Can you give an example that looks like mine? Not sure how you use it
9X% confident that’s the correct syntax, the match
form has some magic for allowing either a single value or a vector of values to be matched against.
If you wanna see some real core.match use, lib-grimoire is mostly core.match in a very Haskell style.
https://github.com/clojure-grimoire/lib-grimoire/blob/develop/src/grimoire/api.clj#L441
Why does this work:
(match {:a {:b 1}} {:a {:b x}} x)
but this doesn’t:
(match {:a {:b 1}} {:a {x 1}} x)
, because values aren’t unique in a map?core.match
does not do search for values which would match in a logic programming style.
Hi! Is there a more succinct way of counting occurrences of a vector of strings than
(apply merge (map #(let [mat (re-seq (Pattern/compile %1) "a a b b c c")]
{(first mat) (count mat)}
) ["a" "b" "c"]))
whats the difference between core.match/match and core.match/matchm? I think there are some other ones in the code also
(defn count-by [f coll]
(reduce (fn [acc x]
(update acc (f x) (fnil inc 0)))
{} coll))
(def count-by (comp frequencies map))
quick question: is there a way to use alias
(or similar) to remove an alias? in other words, make it as if the library was required without the :as
keyword? using unalias
seems to remove access to the library entirely, unless i'm confused and it's a matter of reloading it afterwards
in the absence of an alias, you have to use the fully qualified names, you don't get the short names you get from refers
to explain the reason i'm interested in this, i want to toggle between two versions of functions in different namespaces and previously would be like (doto 'namespace2 require in-ns)
. someone suggest i instead require it from the start and then toggle the alias on and off, but i'm having trouble figuring out how to toggle if off...in other words, make it as if i had required it without an alias to begin with
The aliases table is used only when resolving Vars at compile time to find aliased namespaces. Once a function has been compiled, it is linked statically-ish against fully named Vars in the namespace where they are defined.
Yeah. If this is what you want, you’re gonna want some sort of API object or map of names to functions to pass around.
i'm not sure what you mean. wouldn't i want to simply want to require it only when i toggle it on and then remove the entire ns when i toggle it off? which would be a slight improvement over do-to since the initial namespace will remain loaded the entire time and just have its functions overriden
A namespace is a mechanism for resolving names to functions. So if you take a step back, if you have a function defined in terms of a thing you refer with an alias from a namespace, that’s a full application of a function which would accept the thing you’re referring as an argument and return a function that does the thing you want.
I’m sorry you want functions that behave differently depending on what namespace you’re in?
i want to stay in the same namespace and be able to toggle whether they're overridden by those in an another one
i had the toggle functions switch namespaces to achieve this same effect effect before and someone suggested i try this instead
So what I’d do is I’d change my functions so that they take as an argument (probably the first argument) a map of keywords to functions, destructure it and call the functions which were destructured out. You can then define two API maps, one for the functions in the current namespace and one for the implementations elsewhere. This way you can switch back and forth between which implementations you’re using without any mucking with namespaces or compilation.
the functions are (some-thing-off)
and (some-thing-on)
. i don't know why i'd have a function where i pass it the names of ~100 other functions to achieve this
i already implemented it one way that's fine, but now i'm asking specific questions about how to implement it another way
specifically, how to have a function that requires a library so that it overrides functions
Because of Clojure’s namespace and compilation model as explained above, you can’t make such a function which doesn’t also (require :reload)
the namespace you’re currently in.
The “best” way is not to do this at all as I’ve been trying to say, but if this is specifically what you want to do and what you desire to improve, no there isn’t a better way.
and it seems like the worst possible solution to have a function that's 100s of words long
i guess there's a question of whether i's better to do (doto 'namespace2 require in-ns)
or (ns namespace2 (:require [namespace2]))
Hello! I need some help… I am getting this error
main │ Caused by: java.lang.NoClassDefFoundError: snow_client/core/Tabel
main │ at service_now_bot.service$evs_for_tag.invokeStatic(service.clj:100)
main │ at service_now_bot.service$evs_for_tag.invoke(service.clj:97)
main │ at service_now_bot.service$fetch_and_enrich.invokeStatic(service.clj:138)
main │ at service_now_bot.service$fetch_and_enrich.invoke(service.clj:133)
main │ at service_now_bot.service$snow_page.invokeStatic(service.clj:150)
main │ at service_now_bot.service$snow_page.invoke(service.clj:146)
main │ at io.pedestal.interceptor$fn__1366$fn__1367.invoke(interceptor.clj:41)
main │ at io.pedestal.interceptor.chain$try_f.invokeStatic(chain.clj:52)
main │ ... 39 common frames omitted
main │ Caused by: java.lang.ClassNotFoundException: snow_client.core.Tabel
main │ at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
main │ at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
main │ at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
main │ at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
main │ ... 47 common frames omitted
when i am running my app from a uberjar but not when i run it in the repl@ericfode Hi! After running lein uberjar
which one of the jar files generated do you run? I don't know why but I've always been lucky running the jar file that doesn't have my version number in the name, if you now what I mean, as an example: mygreatapp-0.1.1-SNAPSHOT.jar wouldn't run but mygreatapp.jar would.
I get
main │ Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Var
main │ at service_now_bot.server.<clinit>(Unknown Source)
main │ Caused by: java.lang.ClassNotFoundException: clojure.lang.Var
main │ at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
main │ at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
main │ at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
main │ at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
main │ ... 1 more
➜ service-now-bot git:(master) ✗
@arrdem that makes sense. I am trying to get it into an uberjar so i can put it in a docker file
The first stacktrace you posted is an AOT problem, you’re referencing a class (`snow-client.core` contains a deftype
or something it looks like) before the Clojure code which defines it has been executed.
https://github.com/hiredman/clojure-site/blob/df56aef005d5d867213a51c2d3bbec5a86b0acad/content/guides/running_a_clojure_program.adoc first step is to turn off aot
(that doc explains starting a clojure programming with aot compilation, which is 95% of the reason people give for needing to aot compile)