This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # beginners (15)
- # boot (4)
- # cider (1)
- # cljs-dev (2)
- # cljsrn (5)
- # clojure (124)
- # clojure-france (2)
- # clojure-russia (22)
- # clojure-uk (10)
- # clojurescript (50)
- # core-async (5)
- # cursive (3)
- # datomic (8)
- # emacs (2)
- # fulcro (10)
- # hoplon (8)
- # jobs (4)
- # luminus (2)
- # lumo (7)
- # off-topic (14)
- # portkey (7)
- # re-frame (22)
- # reagent (2)
- # shadow-cljs (3)
- # spacemacs (1)
- # yada (26)
Thanks! It's quite ironic actually, the numeric part I'm optimizing now I assumed I would be able to swap out for a library yet none come close to meeting my needs, whereas the complicated control flow analysis and source transformation already existed.
can any-one explain how the following would be converted to clojure, including the import.
ArangoDB arangoDB = new ArangoDB.Builder().host("192.168.182.50", 8888).build();
ArangoDB is a class Builder is a static class inside ArandoDB, Builder calls super() host is a method on Builder build() is method of the ArangoDB class
@beoliver inner classes don't really exist on the JVM, they're simply naming sugar. So You'd want to import ArandoDB$Builder
@the2bears @tbaldridge - the code is directly from the git hub page for the project https://github.com/arangodb/arangodb-java-driver (i think they used
maxConnections(...) instead of
host(...) but same difference.
seems to work (at least it returns
(.build (-> (new ArangoDB$Builder) (.host "127.0.0.1" 8888)))
#object[com.arangodb.ArangoDB 0x703a3035 "[email protected]"]which is something 😄
@genec It seems nice - havn't used it enough to be critical, but I have the impression that most people that use it are satisfied (obviously not clojurians by state of the libs)... Trying to decide if I should write a wrapper around the java lib or just write a new one? The most popular clojrue lib https://github.com/Lepetere/clarango looks dead (hasn't been touched in 2 years - and looks like version 3.0+ of the db breaks it)
I've come unstuck again with these nested classes. If anyone has any hints feel free https://stackoverflow.com/questions/46390544/clojure-importing-nested-classes
what is the best practice for naming methods which handle different types, ax example: i have two namespaces A and B both should has method foo but each will handle different data structure, so it's the best to use them as A/foo B/foo or write multimethod which handle them ?
@abdullahibra don't use multimethods unless you really need to, they have runtime performance implications, they are not composable and they are less readable than plain functions. IMO multimethods are worth it when you need runtime polymorphic dispatch which is open. by open I mean that you expect consumers/callers of your code to potentially extend the hierarchy by defining their own implementation. From what you wrote it does not seem to be the case. Why not renaming your functions to
B/foo-with-ds-b if you want to be explicit, or don't rename them and implement runtime assert/spec to warn caller about wrong data structure passed?
@abdullahibra Generally, I namespace all functions I use. I'm presuming that the different data structures they handle are indicated (even partially) by their namespace, in which case I would go with A/foo or B/foo every time. It's not often that I
and one last note, if you needed to do one umbrella function which does the dispatch, you can write it as plain clojure function, say X/universal-foo, which has one huge
cond to dispatch to individual namespaces based on data structure passed, this would be like multimethod, but closed (and without unneeded overhead).
Hello. Is a list of all Clojure reserved words (like
if) etc available somewhere?
technically, there aren’t really any reserved words other than “true”, “false”, and “nil” - those are the only special symbols read explicitly in the reader
almost everything else is a namespace or var name (that you can shadow and use yourself).
there are some special forms that the compiler understands, as defined in https://clojure.org/reference/special_forms. Everything else (and even some of those) are just vars declared in clojure.core namespace
UPD: found something here: https://github.com/vim-scripts/VimClojure/blob/master/syntax/clojure.vim#L31
Is Clojure macroexpansion performed depth-first or breadth-first? Is it possible to change that?
@andrewboltachev "outer" macro is expanded first and its result is expanded further until there is no further expansion detected
and there is no recursion there - the top macro will receive the unevaluated forms
@andrewboltachev I believe you can write your own macro-expanding for code you receive in macro as input, this way you can reverse the outer-inner order. This is what I did: https://github.com/binaryage/cljs-oops/blob/master/src/lib/oops/compiler.clj#L21-L36
it is cljs-related, but the idea should be similar, you can "force" macro expansion on your input if you really need
there are some custom macro expanders out there like https://github.com/ztellman/riddley
And you can use all others navs, like
(transform (walker number?) inc '(let [n 1] (+ n 1))) => (let [n 2] (+ n 2))
continue-then-stayand recursive stuff
@darwin huh great. Btw, it all ends up to use prewalk/postwalk (though it's not a recursion)
In fact, I'm trying to rewrite the code in such a way that I'll touch only functions
if I want a single api that: on jvm: provides cuda acceperated blas on js: provides some blas api is core.matrix the best way to go?
@andrewboltachev I'm not that familiar with this, but I believe you can look at metadata of individual sub-forms and get some useful properties from analysis (to determine what symbols are functions maybe). Otherwise you would have to invoke full-blown analysis for your code form, which might be pretty advanced (and slow?) thing to do.
@darwin Yes, exactly. I'll probably just filter out all the macros (pretending there're just a few) by their name. I was just trying to follow the idea: If “code is data”, then let's edit it. But this doesn't work straight away.
well, code is data, but if you want to rewrite it, you should better do it based on a template, not on compiler's analysis knowledge
knowing if a given symbol is a macro, function or something else is not encoded in the form itself
True. In that sense my idea would be better implemented via hacking a compiler probably (which knows that and has explicit step — macro expansion, all the transformations etc)
also you can force macro-expansion on your macro input, so you can work on already expanded code, so there will be no "macro-calls", only "function-calls" and quoted data
there should be also like
:env somewhere? may be this already holds all the macros' names?
as I wrote, if you force macro-expansion, macro names are no longer your issue, you will have to detect quoted stuff, which might look like function calls, but is quoted, so you don't want to touch it
@laujensen if you're running a server, you might probably do this via
apache2 etc) to add certificates
if you speaking of client and have troubles calling https, then you'd better try to figure out if all certificates (of a target server) are in place
I have it running locally with ws:// and its working fine. Then when I pushed to a server running https behind nginx with certs, it just says connection failed. Which I take it to mean that its not getting ported in/not listning on the port
@laujensen you might wanna check this https website of yours with: https://cryptoreport.rapidssl.com/checker/views/certCheck.jsp
@darwin @alexmiller just FYI there's what I came up with: http://dpaste.com/27S1PS9
eval is evil, what if
x is implemented as
i.e. I have another tool that would rewrite 1st symbol of all lists in particular file(s)
user=> (defmacro m2 [x] (eval x)) #'user/m2 user=> (m2 identity) #object[clojure.core$identity 0x56a9c24a "[email protected]"]
user=> (defmacro m2 [x] (when (symbol? x) (eval x))) #'user/m2 user=> (m2 '(println "boom!")) nil
you should be able to find something like
resolve which should be more light-weight than eval and will do what you are afte5r
resolve... uhm, it fires an exception anyway somehow
don't know, but I would be very careful calling
eval on arbitrary input in your macros
if only someone would provide something which is
symbol? and inside hosts sth callable/evaluatable?
why exactly you cannot
(defmacro m3 [form] (my-dbg-transform (clojure.walk/macroexpand-all form)))
my-dbg-transform walks the form and replaces all lists with dbg wrapper, except for special forms and quoted data
i.e. if doing macroexpand vs. this "with-eval" magic is worse in terms of what is possible in keeping all the positions
AFAIK source positions are in metadata, you can be properly providing them if careful enough
In fact, first I'm using project called
rewrite-clj to add this
(dbg ...) forms
you lost me here, if I remember correctly rewrite-clj does source->data->source transformation, or you can use it from a macro? by feeding it forms?
well, I'm first editing a code (say, whole namespace of files) to wrap every 1st member of list with
and then it's everything (functions and macros) wrapped with
dbg macro should leave macros as-is and make functions log themselves
(and in the end I want to build whole call stack/tree and see like wow, it's what has happened when I've ran a request in my very-huge-and-hard-to-debug-project)
I'm afraid this is not going to work. If you rewrite code
(my-macro 1 2 3) into
((dbg my-macro) 1 2 3) you change meaning of it, it might not compile at all, if
my-macro checks args
I was comparing
((dbg my-macro) 1 2 3) vs.
(dbg my-macro 1 2 3) vs.
(dbg (my-macro 1 2 3)) etc
and secondary minor problem which comes to my mind is that rewrite-clj does not use tools.reader, they have their own reader, it won't be able to read everything the same way normal clojure reader would
wait I take my "I'm afraid this is not going to work" note back, I was thinking about
dbg as function, but it is a macro
I think you should go
(dbg my-macro 1 2 3) route, look at 1st arg and decide what code to emit based on it
@andrewboltachev maybe you could mark
my-macro arg in 1st phase
(dbg (my-marker my-macro) 1 2 3) and make
dbg flexible to look it up and remove it from any position
but still it would not be perfect solution, more complex macros could get puzzled by extra arg there
(println "foo" ((dbg when) true "Hello world111!")) (println "bar" (when true "Hello world222!"))