background preloader

Clojure

Facebook Twitter

Datatypes

Trie. Remote slime repl. SLIME is a powerful extension for Emacs that transforms Emacs into an IDE for Lisp. It sets up Emacs so that it can connect to and interact with a Lisp running as a separate process – even on a separate server. This configuration allows you to connect to a running application with Emacs, allowing you to inspect the state of and debug a running application.

In this post I will walk you through how to set up and use this scenario using Emacs, SLIME and SSH to connect to a remote JVM running Clojure. SLIME and Swank Slime largely provides the ‘IDE’ portion of the extension, where Swank provides the inter-process communication between Emacs and the running Lisp image. Swank is broken into two parts, a layer run within Emacs and a server which runs within the Lisp image. Clojure Slime was extended by Jeffery Chu to support Clojure through swank-clojure. Getting Emacs, SLIME, Clojure and clojure-swank set up is covered by others; technomancy.us has a good getting started guide. Conclusion Thanks. Pcollections - Google Code. Ongoing · Concur.next & WF2 — Tuning Concurrent Clojure. I’ve been work­ing on, and writ­ing about, run­ning Clo­jure Wide Fin­der code. But I was nev­er sat­is­fied with the ab­so­lute per­for­mance num­ber­s. This is a write-up in some de­tail as to how I made the code faster and al­so slow­er, in­clud­ing lessons that might be use­ful to those work­ing on Clo­jure specif­i­cal­ly, con­cur­ren­cy more gen­er­al­ly, and with some in­ter­est­ing da­ta on Ja­va garbage col­lec­tion and JDK7.

