This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-12
Channels
- # aleph (10)
- # beginners (62)
- # boot (12)
- # cider (97)
- # cljs-dev (171)
- # clojars (1)
- # clojure (224)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-russia (1)
- # clojure-spec (41)
- # clojure-uk (68)
- # clojured (7)
- # clojurescript (115)
- # community-development (4)
- # cursive (2)
- # data-science (1)
- # datomic (18)
- # duct (40)
- # emacs (1)
- # events (1)
- # fulcro (148)
- # funcool (2)
- # graphql (2)
- # immutant (3)
- # jobs (3)
- # keechma (1)
- # luminus (2)
- # numerical-computing (1)
- # off-topic (19)
- # om (6)
- # parinfer (10)
- # pedestal (15)
- # precept (86)
- # reagent (12)
- # ring (3)
- # ring-swagger (2)
- # shadow-cljs (42)
- # spacemacs (19)
- # specter (17)
- # sql (11)
- # tools-deps (78)
- # unrepl (62)
- # vim (28)
hi there! I am not sure that this is a right place for asking that. But, I’ve started to learn clojure a week ago and want to ask you guys to review my PR. Nothing complicated there. I’d like to hear any issues with style or more elegant ways to do something. Will appreciate your help. https://github.com/finomayato/ad-astra/pull/1
I have a hunch there is a built-in macro you could use instead of (if (nil? commands) nil (do...
. Maybe take a look at when-let
or if-let
?
Also, there's a lein plugin called kibit
. You can run it on a codebase, and it will analyze your code to try to suggest idiomatic changes
@U9N3MM3H8 ^ in general, the when
forms are for doing a do
form but only under certain conditions, or after making a binding
@mathpunk didn’t get the last one. What do you mean by “when forms”?
and when-some
- which specifically checks for nil
(if (nil? x) nil ...)
directly translates to (when-some x ...)
- they will compile to the same byte code
Thank you so much, guys!
Is there a way to pass a function to another function (or macro) that contains a macro? Maybe my specific example will make this more clear. I’m trying to make this work: (.... foo [f] (meta #'f))
but i’m a bit rusty on macros and i’m having trouble understanding my options.
I’m guessing because the meta macro happens at compile time i can’t do this
This works! Thanks. Huh, i must not understand something about how macros work.
Well, if you macroexpand it you can see it turns into what you want. But is there some aspect that is not clear?
1) right so defmacro stops evaluation of the passed arg 2) ` means dont eval anything inside this until returned 3) ~ means execpt eval this? argh. i need to re-read how everything works it seems
(By the way, foo
can't be written as a function; if so f
would be a function object, associated with 0, 1 or many vars, and you can't find out inside the function)
thanks again. No need to try to type out an explanation i can find stuff :0
kk. I have all the books, so i’ll just refresh my memory.
@drewverlee The syntax quote stuff prevents the need for writing harsh stuff like
(defmacro foo [f] (list 'meta (list 'var f)))
Perhaps understanding of syntax quote also involves realizing that it works outside of macros. Hrm.
Or, perhaps the simplest:
`x
which gets turned into user/x
if you are in the user
namespace.@mathpunk the ring wrap-params middleware will put the request body into a key on the request - but even without that you can find the body in that request map. Recall that the req is a hash map, you can look at what's stored under the keys, and you can make middleware that puts things under new keys.
@noisesmith hmmm see that's what I thought, and so I expected, if I just put req
into my response I'd see a map with my test data inside, and infer the structure from it
I’m doing this inside some cljs code:
(set! (-> @chart .-data .-datasets (aget 0) .-data) (clj->js (reverse temps)))
I’m getting errors sometimes about array access now because sometimes there’s no elements in datasets
Can I convert this using cljs-oops
like this?
(oset! @chart "!data.!datasets.!0.!data" (clj->js (reverse temps))
I didn’t see anything relating to array access in cljs-oops
.@duminda one option is to use some->
which short circuits if any value is nil
or do you want to create index 0 in .-datasets if it isn't there?
@noisesmith: yes I want to add element if it’s not already there.
(.. (OctetSequenceKey$Builder. k)
(keyID kid)
(algorithm (or alg alg-a128kw))
(keyUse (KeyUse/ENCRYPTION))
(build)
(toSecretKey "AES")))
is that similar like at Clojurescript interop? or exactly what means the two dot?How to correctly distinguish prod and dev environment when running web application via uberjar? I am using Environ for setting the dev
and prod
property and I have a profiles like this (no vars are being set)
:profiles {:uberjar {:aot :all}
:env (:prod "true}
:test {:dependencies [[midje "1.9.0-alpha5"]]
:plugins [[lein-midje "3.2.1"]]}
:dev {:env {:dev "true"}}}}
Howeover then I realized that project has probably no way how to distinguish lein run
vs java -jar uberjar.jar
when running the project, so what is the correct way of setting those?environ picks up environment variables, you can set them on the command line, no lein logic should execute on your server, it's a build tool
PROD=true java -jar uberjar.jar
Thanks for tip
@drewverlee Macros are certainly a slippery concept. I have to remind myself over and over: Macros run as the code is being compiled. When you pass an argument to a macro the macro sees the argument more or less as you wrote it in the source (that's all it has at compile time). The macro takes its arguments and does its thing and returns the code that should be compiled. The syntax quoting thing ` is a separate feature, but one that is really handy for writing macros. Syntax quoting is a lot like HTML templating in a we application.
Thanks! Yea. I remember most things correctly.
I suppose there is one other thing about macros: Most of the time that you think you need a macro you don't. 😁
In retrospect, i need a macro to do what i’m doing. But what i’m doing might have questionable value in what it achieves…
I was trying to write a lib that given a set of functions, make them available at the command line. I’m starting to question why anyone would ever need a command line program if they have a REPL though.
I suppose, the user might not now clojure, but imo knowing basic clojure syntax is actually much easier then some of the syntax i see for cli programs…
I suppose if your chaining together programs at the cli? But maybe you should stop doing that.
So I'm kind of a fan of command line programs that don't require me know know anything about the underlying programming language, but maybe that's just me.
But I'm not sure you would need a macro to do that - couldn't you just deal with the functions in question as functional values along with a description of their arguments?
My reasoning was that i need to call meta
to get information about the function (e.g name) and it’s a macro itself so if i don’t stop it from evaling at compile time it will fail as the function var hasn’t been resolved defn expose [f] (meta f)
>So I’m kind of a fan of command line programs that don’t require me know know anything about the underlying programming language, but maybe that’s just me. In general i agree, but I haven’t used a sufficiently complicated cli program yet that wasn’t more complex then clojures syntax. For me, the reason it doesn’t have enough value is because its dependent on clojure and you have to use clojure syntax, so why wouldn’t you just use the repl for something simple.
@noisesmith @lee.justin.m @joelsanchez thanks for the resonating yesterday, and also the practical tips!
@joelsanchez thanks for pointing at data-specs!
I thought I'd just start examining what req
looked like as I learned how compojure works, but I'm stumped
Hello. I'm a Clojure newbie and was wondering if anyone here has used both Clojure and Common Lisp extensively?
depends on your definition of "extensively" in my case (years of clojure at work, vs. I made a few toy things to learn common lisp) - but if you have specific questions there's likely someone who can answer
I did learn common lisp (and scheme) before clojure though