Fork me on GitHub

How would you go about executing multiple expressions when a case is true? When I wrap it in (do...) I get nothing. When I remove it it at least loads base.css


Hum, do should work, but I'm confused about your nested case?


You are embedding this in some kind of dsl for expressing html as data


Do composes side effects


But does not turn 2 pieces of data into one piece of data


How you do that will depend on what the interpreter for the data structure you are building accepts


Likely just create a list

👍 1

I'm using hiccup.... using a list makes sense. Lets see.


@U0K064KQV me too lol. I have pages that have different styles to them so i'm using feeding in a map to tell what type of page is used and it includes the right stylesheet.


No dice... even (apply include-css ["css/base.css" "css/style.css"]) doesn't work. Alrighty, I'm going to take a different route. I've seen this work but the person was using rum.


No, just make a list


(list (include-css ...) (include-css ...))

hiredman03:04:13 and include-css from hiccup does indicate it would work with apply anyway


Did that as well... that should work. It may be something else.


Is the include-css you are using that one?


yeah, i was looking at that and that gave me the idea to do (apply...) . Yup


It does work like that, so the fact that it doesn't for you means you have something else going on, how are you rendering the hiccup?


My guess is you aren't rendering it using the html function from the hiccup library, but something else, which doesn't know how to render seqs/lists (which hiccup does)


Thats what i'm thinking. And I've verified both stylesheets work before I started toying around with 'case'. Then 'case' does work because when I go to my 'vivarium' page it loads that stylesheet correctly.


Have you looked at the html that is being rendered?


How sure are you that what you are looking at corresponds to that code? Have you restarted your process to make sure it is running code that is on sync with what is on disk?


omg i'm sorry.... o_O


wtf,,,somehow I deleted my style.css


Ok, it is indeed working. I know exactly what I did.... I cut some code from style.css and put it in a register to move to a new namespace *using Garden' and completely forgot about it.

Godwin Ko06:04:05

When writing macro, can I invoke functions in dependency libraries other than those in clojure.core? Does the compiler environment the same for clj & cljs? :thinking_face:


You can invoke Clojure and cljc functions, but not Clojurescript.


I'm learning Clojure for 2 weeks. I aim to build a web app with Clojure backend and a Clojurescript frontend. I see there are three Project configuration tools, Leiningen, Clojure CLI tools and Boot. Which tools should I use?


The web app code will be the same regardless of project tool. Leiningen is pretty self contained app with a few pluggins, using Clojure for the project configuration Clojure CLI is a collection of tools and configurations, using data (edn) to define a project (and Clojure if there is a need to define custom build tasks). Both are relatively easy to pick up, although Leiningen has fewer pieces. Boot didn't really get that wide an adoption in the community


There are some projects building web apps in one of my books

practicalli-johnny10:04:33 is a flexible template for creating full stack projects that can provide examples. There are lots of options to try, so suggest trying to keep it simple to start with


There is also which is a newer project (I think from some of the same authors of Luminous)


If you are following some tutorial or book, then use whatever tool that uses. If you are building your own project, I'd recommend learning and using the CLI tools.


In a macro like with-precision, can I dynamically pass the precission from a variable at runtime?


You have to give a bit more information) can you share this macro?


It’s on clojure.core


It’s used as

(with-precision 10 <decimal ops...>)
but I’d like to have precision to be dynamic, wondering if there is any way to do it


macros cannot use run-time data unless you call them at runtime (eval)


and eval is usually a sign you are making a big mistake


if you look at the macro itself, it shouldn't be hard to use the uglier expanded version with a runtime determined value


(cmd)user=> (defn example [precision] (binding [*math-context* (java.math.MathContext. precision)] (/ 1M 3)))
(cmd)user=> (example 10)
(ins)user=> (example 2)


yeah, so far I’ve been doing the binding of math context myself, wanted to make sure i wasn’t missing something on macro side. thanks!


Is there any convention (naming) for functions that return functions? I feel like it would clarify my code, compared to functions that return another value type. In this particular case, I bind some predicate conditions using a closure and return a predicate with lower arity. But then using the question-mark convention seems off. It is not a predicate, but it returns a predicate.

Darin Douglass13:04:05

i tend to use -fn as a suffix

👍 1
☝️ 1

I have seen -factory used in other contexts.


