This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-22
Channels
- # aws-lambda (2)
- # beginners (195)
- # boot (47)
- # capetown (14)
- # cljs-dev (7)
- # cljsjs (1)
- # cljsrn (1)
- # clojure (103)
- # clojure-berlin (28)
- # clojure-dev (92)
- # clojure-dusseldorf (3)
- # clojure-finland (2)
- # clojure-germany (3)
- # clojure-italy (4)
- # clojure-russia (37)
- # clojure-spec (104)
- # clojure-uk (52)
- # clojured (2)
- # clojurescript (126)
- # community-development (7)
- # core-async (6)
- # cursive (40)
- # datomic (53)
- # dirac (2)
- # emacs (16)
- # hoplon (5)
- # jobs (3)
- # juxt (12)
- # lein-figwheel (6)
- # leiningen (15)
- # luminus (3)
- # off-topic (49)
- # om (5)
- # onyx (13)
- # overtone (27)
- # re-frame (7)
- # reagent (46)
- # ring (3)
- # ring-swagger (11)
- # spacemacs (2)
- # specter (40)
- # sql (6)
- # untangled (149)
Hello, possible to create from string a function name or generate a function? for example> '''(defn stringhere ...)''' during run the program, the program create new-sub-processes (functions dynamically). Is that possible in Clojure or how? Sorry, if that is very ugly question.. just I used before this.. and maybe easier send a question.
exactly> I would like created new functions and add custom names for this when run the program.
Ok, in this case I need to write the namespace and after this can use the program. is that true when you compiled to java or how works in the real life?
So the compiler will read the UTF-8 string which will just be a bunch of clojure datastructures for the clojure compiler.
Maybe you just want macro?
(defmacro create [name]
`(defn ~(symbol name) [] "Hello"))
(create "xx")
(xx)
Then it'll macroexpand everything. Then it'll compile the datastructures into Java bytecode which you can use
Though, are you sure you want to do this? This means loading clojure code during runtime, usually a bad idea
Ok, I research what can I do.. what is the best in Clojure. Many thanks the quick answer really!!! :+1:
@sb in general clojure is very dynamic, thanks to the JVM, for instance just like clojure dynamically creates JVM bytecode you can do that too during runtime and swap out your functions with those new versions
>>>
clojure beginner here, following the (so far good) braveclojure
tutorial
and at some point it recommends to implement comp
by hand
and there's no solution and I'd like someone to look at it :speak_no_evil:
@nico If you click the + button on the left of the input field you can paste a snippet.
> Reducing over a collection of functions is not a technique you’ll use often, but it’s occasionally useful
i noticed that when I wanted to implement the same in js (I'm very proficient in js and it helps me remember things)
I still don't know when I'll actually use clojure, but if at least it makes my js code better, it's not a waste
Well, you could always write ClojureScript, which compiles to JS :slightly_smiling_face:
the idea is that the dom is slow and that js is fast. So react is gonna create a virtual dom (a copy of the dom, as a structure), and do operations of that instead
and every x milliseconds (rendering cycle), it's gonna apply those changes on the virtual dom to the actual dom
but basically it gave idea to lots of people and now this paradigm of virtual dom vs dom is popping up everywhere (preact, react, inferno, etc.)
and it also leverage the immutabilty in clojure to make that even faster and better (take that one with a grain of salt, I never tried)
Oh, that's a really good idea. Caching the DOM and applying the changes every so often.
@nico have you ever made a large SPA in non-react js? is it laggy compared to the ones made with react ?
but I've been working in react for a while now (give or take a year) and i would never go back to angular 1
it's not actually laggy from what I recall. it's just the way you have to put the pieces together that annoyed me
as I said, I'm a #beginners in clojure, not in js :smile: so I'll just agree with you jcromartie :smile:
mavbozo, iirc, the ui was never an issue, this backbone project is still up and running, but I never liked working on it
@nico I never made a large SPA in js before. It's highly likely I'll make one in om.next
. Thank you for sharing the experience building a large SPA apps.
but the preferred way of checking an empty (including whitespace) string is clojure.string/blank?
@mavbozo Doc is in clojure.repl. You have to do /clj (do (use 'clojure.repl) (doc not-empty))
or /clj (clojure.repl/doc not-empty)
not-empty is often used when you need a sequential object but want to get nil
if it is empty
(if-some [v (not-empty some-vec)]
(transform-somehow v)
[:some :default :result])
@tech_hutch I think you can evaluate clojure in slack by sending a message to yourself in slack (?)
@sova use do
when you have to. There is no reason to use it in a function body, but it makes sense when you need to do more than one thing in both conditional branches of an if.
(if COND
(do
(println "a")
(println "a"))
(do
(println "c")
(println "d")))
Instead of an if
and a single do
, you can use when
.
do
is only useful for side effects because in FP if you discard the return value of some function call, you can as well not call it at all.Sure! Input: (cljs) "[:nf-token \"$s0omeToken\"][:login-time 1487802419][:user-email \"[email protected]\"][:welcome-string \"Hey, welcome back!\"][:encryption-check true]"
Haha my bad. I'm just sending some stuff over the wire and my map gets transformed into a string of vector pairs... i should probably be learning how to use Transit instead
yeah, i'm guessing there's a setting on whatever is receiving that data to "clojureize" it
Haha right. That's true. it's a very brilliant library. can't say the same for the implementor at the moment...
it looks like sente users a standardizer get-sch-adapter
depending upon what transport layer you are using
https://github.com/ptaoussanis/sente/blob/master/example-project/src/example/server.clj
see the make-channel-socket-server that takes an adapter and a serialization format?
but hopefully you are seeing the result of not telling it how to deserialize responsees
Right... I think it's all good, since my websockets comm with Sente is splendid (data works great) but, in this particular case I'm using an Ajax call (because I must manipulate the Ring Session variable, and I cannot do that over web sockets to my knowledge)... so it's kinda a fringe case I'm working on at the moment. I'm not really sure how to pass back data directly over ajax. Although, I suppose I could always do the ajax call to the server to login, set the session, and then web-socket stuff over to the user...
( ^ probably more than you want to know about my current foray into web programming land)
`
(dom/button #js{:id "login_submit_button"
:onClick ;:onSubmit
(fn [e]
(.log js/console (str "Submitting: " login-useremail-input " | " login-password-input))
(sente/ajax-lite "/login"
{:method :post
:headers {:X-CSRF-Token (:csrf-token @chsk-state)}
:params {:user-id (str login-useremail-input)
:password (str login-password-input)}}
(fn [ajax-resp]
(infof "Ajax login response: %s" ajax-resp)
.....
`