5 ms·
Clojure.core: Batteries Almost Included
- trothoun 13y agoThe core.match example uses python-style triple quotes. Is that actually possible in clojure? I would be enormously excited if it is.
- omaranto 13y agoI don't think clojure has triple-quoted strings. Something like """ a """ parses as three strings, two of which are empty: "", "\na\n", and "". (Clojure strings are allowed to contain literal newlines.)
- adambard 13y agoHah, so it is. It was pretty late when I finished this one off, sorry about that.
- michaelochurch 13y agoI tried it at a REPL in version 1.5.1 and it didn't work for me. I don't think standard Clojure has triple-quote strings.
- tobik 13y agowhy? in clojure strings can be multiline already. so there is no point in triple quotes.
- drcode 13y agoSo you don't have to escape internal quotes.
- michaelochurch 13y agoTriple quotes tend to come up for two purposes: 1. Long regular expression strings that have quote marks involved. I'm not a fan of large, complex regexes, but a lot of people dislike the line-noise added by escaping. 2. Docstrings that may have quotes in them. It's to remove the string escaping that makes literals look different from the strings they describe.
- tobik 13y agoThanks. Thinking about it, I guess triple-quoted strings also facilitate doctests involving strings that would otherwise be really awkward to read/write.
- adambard 13y agoNo, it's not, my bad. Not that there's a need for them, as it turns out.
- landhar 13y agoI often find myself having to spend more time than necessary to track down how to add these libraries to the dependencies of my leiningen projects. I think this post would be a lot more useful if it included a link to clojars for each one of these libraries.
- weavejester 13y agoThey're not on Clojars; the Maven repository they use is build.clojure.org. The project source code for all the contrib libraries is on Github at https://github.com/clojure https://github.com/clojure
- landhar 13y agoThanks for clarifying !
- adambard 13y agoI was thinking about including the Leiningen dependency line, but I don't want someone including the wrong version later because I didn't update it. Install info is usually pretty prominent on the github pages of the projects (which I've linked to).
- olenhad 13y agoQuite an awesome whirlwind tour. Didn't know about core.unify, which seems quite impressive.
- adambard 13y agoI suspect core.logic is the more practical library in many cases. I wrote a disproportionate amount on core.unify because I couldn't find any official docs that approached it from the perspective of someone (e.g. me) who didn't already know all about Prolog and unification in general.
- fhd2 13y agoNice writeup, wish this existed back when I worked with Clojure. The migration away from clojure.contrib caused quite the mess. Back then (about a year ago), looking for a function you want (things you would expect in the standard library) was like this: 00:05 Found it in clojure.contrib 01:05 Figured out which standalone library it has moved to (or conclude that it has disappeared) 01:15 Figured artefact/group ID and current version out That was a bit annoying.
- jared314 13y agoWhy did the author mention core.typed, but leave out core.contracts? https://github.com/clojure/core.contracts https://github.com/clojure/core.contracts
- adambard 13y agoI started writing a bit on contracts, but it was 2am and I really wanted to be done. (I thought I had a little more time between then and HN front page.) You're right, though, I should at least give it a shout and let people know about it.
- adambard 13y agoThere is now a (mildly half-assed) blurb on contracts, not that fogus was likely to feel left out otherwise.
- tieTYT 13y agoI still have no idea what core.unify does.
- jared314 13y agoIt is a subset of core.logic's functionality. It allows you to use unification in your code without the full logic engine of core.logic.
- tieTYT 13y agoThis comment assumes I know what core.logic does.
- jared314 13y agoTrue, but your comment gave no indication of context, your knowledge level of clojure, awareness of logic programming, or an actual question. So, I had no basis to give a response that answered the question you did not ask. I honestly thought you were just trolling.
- adambard 13y agoGive it two patterns with some unknowns and it tries to get values for the unknowns via pattern-matching. That's all it does! It's one of those things that humans do very well but computers have trouble with, so I'm afraid it doesn't look too impressive.