This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-24
Channels
- # 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)
@sophiago sure, feel free to ping me here, or even in a pm when the time comes
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
and yeah, the new
doesn't look right
@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.
well
(.build (-> (new ArangoDB$Builder)
(.host "127.0.0.1" 8888)))
seems to work (at least it returns #object[com.arangodb.ArangoDB 0x703a3035 "com.arangodb.ArangoDB@703a3035"]
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
Hi guys
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 ?
i'm asking about best practice in FP in general
@abdullahibra go multimethods, it'll be much cleaner and readable a month later 😉
@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 A/foo-with-ds-a
and 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?
How are they not composable?
@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 :refer
something.
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 ns
, def
, defn
, 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
thanks@hmaurer. I tried this one, but it's incomplete
huh, that's really quite a bit: http://dpaste.com/0P9XQEW 😄
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
@darwin got it, thanks!
and there is no recursion there - the top macro will receive the unevaluated forms
so it’s neither breadth nor depth first as far as I would say
aha, got it. ty @alexmiller
@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
With #specter
(transform (walker number?) inc '(let [n 1] (+ n 1)))
=> (let [n 2] (+ n 2))
And you can use all others navs, like continue-then-stay
and 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
(when x (fn1 a b))
-> (when x ((dbgfn fn1) a b))
(but I got ((dbgfn when) x ((dbgfn fn1) a b))
)
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
macro vars have {:macro true} meta on them, in case that’s helpful
@laujensen if you're running a server, you might probably do this via nginx
(or 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 is all the proxy_pass
etc in place?
@laujensen you might wanna check this https website of yours with: https://cryptoreport.rapidssl.com/checker/views/certCheck.jsp
(or other provider's tool, this one for RapidSSL)
@laujensen you might also check with curl
@darwin @alexmiller just FYI there's what I came up with: http://dpaste.com/27S1PS9
@andrewboltachev eval
is evil, what if x
is implemented as launch-nukes-to-north-korea!
?
@darwin it just evaluates to the name, and doesn't do actual function call 🙂
i.e. I have another tool that would rewrite 1st symbol of all lists in particular file(s)
and for me, if this one would work it already would be amazing
e.g.
user=> (defmacro m2 [x] (eval x))
#'user/m2
user=> (m2 identity)
#object[clojure.core$identity 0x56a9c24a "clojure.core$identity@56a9c24a"]
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
just replacing eval
with resolve
... uhm, it fires an exception anyway somehow
i.e. can't macroexpand this way
don't know, but I would be very careful calling eval
on arbitrary input in your macros
btw yes...
and no. can't use macroexpand
arbitary symbol in my case.
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)))
where my-dbg-transform
walks the form and replaces all lists with dbg wrapper, except for special forms and quoted data
well, just I've selected different point of application
as well I want to keep the position inside the source file (line/column)
didn't think about it though
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
(which has that positions info and I'll inject it to there)
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 (dbg first-member)
(fn1 a b)
-> ((dbg fn1) a b)
(before that require
is added to include the dbg)
yes, that's the 1st step
and then it's everything (functions and macros) wrapped with dbg
, thus 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
uhm this is also a problem
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
well, it's "based" on it, but does provide it's own stuff
uhm, here on real code have another "Can't take value of a macro:" error
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
yes sure
oops, it was one with resolve. Will try "eval"
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
this has failed: (-> x (dbg my-macro 1 2 3))
@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
uhm, might also work btw!
but still it would not be perfect solution, more complex macros could get puzzled by extra arg there
uhm I'm still having "Can't take value of a macro"
I mean with (dbg (...original expr...))
btw how crazy is this:
(println "foo" ((dbg when) true "Hello world111!"))
(println "bar" (when true "Hello world222!"))
and I've got
foo Hello world111!
bar nil
(it's inside file itself)
sorry. wrong chat 🙂