[Up­date: My re­la­tion­ship with the JVM is im­prov­ing, based on good ad­vice from the Net. This ar­ti­cle has been part­ly re-written and is much more cheer­ful.] [This is part of the Con­cur.next se­ries and al­so the Wide Fin­der 2 se­ries.] In a com­ment on my last piece, Alexy Khrabrov not­ed “I saw WF2 has a pret­ty good Scala re­sult, ap­par­ent­ly bet­ter than Clojure's — and that's a year-old Scala.” Alexy is right; my best times were most­ly over 30 min­utes, while Ray Waldin’s Scala code ran in un­der 15. (let [chunks (. Yep, that helped. Be mindful of Clojure's binding - Chas Emerick - Muck and B. Clojure performance tips « Occasionally sane. I originally wrote this in a Google Groups thread, but I figured it’s worth repeating here. Somebody posted a Java and Clojure snippet to the Clojure Google group and mentioned that the Java code was vastly faster than the Clojure code and he wondered if Clojure could get within reach of Java’s speed.

In my own clj-starcraft project, I faced — and actually, still face — performance problems vis-à-vis Java. Specifically, at the time of this writing, my Clojure code is roughly 6 times slower than Java (Clojure takes around 70 seconds to parse 1,050 files, Java takes 12.) The 70 seconds figure used to be much worse however. At the beginning of the project, it took over ten minutes to analyze my 1,050 files. Thanks to Java’s nice profilers and the friendly Clojure folks, I was able to improve the performance of my program. (set! Fixing all the instances where *warn-on-reflection* complained improved the performance of clj-starcraft from ten minutes down to about three and half. Caveat. New new | Clojure. Protocols | Clojure. Clojure issue tracking now lives at and the wiki is at These Assembla pages are kept online for historical interest only. Protocols This page is a design scratchpad.

Please see: for the current documentation. There are several motivations for protocols: Basics A protocol is a named set of named methods and their signatures: (defprotocol AProtocol "A doc string for AProtocol abstraction" (bar [a b] "bar docs") (baz ([a] [a b] [a b c]) "baz docs")) No implementations are providedDocs can be specified for the protocol and the functionsThe above yields a set of polymorphic functions and a protocol object all are namespace-qualified by the ns enclosing the definitionThe resulting functions dispatch on the type of their first argument, and thus must have at least one argumentdefprotocol is dynamic, and does not require AOT compilation Protocols are fully reified and will support reflective capabilities. See also: extends? Online Learning in Clojure ← Structure & Process. Online Learning is a relatively old branch of machine learning that has recently regained favour for two reasons. Firstly, online learning algorithms such as Stochastic Gradient Descent work extremely well on very large data sets which have become increasingly prevalent (and increasingly large!).

Secondly, there has been a lot of important theoretical steps made recently in understand the convergence behaviour of these algorithms and their relationship to traditional Empirical Risk Minimisation (ERM) algorithms such as Support Vector Machines (SVMs). In order to understand these algorithms better, I implemented a recent one (Pegasos, described below) in Clojure. This had the added advantage of seeing how well Clojure’s performance held up when doing some serious number-crunching. Online Learning One very appealing property of online learning algorithms is that they are extremely simple. Models are usually represented as vectors of weights for the features used to represent the examples.

OverviewOfContrib - clojure-contrib - An overview of the clojure. 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. A monad tutorial for Clojure programmers (part 1) « On Clojure. Monads in functional programming are most often associated with the Haskell language, where they play a central role in I/O and have found numerous other uses. Most introductions to monads are currently written for Haskell programmers. However, monads can be used with any functional language, even languages quite different from Haskell. Here I want to explain monads in the context of Clojure, a modern Lisp dialect with strong support for functional programming.

A monad implementation for Clojure is available in the library clojure.algo.monads. Before trying out the examples given in this tutorial, type (use 'clojure.algo.monads) into your Clojure REPL. You also have to install the monad library, of course, which you can do by hand, or using build tools such as leiningen. Monads are about composing computational steps into a bigger multi-step computation. Consider the following piece of code: (let [a 1 b (inc a)] (* a b)) This can be seen as a three-step calculation: Like this:

Clojure maps. It's great to see all of the Clojure libraries springing up as people pull Clojure towards their application domains, and shape it for the styles of programming they prefer. In looking at some of the libraries, I am a bit concerned that maps are not being used when the logical entity is in fact a map. If you like Clojure, I would hope one of the things you like about it is that 'everything works with everything' to as great an extent as possible. This falls out of the fact that Clojure very much takes to heart this Alan Perlis quote: "It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures. " And recasts it as: It is better to have 100 functions operate on one data abstraction than 10 functions on 10 data structures.

Recently it was said in a thread: I know people usually think of collections when they see vector/map/ set, and they think classes and types define something else. Classes and types usually create desert islands. Thanks, Rich. Clojure intro. By R. Mark Volkmann, Partner Object Computing, Inc. (OCI) last updated on 9/29/12 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".

Clojure Overview methodName(arg1, arg2, arg3); Vars. Streams in clojure. (Note: this section describes work in progress, currently only available in SVN) I've been working on a stream model for Clojure. The basic idea behind streams is that they are ephemeral - they flow by once. Streams have nice laziness and performance characteristics when building pipelines of computations. You see stream-like things in many languages - often they are called generators/iterators/enumerators.

One of the main problems I have with them is that they are (inherently) stateful, and thus, when aliased, unsafe and error prone. Using them as general values is a bad idea. Generator A generator is a fn that (potentially) returns something different every time you call it (i.e. not a true function). Stream A stream owns and encapsulates a generator. Stream Transformers (defn map* [f coll] (stream f coll)) (defn filter* [pred coll] (stream #(if (pred %) % (skip)) coll)) (defn drop* [n coll] (let [n (atom n)] (stream #(if (pos?

(reduce* + 0 (map* inc (filter* even? Trampoline for mutual recursion - Clojure. On 28 Nov., 23:29, Meikel Brandmeyer <m... @kotka.de> wrote: > Hi André, > > Am 28.11.2008 um 22:56 schrieb André Thieme: > > >> Maybe I have a wrong understanding of "closure", but > >> as far as I understand, every function definition in > >> Clojure - be it defn or #() - finally translates to (fn ...). > >> And fn creates a closure. > > I tooled myself up and looked up the definition of "closure" > on Wikipedia. It seems that the definition says "one or more > bound variables". I still don't see why the "empty" environment > should that much of a special case.

Why not just say: > "a closure keeps its environment". Why should it matter > whether its empty or not? Because then having the word “closure” would be pointless. > > Well, from my experience I can say that a lot of people > > think that “anon function = closure”, which would be > > fn in Clojure or lambda in Common Lisp. > > This however is not generally correct. Defn is an abstraction to abstract these details away. Yes.