Below you will find pages that utilize the taxonomy term “Clojure”
October 6, 2021
Go is Korean, Lisp is Japanese
Recently I took a fresh at look at the Go programming language after having last taken a look at it before version 1.0 was released back in 2009. What I’ve found in just a few days is shocking in a really really good way.
August 30, 2012
Purely Functional Data Structures & Algorithms : Selection Sort
*Updated @ 2012-08-31 02:08:58 due to internet pedantry*
Previously, previously.
According to Wikipedia :
In computer science, a Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its simplicity, and also has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.
March 14, 2012
Happy Pi Day in Shen
Here’s a port of the previous Qi II code to Shen.
Run with Hakan Raberg’s 0.1.4 version of shen.clj (Shen implemented in Clojure !).
* Accurately calculates N digits of Pi using Machin's formula with fixed point arithmetic and variable guards digits. Depends on the maths library --> http://www.shenlanguage.org/library.html * (tc +) (define arccot- {number --> number --> number --> number --> number --> number} X N XPOWER 0 _ -> 0 X N XPOWER TERM 1 -> (+ (arccot- X (+ N 2) (floor (/ XPOWER X)) (floor (/ XPOWER N)) 0) (floor (/ XPOWER N))) X N XPOWER TERM 0 -> (- (arccot- X (+ N 2) (floor (/ XPOWER X)) (floor (/ XPOWER N)) 1) (floor (/ XPOWER N)))) (define arccot {number --> number --> number} X UNITY -> (let XPOWER (floor (/ UNITY X)) (arccot- (* X X) 1 XPOWER (floor XPOWER) 1))) (define machin-pi {number --> number} DIGITS -> (let GUARD (+ 10 (ceiling (log' DIGITS 10))) UNITY (expt 10 (+ DIGITS GUARD)) (floor (/ (* 4 (- (* 4 (arccot 5 UNITY)) (arccot 239 UNITY))) (expt 10 GUARD))))) (1+) (time (machin-pi 100)) run time: 2.
November 11, 2011
Clojure/Conj 2011
Sold out attendance marked this being the second premiere conference for Clojure. What I realized is just how great the people are in this community. No, seriously. There’s far less ego than with many other communities. This is a great sign for the future of Clojure. Particularly because Rich is such a great guy. He even gave a public apology for something or other that he said(on a mailing list) which he felt was not in the spirit of the Clojure community.
October 2, 2011
Overtone
Overtone is an open source audio environment being created to explore musical ideas from synthesis and sampling to instrument building, live-coding and collaborative jamming.
In this video Sam Aaron gives a fast-paced introduction to a number of key live programming techniques such as triggering instruments, scheduling future events and synth design. Finally, the viewer is shown how a simple musical sequence may be composed and then converted into an intricate Reich phase.
September 23, 2011
Shen/Kl arrive
The first publicly available version of Shen/Kl has been released. The Shen mission is to develop an ultra-portable version of Qi that can run under a wide variety of platforms and which incorporates missing features in Qi such as streams. The targeted platforms are CL, Clojure, NewLisp, Emacs Lisp, ECL, Scheme, Javascript and Python as well as C/C++, DVM, CLR or the JVM. This approach involved rewriting and redesigning Qi to fit within the smallest feasible instruction set.
July 23, 2011
ClojureScript Demo : Convex Hull
Update : bug-fix when hull was being incorrectly calculated due to there being duplicate points generated in the random set.
ClojureScript looks like a solid approach to building applications that target JavaScript VMs. It’s built on top of Google’s Closure Compiler/Library which is very intruiging and is the best approach that they could have taken (now that I’ve a played with it a little). Being new to both Closure and ClojureScript I was curious about what it might feel like to build an application using these tools.
March 14, 2011
Happy PI day ! (in QiII)
Qi is the future of Lisp.
It is Lisp with many great features such as pattern-matching, a turing complete static type system (even more powerful than Haskell’s type system) and many others. So in the spirit of PI day, here’s an implementation that calculates PI using Machin’s formula.
(define ceiling X -> (CEILING X)) (declare ceiling [number --> number]) (define expt X Y -> (EXPT X Y)) (declare expt [number --> number --> number]) (define floor X Y -> (FLOOR X Y)) (declare floor [number --> number --> number]) (define log X Y -> (LOG X Y)) (declare log [number --> number --> number]) (tc +) (define arccot- {number --> number --> number --> number --> number --> number} X N XPOWER 0 _ -> 0 X N XPOWER TERM 1 -> (+ (arccot- X (+ N 2) (floor XPOWER X) (floor XPOWER N) 0) (floor XPOWER N)) X N XPOWER TERM 0 -> (- (arccot- X (+ N 2) (floor XPOWER X) (floor XPOWER N) 1) (floor XPOWER N))) (define arccot {number --> number --> number} X UNITY -> (let XPOWER (floor (/ UNITY X) 1) (arccot- (* X X) 1 XPOWER (floor XPOWER 1) 1))) (define machin-pi {number --> number} DIGITS -> (let GUARD (+ 10 (ceiling (log DIGITS 10))) UNITY (expt 10 (+ DIGITS GUARD)) (floor (* 4 (- (* 4 (arccot 5 UNITY)) (arccot 239 UNITY))) (expt 10 GUARD)))) And the output …
June 16, 2010
So you say that programming language choice does not matter ...
One popular interview question that never dies : write some code to reverse a singly linked-list.
Now understanding the problem for interviewees is one thing but getting it right in an imperative language seems to be quite a feat based on my experience as an interviewer. Most take 15-20 minutes to get this completely correct and sometimes even longer. Here’s a quick solution that took me 10 minutes (in C) : #define LIST_SIZE 10000000 #define SHOW_SIZE 5 typedef struct node { struct node* next; int val; } node; int main(int argc, char* argv[]) { int i; long start, end; node* head = malloc(sizeof(node)); node* cur = head; node* cur2 = head; node* prev = NULL; node* next = NULL; // init linked list printf("
June 2, 2010
Convex Hull with Aki-Toussaint heuristics
;; Calculates the convex hull of a set of points using the Graham scan ;; algorithm. (ns i27.geom.convex-hull (:use [i27.geom.misc :only (angle cross-product)])) (defn presort-points [pts] "Presorts the cartesian points in descending order by angle. The point with lowest y value is last in the vector." (let [pts (distinct pts)] ;; must be distinct or else errors ... (letfn [(find-start [[x1 y1 :as pt1] [x2 y2 :as pt2]] (cond (< y1 y2) pt1 (= y1 y2) (if (< x1 x2) pt1 pt2) true pt2))] (let [pt (reduce find-start pts) npts (remove (fn [[x y :as cpt]] (and (= (first pt) x) (= (last pt) y))) pts)] (conj (apply vector (sort (fn [pt1 pt2] (> (angle pt pt1) (angle pt pt2))) npts)) pt))))) (defn convex-hull "
May 24, 2010
Bucket sort (Clojure)
(defn bucket-sort "Runs in O(n) time." [items] (let [len (count items) mx (apply max items) bucket-size (inc (int (/ mx len))) buckets (reduce (fn [v n] (conj v [])) [] (range (+ bucket-size (/ mx bucket-size))))] (letfn [(distrib-nums [v n] (let [ind (int (/ n bucket-size)) bucket (nth v ind)] (assoc! v ind (conj bucket n))))] (let [pre-buckets (persistent! (reduce distrib-nums (transient buckets) items))] (apply concat (map (fn [bucket] (when (> (count bucket) 0) (insertion-sort bucket))) pre-buckets)))))) Runs slightly faster than Clojure’s built-in sort (at least on integers in the range 0 to 1E6) :
March 30, 2010
A molecule viewer in Clojure
Here’s a molecule viewer using OpenGL in Clojure. Implemented so that I could compare this type of development with Common Lisp (and also with using OpenGL development in C). OpenGL with Clojure can be really fun using Zach Tellman’s Penumbra. Coming at OpenGL from a more functional angle (e.g. not mutating global vars etc.) can be a little different but not difficult for anyone who has done enough functional programming. The code is here.
February 26, 2010
Do you really know Lisp ?
DISCLAIMER :
THIS IS A LANGUAGE RANT. DO NOT READ IF YOUR BPF* IS LESS THAN 0.37.
SIDE EFFECTS MAY INCLUDE SEVERE CONFUSION, UNJUSTIFIED ANGER, GASSY DISCHARGE,
INCOMPREHENSIBLE DIALOG, ERRATIC DEGRADATION OF CHARACTER AND POSSIBLY A
COMPLETE EMOTIONAL MELTDOWN.
Performance is one important aspect that people might want in a language. One language that continually surprises me in this regard is Haskell. Seriously, it’s simply amazing. But performance is only one important consideration when using a language.
December 25, 2009
Palindromes (Clojure)
* Update 2009-12-27 * Using lists instead of vectors brings the Clojure version down from around 20x to 10X slower than the CL version. One reader correctly stated that when doing performance comparisons between languages and implementations you want the code and data structures to be as identical as possible.
“A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction (the adjustment of punctuation and spaces between words is generally permitted.
September 18, 2009
Clojure Quine
A Quine is a program that produces its complete source code as its only output. Because Clojure is a Lisp, it is especially well suited to writing Quines. This is a quine implemented in Clojure.
((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x))))) M.C. Escher – Drawing Hands – 1948
September 14, 2009
Play Pong!
A few updates and bug fixes from the
first version.
You can now play it here.
ACHTUNG ! : This requires unrestricted perms so you should probably just grab the code and compile it yourself.
September 12, 2009
Pong! (in Clojure)
* UPDATED : 2009-09-17 * – rewritten in a functional style that is more idiomatic of Clojure.
A nostalgic attempt to try and learn some GUI programming in Clojure. Inspired by Pong in Haskell.
Play online here.
The computer seems unbeatable(but it’s not thanks to a bug as things get faster).
Have fun !
< 200 lines of code :
;;;; ;;;; Pong! ;;;; ;;;; Justin Grant ;;;; 2009/09/12 (ns i27.
August 21, 2009
Calculating π in Clojure (Salamin-Brent)
Took a shot at implementing a PI digit generator in Clojure using a ‘fast’ algorithm.
It seemed like a decent enough excercise to try and understand something about performance in Clojure.
MacBook Pro – Intel Core 2 Duo 2.26 GHz – 4GB RAM Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219) Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode) Clojure 1.1.0-alpha-SNAPSHOT (Aug 20 2009) git commit f1f5ad40984d46bdc314090552b76471ee2b8d01
Clojure matches the performance of Java in this example.