Fork me on GitHub
Jacob Rosenzweig00:05:50

Is there a common naming convention for patterns? Something like the convention of using a ? for boolean fns (e.g. string?)


Do you mean for symbols bound to regular expression patterns?

Jacob Rosenzweig00:05:34

Yeah for the bindings themselves. E.g. (def alphanumeric-pattern #"[A-Za-z\d]")


i think we usually prefix with re-. re-alphanumeric etc

๐Ÿ‘ 1
Jacob Rosenzweig01:05:28

I like that. Simple and clear


Looking at our codebase, it seems we mostly use a -regex suffix.

Andy Wootton12:05:09

I like that better. I read -re as "in relation to".


#naming-things is a channel I just started for discussions like these - one of my favorite kinds of channels from other programming language chats.

๐Ÿ‘ 1

anyone have an example of how to copy the contents of a ZipEntry to a string? i cannot figure this out for the life of me - the java docs are quite confusing for input/output streams


i figured it out... you have to navigate to the appropriate entry and then read from the underlying ZipInputStream - not the ZipEntry itself. :man-shrugging:


I'd like to understand better the mechanism behind clojure.repl/source. Here's a snippet:

(ns my-ns
  (:require [clojure.repl :as repl]))

(defn foo [a] (inc a))

(repl/source omicron.core/foo)
This prints
Source not found
I'd like to understand why this happens (isn't my file on the classpath too?) and what's the standard solution to get the source of the functions in your own project.


And by the way, why doesn't clojure put the source code in the metadata for the function? There has to be a tradeoff there, but I'm unsure where!


The namespace my-ns does not match omicron/core


The source function finds the .clj(c) file on the classpath, then reads until the line that is in the metadata and reads the entire form


@U04V15CAJ I made a mistake in copying; but this doesn't work either:

(ns omicron.core
  (:require [clojure.repl :as repl]))

(defn foo [a] (inc a))

(repl/source omicron.core/foo)


Where does your omicron.core source file live?


in src/omicron/core.clj on disk?


yes, but maybe it could be because I don't have the paths set up in my deps.edn?


src is automatically on the classpath, but perhaps if you restart your REPL it will work


unfortunately it doesn't even restarting. I can make a repro example, but it's just the snipped I pasted. I'm using:

;; CIDER 1.3.0 (Ukraine), nREPL 0.9.0
;; Clojure 1.11.0, Java 11.0.12


you don't need CIDER to test this. could you just go into a terminal with clj and then (require '[omicron.core]) and then (clojure.repl/source omicron.core/foo)?


Interestingly, clj errors out when I try the require:

user=> (require '[omicron.core])
Execution error (FileNotFoundException) at user/eval2 (REPL:1).
Could not locate omicron/core__init.class, omicron/core.clj or omicron/core.cljc on classpath.


But the file is definitely called src/omicron/core.clj and I'm invoking clj from the root of the project


Could you do a find . in the root?


or find src


/home/carlo/code/clojure/omicron ฮป tree .           
โ”œโ”€โ”€ deps.edn
โ””โ”€โ”€ src
    โ””โ”€โ”€ omicron
        โ”œโ”€โ”€ core.clj
        โ””โ”€โ”€ new.clj


What's in your deps.edn


for now just {:paths [src]}


can you change that to ["src"]? :)


If you use clj-kondo, you would get a warning about this:


That was dumb on my part, sorry; anyway, now the code works in clj but still not in cider


The clj-kondo warning here is weird too btw, it should just be a string


you should restart cider


I restarted the repl, is that not enough?


the classpath is not updated dynamically, so you have to start a new CIDER REPL. if it doesn't work, perhaps you didn't restart it hard enough ;)


Let me restart it hard enough ๐Ÿ˜„


No, I rebooted everything and I still get Source not found in cider.


What does (System/getProperty "java.class.path") say? It should list src as one of the first things


it does mention src as the first path, yes


So what exactly does not work in CIDER, source doesn't print anything?


when I eval

(repl/source omicron.core/foo)
I get Source not found in the repl.


Maybe ask in #cider - don't know


thank you @U04V15CAJ! I appreciate the help in understanding it has to be a cider issue ๐Ÿ™‚

๐Ÿ‘ 1

Hey folks, wondering what you'd recommend to an experienced dev to get a deep understanding of clojure. Can be a book, blog series, video course, anything really


