Fork me on GitHub

Why is it that when is a macro and not a function? Can be written both ways?


idk if this is a valid implementation. Macro implementation is a lot shorter


It's so that the body isn't evaluated if the predicate check fails.


Try this: (when false (throw (Exception. "Doesn't happen")))


Just like if


Exactly. The implementation of when actually just uses if.


Yes, I was reading it some minutes ago


ok, that makes sense

Nate Sutton18:05:17

given I have (.), how do I append the vector [1 2 3] such that I get (. [1 2 3])

Nate Sutton18:05:06

(cons '(.) [1 2 3]) results in (. 1 2 3)

Nate Sutton18:05:21

I'd use (cons '(.) '([1 2 3])) only [1 2 3] is actually a var


If you want (. [1 2 3]) from (.) and [1 2 3], you could do (concat '(.) (list [1 2 3])). Using cons gives the list (.) as the first element instead of just ..


(cons '. (list [1 2 3])) also works

Nate Sutton18:05:28

ahhh list is the bit I was missing out on, I think. I tried a bunch of these variations but list lets me reverence the vector at my-list and transform it into a list

Nate Sutton18:05:32

I was trying to figure out dynamic method calls on java objects like this:

(def my-list [1 2 3])
(def my-method 'count)
(eval (concat '(.) (list my-list) (list my-method)))
;; => 3


I can't seem to truly grasp how others use namespaced keywords in practise and what the thought behind it is (or well I do, unique keys). Let's say I have a danger.core.login.specs namespace. If I want to construct maps with namespaced keywords I would have to require the danger.core.specs namespace with an alias everywhere I want to use it? e.g (:require [danger.core.login.specs :as entity]) and then ... ::entity/login-form`? Is that idiomatic?


There’s a shorthand for defining namespaced maps:

#:my-cool-ns.whatever {:name "example" :age 51}


No need to require. Keywords are just… keywords. 🙂


You have to require if you want the alias


I usually don't use the sugar unless I don't want my keyword being used outside of the namespace I'm defining it in


Sort of like naming something like ____thingThatMostConsumersShouldntNeed


I usually find it better to manually namespace things. But then they can get real long :slightly_frowning_face:


True that require is needed for aliasing. It would be weird to require a namespace only for aliasing keywords.


require is not needed for aliasing.


user=> (alias 'foo (create-ns 'bar.quux))
user=> ::foo/x
That's what we use at work to provide aliases without requiring a namespace -- since our keywords don't need to match namespaces.


Also, we use qualified keywords for partitioning keywords into "domain groups" so they can't conflict.


Good call, I had forgotten about alias.


e.g., :api/country, :membership/transaction-id


ah, cool. Thanks for the insight everyone!


Doesn't work in cljs tho :slightly_frowning_face:


yeah I just tried it out in cljs, got the same issue


It's because the aliasing is tied to the ns actually existing as a file


I'll go with the manual aliasing aka constructing maps like @valtteri mentioned for cljs. I really want my specs to guide me when I look at the code 6 months later 🙂.


why would I be getting "circular dependency detected" when I require/reload in cljs?


Have you required an ns that also requires the first ns?


I promised to give Clojurians some experiences regarding Purely Functional training web site ( I have watched the first sessions in the "Repl-Driven Development in Clojure" series and it looks really promising. I really like Eric's teaching style. He gives nice background regarding topics he's teaching. And in the latest session I started to watch he explains the way he uses the Clojure REPL as part of his development process. You can clone the repository he is using as an example, and it's really nice to be able to pause the video and try the same expressions yourself in your own REPL session. I'll give you more experiences later. But already I can say that if you are an absolute beginner Eric can give you a quick start in your Clojure study path.


I just finished watching the last few lessons last night. It's a great course -- and a subject that I've been very passionate and vocal about: learning a productive and instinctive REPL-based workflow.


@seancorfield Is the db as a first arg to functions a personal preference or is there more to it?


To run tests from CLJ command line its:

clj -C:test
clj -A:test


@lockdown- I typically put arguments that change the least at the front -- so you could partial them. I try to do that with all my code.


ah partial is a good reason


@papachan -C will only bring in classpath-elements. Generally you'll want -R for resources (dependencies) and you may need -M for main options, for actually running tests. So -A:test makes more sense here: -R + -C + -M.


Thanks @seancorfield it worked fine for me !


@papachan -C:test would just add :extra-paths, so just the "test" path. In general tho' you're going to have test dependencies, such as test.check etc which would need a -R option for :extra-deps, and you may have a test runner involved that would need a -M option to bring in its :main-opts (hopefully that's clearer than my previous message).


@lilactown yes. Using this project: I compiled it (had to do npm install jquery) and connected to it with cider from the main.cljs file, switched over to it with , s N (which sends the ns declaration) then I tried just adding a def to the file (def foo "abc") and did (require 'app.main :reload) and get that circular error. In the repl I find that foo is unknown/null


There's a lot in that message. Not sure what's going wrong


Your cljs code by default hot reloads on file change so you shouldn't need to require it like thay


But also I'm not sure how you're connecting to the REPL, if you've successfully gotten into a CLJS repl or a Clojure repl


I use the cider-connect-cljs command