7 Rules for Writing Clojure Programs « Two Guys Arguing Over the past 5 months, I’ve had the incredible opportunity at Revelytix to write Clojure every day and get paid for it. 5 months is an incredibly short time to pretend to have learned anything, but I can feel the beginnings of a style emerge in my programming and while writing a small program some ideas congealed into actual words that I thought I’d capture here. Update: Ugh. I really messed up. As it has been noted in the comments below, on Hacker News and even Twitter, my final solution is much (much) slower thanks to it’s not one, but two sorts. In the end, the whole thing is doubly redundant as clojure.contrib.seq-utils implemented a function ‘frequencies’ which will be in 1.2′s clojure.core. It uses ‘reduce’ and you should too. #1 – Your brain will think in steps. The program that brought these ideas to life was a small utility I needed to read a file and print out the set of characters contained within along with the number of occurrences of each character. "abcdaabccc"
Foreword | Clojure for the Brave and True As you read this hilarious book, you will at some point experience a very serious moment. It is the moment you admit to yourself that programming is more enjoyable after knowing some Clojure. It is also the moment that your investment in this book, in money and time, comes back to you—with interest. Humor has a certain relationship to seriousness. This book works in the opposite way. This approach is refreshing because most of the programming books I’ve read are drier than a camel’s fart. Clojure is the topic of this book, but in a way it—or perhaps its creator, Rich Hickey—is also one of the authors, since Clojure is the most elegant programming language ever designed. Elegance is a quality regularly ascribed to many dialects in the family of programming languages known collectively as Lisp, of which Clojure is one. Since 1958, there have been many Lisps and Lisp books. I find Clojure, and this particular book about it, especially right for the present. Alan Dipert
Clojure - home Clojure - Functional Programming for the JVM by R. Mark Volkmann, Partner Object Computing, Inc. (OCI) last updated on 6/2/13 Contents Introduction The goal of this article is to provide a fairly comprehensive introduction to the Clojure programming language. Please send feedback on errors and ways to improve explanations to firstname.lastname@example.org, or fork the repository and send a pull-request. You said X, but the correct thing to say is Y. Updates to this article that indicate the "last updated" date and provide a dated list of changes will be provided at Code examples in this article often show the return value of a function call or its output in a line comment (begins with a semicolon) followed by "->" and the result. (+ 1 2) ; showing return value -> 3 (println "Hello") ; return value is nil, showing output -> Hello Functional Programming Functional programming is a style of programming that emphasizes "first-class" functions that are "pure". In practice, applications need to have some side effects.
Improving Clojure’s docs You are here: Home / Clojure / Improving Clojure’s docs There was an interesting conversation today on #clojure about various aspects of Clojure documentation. This is not a new topic I thought I’d goose it a little more publicly. There are docs in several places (this is incomplete, but most easily found): clojure.org – “official”, first-stop, very small editor set dev.clojure Confluence – wiki, editable by many but less formal. Clojure Docs – a place to stash per-function examples in core and libraries Learn-Clojure – a gathering of “learning” resources At last year’s conj, I was inspired to improve and talked Stu into letting me make some changes <evil-laugh/>. Eventually, my free time ran out and I declared doc change bankruptcy and just put my todo list on the dev site . If you come out of the conj inspired to do some doc work to improve your world, here are some suggestions: Pick up one of the items on the .org TODO list (or add your own pointy edge).
SICP in Clojure Learn clojure in Y Minutes Clojure is a Lisp family language developed for the Java Virtual Machine. It has a much stronger emphasis on pure functional programming than Common Lisp, but includes several STM utilities to handle state as it comes up. This combination allows it to handle concurrent processing very simply, and often automatically. (You need a version of Clojure 1.2 or newer) Further Reading This is far from exhaustive, but hopefully it’s enough to get you on your feet. Clojure.org has lots of articles: Clojuredocs.org has documentation with examples for most core functions: 4Clojure is a great way to build your clojure/FP skills: Clojure-doc.org (yes, really) has a number of getting started articles: Got a suggestion?
Practical: An MP3 Database Copyright © 2003-2005, Peter Seibel In this chapter you'll revisit the idea first explored in Chapter 3 of building an in-memory database out of basic Lisp data structures. This time your goal is to hold information that you'll extract from a collection of MP3 files using the ID3v2 library from Chapter 25. You'll then use this database in Chapters 28 and 29 as part of a Web-based streaming MP3 server. Of course, this time around you can use some of the language features you've learned since Chapter 3 to build a more sophisticated version. The Database The main problem with the database in Chapter 3 is that there's only one table, the list stored in the variable *db* . This time you'll solve both problems by defining a class, table , to represent individual database tables. (defclass table () ((rows :accessor rows :initarg :rows :initform (make-rows)) (schema :accessor schema :initarg :schema))) Defining a Schema (defgeneric make-column (name type &optional default-value)) Inserting Values
Learning Clojure Some paragraphs in [ ] are author notes. They will be removed as the page matures. You should be able to read the text OK if you ignore these notes. This Book is currently being restructured to better satisfy the wikibooks standard. For detailed coverage of Clojure, consult the language and API reference at clojure.org. Clojure (read as closure), is a powerful, lisp-1 programming language designed by Rich Hickey and designed to run on the Java Virtual Machine. Getting Started History A brief history of the Clojure language. Installation Learn how to install Clojure on Windows, Linux, and Mac Learn how to launch the REPL execution system and the classic "Hello World" application Basics Basic Syntax Describes the basics in how the applications you write will be interpreted Coding Conventions Quickly describes the generally accepted conventions for Clojure. Functional Programming The entities used to store data of various shapes Namespaces Basic Operations Explains how use essential functions
Learning Clojure - What should I know about Java and more