I presume you mean a dev who is experienced in other programming languages but not Clojure. In that case, I'd recommend just writing your own Clojure code and reading the sources of libraries or Clojure itself. Depending on which other languages the experience is in, the biggest challenge is likely to be unlearning previous habits and learning to think in Clojure. Some more advanced books might be useful too. A good starting point is


Cool, thank you!

Luke Zeitlin17:05:33

Joy of Clojure is my fav clojure textbook

Luke Zeitlin17:05:43

maybe a bit dated now


8 years old ๐Ÿ˜‰


still worth a read I'm sure


I guess I should expand a bit more on what I'm looking for. I've been writing clojure for a few years now but I never really invested time in learning it thoroughly. So I want something that will give me the most comprehensive/deep understanding of the language

Luke Zeitlin17:05:07

oh, probs just read the source code then


ok.. that's 2 recommends for reading the source


Solve an interesting advent of code (or similar) problem in your language of choice, then solve it in clojure, then see how a pro clojurian did it, then gain insight, then repeat.

๐Ÿ‘ 1

A few clojurians here are very fond of the book Getting Clojure


cool, I'll take a peek at that one


I started reading Programming Clojure. Any chance you read that @UA7E6DU04? I wonder how you would contrast the two


Joy of Clojure is a fantastic book - it's not a super easy read but if you have been doing clojure for a few years I really recommend it

๐Ÿ™ 1
practicalli-john22:05:31 has a lot of articles explaining Clojure


Thanks! Yeah I have gone through some of those in the past. I think I'd prefer to have a one stop shop explaining and going into depth. A book seems like maybe the best fit for this?

Ben Sless04:05:44

Reading the source is good All the books with Alex Miller as an author You can also read Bagwell's paper on HAMTs And Rich's talks are also an excellent resource

๐Ÿ™ 1
Young-il Choo00:06:30

Thereโ€™s also Clojure, The Essential Reference by Renzo Borgatti, that provides detailed explanation of every concept. Itโ€™s one of those available while still being written from Manning. Itโ€™s only 1172 pages so far.๐Ÿ˜†

๐Ÿ™ 1

I second Clojure, The Essential Reference too. Probably not an introductory text, but wonderful to read after an introduction

๐Ÿ‘ 2

I recently noticed a nice trick that is actively used in clojure.core eg core_print: code is in a from core and it uses in-ns at the top of the file to be included in the clojure.core ns. I haven't seen this in the wild. Is it cos I haven't seen enough code bases or because it's not preferred by the community for some reason?


clojure.core is a very unusual piece of Clojure code -- and it's a massive namespace -- so splitting it up is, I suspect, just a way to make it a bit more manageable when working on it. I can't imagine any real world production code ending up looking like that...


It's not preferred because it confuses tooling and isn't always supported by tooling, even if it's totally fine in the language itself


yeah, I was thinking that it might mean that the tooling is weak / incomplete.


I don't think that's the conclusion I would draw from it ๐Ÿ™‚


I find it a bit weird that says

