background preloader

Programming Languages: Application and Interpretation by Shriram Krishnamurthi

Programming Languages: Application and Interpretation by Shriram Krishnamurthi

Object Computing, Inc. - Java News Brief - March 2009 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 mark@ociweb.com, 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.

home 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. #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. Rule #1 – Your brain will think in steps. "abcdaabccc"

Learn Clojure SICP in Clojure Closure (computer science) def start(x): def increment(y): return x+y return increment The closures returned by start can be assigned to variables like first_inc and second_inc. Invoking increment through the closures returns the results below: first_inc = start(0) second_inc = start(8) first_inc(3) # returns 3 second_inc(3) # returns 11 # The x value remains the same for new calls to the function: first_inc(1) # returns 1 second_inc(2) # returns 10 In ML, local variables are allocated on a linear stack[citation needed]. When a closure is created, it copies the values of those variables that are needed by the closure into the closure's data structure. Closures are closely related to Actors in the Actor model of concurrent computation where the values in the function's lexical environment are called acquaintances. Closures are closely related to function objects; the transformation from the former to the latter is known as defunctionalization or lambda lifting. Closures have many uses:

Related: