This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-03
Channels
- # announcements (4)
- # beginners (68)
- # boot (3)
- # business (20)
- # cider (39)
- # cljs-dev (7)
- # cljsjs (1)
- # cljsrn (12)
- # clojure (122)
- # clojure-brasil (2)
- # clojure-italy (7)
- # clojure-nl (5)
- # clojure-spec (60)
- # clojure-uk (41)
- # clojurescript (67)
- # cursive (7)
- # datomic (13)
- # emacs (6)
- # figwheel-main (18)
- # fulcro (40)
- # garden (3)
- # graphql (2)
- # hyperfiddle (4)
- # jobs-discuss (10)
- # lein-figwheel (5)
- # leiningen (12)
- # luminus (6)
- # mount (3)
- # off-topic (52)
- # portkey (2)
- # re-frame (1)
- # reagent (6)
- # reitit (24)
- # shadow-cljs (15)
- # sql (3)
- # tools-deps (12)
Or this? 🙂
#((apply vector %1) %2)
vec/vector .. confusing
I was already wondering why (vector) didn't work on its own
vec
converts another collection into a vector, vector
creates a vector with the arguments as elements, e.g
Can some one tell me the difference of the below (let [ k "rain"] (println (str "It is going to " k))) It is going to rain nil (let [ k "rain"] (str "It is going to " k)) It is going to rain Why are we using the println when str does the same?
'println' is a side effect. It actually prints the string to stdout. The return value of the form is 'nil'. The return value of the second form is the string which happens to be printed in the repl. So it feels the same but it's not
Thank you @UBWJ6QDGF
just to make it a little more visual: if you run the println
one as a standalone program, this is your output:
It is going to rain
If you run the str
one as a standalone program, this is your output:
(it's nothing)Standalone program in the sense, (println "Hello") - Hello Because when i run as (str "Hello") even this get printed?
this only works because of the REPL prints return values by default; the following is worth understanding as well:
(let [k "rain"]
(str "It is going to " k)
(str "It is also going to be cold"))
@U8RCW3A2Y why latter was printed ?
Because the return value of let
is the last form inside of it, and the REPL only prints return values
The latter one is not being "printed", it is the return value of the of the function. When you run a function in the REPL it outputs the return value, but that output is different from the output of an actual print statement
(let [k "rain"]
(println "This will print")
(str "It is going to " k)
(str "It is going to be cold"))
Thank you @U8RCW3A2Y @UCQL6E7PY 👍
Glad we could help, this stuff can be hard to wrap your head around at first.
Really the only purpose of non-final forms inside a let
binding is for side-effects.
It's probably also worth noting that, in the REPL, you actually saw two lines from your println
case:
It is going to rain
nil
So you are seeing the REPL print the result -- nil
-- as well as the side-effect of println
itself.In the str
case, the REPL still printed the result -- which was the whole string.
Thank you @U8RCW3A2Y @U04V70XH6 👍
Is there anyway I can 'inject' a variable in a cljs file during build time? using lein cljsbuild auto
?
@mario.cordova.862 See the :closure-defines
compiler option
@mfikes Thanks! I am using :closure-defines
but its not replacing the default value for some reason. Still poking around though
How do you define :closure-defines
if you have a ns set up as (ns myproj.api . . .)
?
so, when we are writing Clojure code, you're literally writing lists and nested lists? and it happens that, for your "code", i mean, list haha, be evaluated, clojure reader expects your first item to be a function, a macro or a special operator, else an exception is thrown. Is that correct?
That’s a pretty good summary, of course it’s not only lists but also vectors, maps etc but that’s the general gist.
yes! wow Clojure is awesome haha
user> (class '(+ 1 1))
clojure.lang.PersistentList
Which turns out, that a List is just a directly implementation of lSeq
user> (seq? (cons + (cons 1 (cons 1 '()))))
true
user> (eval (cons + (cons 1 (cons 1 '()))))
2
my mind is going to explode
one small gotcha here: the list?
function isn't actually something you should use (it returns false for most seqs, and for cons for example)
yeah, i noticed that, when i have to check if it's a list, i prefer to use seq?
If anyone was curious >For :optimizations :none, a :main option must be specified for defines to work, and only goog-define defines are affected. :closure-defines currently does not have any effect with :optimizations :whitespace.
I'm struggling to convert a java sample to clojure as I don't know java. Anyways, i'm trying to convert the below sample
SharedKeyCredentials creds = new SharedKeyCredentials(accountName, accountKey);
final ServiceURL serviceURL = new ServiceURL(new URL("http://" + accountName + "."), StorageURL.createPipeline(creds, new PipelineOptions()));
containerURL = serviceURL.createContainerURL("quickstart");
(defn blob-client []
(let [s-url (ServiceURL. (java.net.URI. "") (StorageURL/createPipeline (storage-creds) (PipelineOptions.)))]
((.createContainerURL s-url)))
for starters, I'd turn every definition in the java into a let binding
(let [creds ... service-url ...] ...)
((...))
in an interop form is pretty much always an error
you should be able to have a translation where each line of java becomes one line of clojure
I'm specifically confused about how to create this serviceURL.createContainerURL("quickstart");
I have a service-url
let binding but I can't seem to figure out how to call a method on a bound variable
(.createContainerURL service-url “quickstart”)
going through "the joy of clojure" and looking at the section that describes having tests in meta data the get ran by clojure.test/run-tests.. Is there a rule on a time and place to use this functionality, or is it best to keep tests in a test directory?
I've never seen a project that actually uses that feature
@alexmiller Thanks!
Thus that would do a component-wise addition of the two vectors? Or is that the wrong thinking and I'm better off making a function? Cheers
the problem is that +
isn't defined in a way that allows such extension
you could make your own plus
multimethod, that uses +
for numbers, and your own code for data structures
that's also true, but more tedious to use from other code
Making its fully qualified name clojure.core/+ would involve unpleasant and fragile surgery that others could not consume easily. making its fully qualified name my.new.ops/+ is much easier.
right, clojure.core/+ isn't really extensible (IIRC making it extensible would be really bad for clojure performance)
so you'd be making a standin for it, that can be extended
or maybe you care about performance, then you'd likely be looking at one of the matrix libs instead of doing all this yourself...