At the Repl itโ€™s best to use in-ns, in which case the new namespace will contain mappings only for the classnames in java.lang. In order to access the names from the clojure.core namespace you must execute (clojure.core/refer 'clojure.core). The user namespace at the Repl has already done this.
I see beginners get confused by in-ns in the REPL quite a bit.


Fortunately, in it says (after explaining the mapping from namespaces to files)

Due to this loading convention, most Clojure is structured with a 1-to-1 mapping of namespaces to files, stored in hierarchical fashion that maps to the namespace structure.


And the official guide about namespaces clarifies the in-ns thing

What happens if you in-ns to a namespace that has never been created? You will see strange things happening.
Strange, indeed ๐Ÿ™‚


ok, so weird historical edge case


that persists cos it's working


so I guess it's important for tooling to understand that files and ns are not the same thing, though they tend to be


And because ns uses in-ns as well as several other low-level namespace-related functions...


It's very rare for files and nses not to map 1-to-1. I can't think of anything outside clojure.core that I've seen that does that...?


no - me neither hence the question


I want to support database rather than file based tooling so anything that is unusual in this way is good to know.


I appreciate your comments @U04V70XH6


We have a handful of in-ns calls but they're all in RCFs and they're like this:

(require ' :reload)
  (in-ns ')
(all from my teammate -- I don't use in-ns because my editor/REPL combo always switches to the right ns to eval code automatically)


I know until recently you also had to load the namespace in CLJS but that was fixed


"recently" being a few years ago ๐Ÿ™‚


Rich Comment Forms


(comment ..) with dev-only code in it (generally). Stu Halloway coined the term because Rich uses them quite a bit ๐Ÿ™‚


I don't know, I think you could argue the tooling is incomplete, but also the idioms people ended up with tend to not split a namespace across files, and so the tooling never had to take on that additional complexity. in-nsis also harder to work with for tooling, because it doesn't have dependencies, instead you would have other calls to refer or require, so it's a lot harder to manage for tooling. in-ns is the special form and it mirrors Common Lisp more, it's more primitive and less useful. Even at the Repl, I personally use ns to switch even to existing namespaces.


Though it looks like in-ns and ns actually both start out as the same thing, both special forms, and then ns is rebound to the core ns


clojure.core does a lot of weird stuff as it is bootstrapping the language across that whole namespace...

Ben Sless04:05:10

@U04V5V0V4 how about breaking the REPL into its components? Read analyzes and inserts to the db, eval takes an id, reifies and evals


@UK0810AQ2 it's not the way I'm going but it sounds like an interesting approach!

Ben Sless09:05:35

@U04V5V0V4 are you trying to go the Unison way where terms that are alpha equivalent are semantically equivalent?


I don't know what that means

Ben Sless10:05:16

In Unison things like (fn [x] (inc x)) and (fn [y] (inc y)) are equivalent and saved/linked in the same hash (db entry) I was wondering if this was the main thrust of your question wrt saving code in a database


ah no, it's not that smart. I'm only tracking named vars per ns.


Those kind of similarities could be detected based on the data but that's downstream


the level of ambition is small: a fancier, better informed editing experience for Clojure

Ben Sless10:05:51

A good start would be saving the form as metadata ๐Ÿ™‚


spec/conform is my weapon of choice


pretty sure all that code predates an actual ns form but not sure


how would in-ns work back then?


namespaces existed. just not the ns macro


ah ok - yes, I see now that the first check-in of clojure.core also used in-ns


The issue is that the ns macro is defined in clojure.core, so you can't use the ns macro before it has been defined obviously, that's why clojure.core has to use in-ns


Actually, it seems like ns is first available as a special form that's similar too in-ns but works as a macro, and then it gets replaced by clojure.core's ns


What's the best way to render user-provided Markdown with hiccup2 (that respects escaping) :thinking_face:


what does markdown have to do with hiccup2?

Andy Wootton12:05:15

Markdown is often rendered into HTML for WIKI web pages. This exists but I haven't used it


@U04V15CAJ I figured it out, I guess it was too late yesterday ๐Ÿ˜… According to Markdown spec it doesn't escape anything. And hiccup2 does, everything by default. And it's a bad idea to render as raw. So what I have to do is to escape the input first, render to Markdown, and then use raw

Drew Verlee22:05:57

@U030521UZ1N can you explain how hiccup escapes everything? As an aside, the terminology "escaped" is really weird to me given what it's about, i never thought about that description very much.

Drew Verlee22:05:19

It's just a way to have reserved functions. like & has special meaning in a url, it's not just a string.

Drew Verlee22:05:36

but what's escaping? getting free? running away?

Drew Verlee22:05:43

i guess if your the character "&" your escaping the pool of reserved words/symbols.


> but what's escaping? getting free? running away? I'm not native speaker, but there is no need to be sarcastic. But here you go:


I guess you should ask James Reeves why he picked this name


Calling this escaping is common CS terminology. You're replacing special characters with escape sequences.

Drew Verlee13:05:10

I wasn't being sarcastic. I was wondering about the words etymology.

๐Ÿ‘ 1
Andy Wootton17:05:45

'Escape character', Wikipedia: "Not to be confused with control character, escape sequence, or Escape key." :-/

Drew Verlee17:05:24

For me, it's easier to think of them as reserved keys/chars/function. I can't get the & table the restaurant, i can get the &foo table though and tell my friends a lie about the name.

Drew Verlee17:05:00

Idk. Communication is hard.

Andy Wootton18:05:22

I think the escape sequence was called that because the escape key was the original character used. I was just looking up why the key was called that, when I came across that helpful warning.

๐Ÿ‘ 1