I like @U02EA2T7FEH’s -fn suffix. By the way, would this be a situation where specs or metadata and tooling could help as well?


I think returning a function is normal and expected and doesn't need a naming convention

💡 1

For what it's worth, I also think it is normal... But I still appreciate your opinion! 👍🙏


• OK, so to conclude the original question, no one seems to be aware of any such convention. • I noticed that it is indeed often easy to see by the position where the function is invoked that it must return a function. (Like when used with map, filter and such higher order functions). No real need for a special name for that reason. • Let me explain that my original trigger was not so much understanding (reading) code that was already written and working, but rather while I was writing new code I noticed I liked making many very similar helper functions, differing only in parameter style (takes collection or &args / apply, etc.) and return value. Thus it became a challenge to name them well, and to know which variant to pick in each case. I know what type i need it to return (e.g. a predicate), but what was that one named again? • I think this has been remedied a little by improved style now. One strategy I use more now is to combine such similar functions under only one polymorphic function name, using multiple arities (& sometimes dispatching on the parameter-type). In such setups there are fewer function names to remember. It makes sense that this returns a function if the parameters are under-specified, but return values when parameters are fully specified. • I have noticed I have also improved in making small composable functions (that often return functions). Efficient composition makes the calling code compact enough without a nagging feeling that every usage variation needs to be factored out into its own helper functions. • I might possibly use -fn or -p or some such convention if I feel it helps in some particular case, and (no offense), I don't want to make more "factories" in programming anymore 😉


Tip for fellow beginners: Using Visual Studio Code with Calva, the command “” is convenient as a scratchpad when exploring and trying things out, messing around with code examples from Clojure books, etc.


This is what my book-reading setup looks like.


You can open a PDF directly inside VS Code so you can move it around just like another tab/panel. No need to have your editor and reader side-by-side.


Awesome! Thanks for the advice, @U04V70XH6! I have my PDF books in the “Books” app so that my highlights, notes, etc., sync automatically between iPad, iPhone, and macOS. Else I would have done that right now!


Ah, I've switched away from macOS to Windows/WSL2 (after being a Mac user since the early '90s) but, yeah, having a cross-device sync'd PDF reader is a good reason to tile the editor and the reader 🙂

👍 1

Yeah, it’s pretty nifty! The only thing that sucks is that it doesn’t sync my read location, so I must manually remember and scroll to the right place when switching devices.


You can do the same in Cider (Emacs). If you open an empty buffer and just jack-in, it'll connect you to a default REPL with only your deps from your user deps.edn


Oh, interesting… I just tried this:

(= 'something (quote something)) ;; => true
And learned that 'something is equivalent to (quote something).


Try ''something (just type it in your repl)


Huh! Would you look at that…


I went too far…


Is it actually more interesting in the standard repl


Whatever you are using is doing some pretty printing that is obscuring things


Also (read-string "'something")


Oh! How peculiar.


It's all quite logical. First your source code is "read" by Clojure. When reading your source code, the text: 'something is translated into (quote something). We call that read-time, which is the set of translations Clojure applies when reading source code. Once you have (quote something), that is then evaluated as code, when that happens, quote is a special form that tells the compiler that what follows shouldn't be evaluated, but returned as unevaluated code. Thus evaluating (quote something) will return something. This all happens recursively, which is where the mind bending occurs. ''something is read as (quote (quote something)) And when you evaluate (quote (quote something)) the first quote tells Clojure not to evaluate the rest but return it as it is unevaluated, and so you get (quote something) back. Some printers will if you want "unread" things so you get them back in source code format in a way that they can be "read" back into the same thing, that's why you might see it printed back as: 'something

💡 1

It takes a while for all this to sink in, but it's all based on a simple set of logical steps, but together they compose to produce results that can be a bit difficult to reason about at first.

👍 1

Clojure has 3 translation steps normally:

<source code>
  -read-> <code>
    -macroexpanded-> <code> 
      -evaluated-> values


read-string takes a string of <source code> and returns you the <code> for it as read by Clojure. So it lets you see what the read translation looks like after reading.


This is a good read: Even if you don't understand everything right away. I think it's good to read it. Later as you practice more Clojure you'll start to have that click and it's good to have it in your brain.

👀 1

Also (read-string "'something")