RSSAmplifier

Blog

Learning Clojure

learningclojure.comRSS feed ↗25 posts

Latest posts

Contract Programmer Seeks Job in Cambridge (£500 reward)

Anyone in Cambridge need a programmer? I'll give you £500 if you can find me a job that I take. CV at http://www.aspden.com I make my usual promise, which I have paid out on several times: If, within the next six months, I take a job which lasts longer than one month, and that is not obtained through an agency, then on the day the first cheque from that job cashes, I'll give £500 to the person who…

Clojure Setup from Scratch on a Clean Install of Debian 11

I've just installed Debian 11 on an ancient netbook whose hard disk failed, so that seems a chance to find out what we need to do to make a functioning clojure environment from scratch. The only changes I've made to my default install are things like getting sudo working and setting the UMASK, my home directory is brand new and empty. first install clojure $ sudo apt install clojure $ clojure…

Fermat's Christmas Theorem : Fixed Points Come In Pairs

#! /usr/bin/env clojure ;; Fermats' Christmas Theorem: Fixed Points Come In Pairs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here's a bunch of code to make svg files of arrangements of coloured squares. ;; I'm using this to draw the windmills. ;; It's safe to ignore this if you're not interested in how to create such svg files.…

Christmas Theorem: Some Early Orbits

#! /usr/bin/env clojure ;; Fermats' Christmas Theorem: Some Early Orbits ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here's a bunch of code to make svg files of arrangements of coloured squares. ;; I'm using this to draw the windmills. ;; It's safe to ignore this if you're not interested in how to create such svg files.…

Chrismas Theorem: Automatic Windmills

#! /usr/bin/env clojure ;; Fermats' Christmas Theorem: Automatic Windmills ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here's a bunch of code to make svg files of arrangements of coloured squares. ;; I'm using this to draw the windmills. ;; It's safe to ignore this if you're not interested in how to create such svg files.…

Christmas Theorem: Principled Windmills

#! /usr/bin/env clojure ;; Fermats' Christmas Theorem: Principled Windmills ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Here's a bunch of code to make svg files of arrangements of coloured squares. ;; I'm using this to draw the windmills. ;; It's safe to ignore this if you're not interested in how to create such svg files.…

Fermat's Christmas Theorem: Windmills

#! /usr/bin/env clojure ;; Fermats' Christmas Theorem: Windmills ;; Sorry for the delay, I had COVID. I'm fine, don't worry! ;; Let's pick an arbitrary number of the form 4n+1, say 29 ;; Precisely because it's of form 4n+1, we can split it into a central square and four identical ;; blocks, in this case, a 1x1 square and four 1x7 blocks ;; 29 = 1*1 + 4 * (1 * 7) (+ (* 1 1) (* 4 (* 1 7))) ; 29 ;;…

A Festive Theorem

#! /usr/bin/env clojure ;; A Festive Theorem ;; About a week ago, a friend of mine who is not noted for his interest in pure mathematics, and ;; whose identity I will conceal behind the alias "Sipper" caught me in the Wetherspoons and showed ;; me a number theory proof (or at least most of one, we couldn't actually finish the argument off) ;; I've never been interested in number theory. It seems…

A test program

#! /usr/bin/env clojure ;; It looks like clojure has become a full citizen of Debian ;; In emacs, a syntax highlighted program can be converted to html with htmlize-buffer, and then if ;; you top and tail that and copy it to blogger it comes up nicely. And this seems to still be ;; working after all this time ;; So here is my first published clojure program for a while... ;; If you're using Debian…

Emacs, even

The truly terrifying bit of getting any language to work on your machine is getting it to work with EMACS. Last time I tried to get clojure working, this was the stage that I gave up at. Everything was just broken, and so I wrote the program I was going to write in python instead. But all it took this time was: (Emacs 27.1, the version that comes with Debian 11/Bullseye) M-x package install…

Clojure Shell Scripts on Debian

So I managed to install a very recent clojure through Debian's package manager, and it just worked. And my next thought is: "If it's somehow become a proper part of Debian, does that mean I can do shell scripts?" so cat >test.clj #!/usr/bin/env clojure (print "hello") chmod +x test.clj ./test.clj (2 second pause...) hello Compare with the python equivalent: cat >test.py #!/usr/bin/env python…

Hello Again World (2nd December 2021) Setting Up Clojure on Debian 11

It's been a while since I've used Clojure, and I've upgraded my system a fair bit since then, so I'm going to try to start again from scratch. My computer is running latest stable Debian cat /etc/debian_version 11.1 (version 11.1, aka bullseye) My first instinct is to install via the package manager: apt search clojure clojure/stable,now 1.10.2-1 all Lisp dialect for the JVM clojure.org tells me…

The Unexpected Appearance of Schlemiel, the Painter

;; The Unexpected Appearance of Schlemiel, the Painter ;; I was doing some statistics one day, and I defined: ;; the average of a finite sequence ( defn average [sq] ( / ( reduce + sq) ( count sq))) ;; and the square of a number ( defn square [x] ( * x x)) ;; and a way of forgetting about all the fiddly little digits at the end ( defn twosf [x] ( float ( / ( Math / round ( * x 100.0)) 100))) ;;…

Reinforcement Learning : Exploration vs Exploitation : Multi-Armed Bandits

;; Reinforcement Learning : Exploration vs Exploitation : Multi-Armed Bandits ;; I'm reading the excellent: ;; Reinforcement Learning: An Introduction ;; by Richard S. Sutton and Andrew G. Barto ;; The book's website, on which is available a complete pdf, is here: ;; http://www.incompleteideas.net/book/the-book.html ;; In Chapter 2, they introduce multi-armed bandits as a simplified model problem…

Define Macro

;; When I say ( def a (* 4 5)) ;-> #'user/a ;; I'd rather the repl told me that I'd just assigned the value 20 to ;; something rather than that I'd just assigned something to user/a a ;-> 20 ;; A macro for this is easy ( defmacro define [var expr] `( let [tmp# ~expr] ( def ~var tmp#) tmp#)) ( define a (* 4 5)) ;-> 20 ;; I'd also like to be able to say, in a scheme-like manner '( define (square x)…

An Introduction to the Lambda Calculus

;; Done Twice as a "Dojo" at Villiers Park on Thursday 19th March 2015 ;; To groups of about 15 ultra-clever teenagers who were thinking about doing Computer Science at university ;; The first group got as far as higher order functions in an hour. ;; The second group went a bit faster, and we had a bit more time, about an hour and a half, ;; and so we got right to iterative-improve and finding…

Destructuring Clojure Maps

;; Destructuring Clojure's Maps ;; I can never ever remember how this works, so here is a note to self: (( fn [{a :a }] a) { :a 1}) ; 1 ;; And by let-lambda isomorphism ( let [{a :a } { :a 1}] a) ; 1 ;; Why on earth is the syntax the wrong way round? Why can't {:a a} match {:a 1}? ;; Similarly (( fn [{a :a b :b }] [a b]) { :a 1 :b 2}) ; [1 2] ( let [{a :a b :b } { :a 1 :b 2}] [a b]) ; ; [1 2] ;;…

A Classic Puzzle

;; A Classic Puzzle ;; This problem, my sources inform me, can be solved by pre-school ;; children in 5-10 minutes, by programmers - in 1 hour, and by ;; mathematicians ... well, check it yourself! :) ( def input (quote ( "8809" "7111" "2172" "6666" "1111" "3213" "7662" "9313" "0000" "2222" "3333" "5555" "8193" "8096" "7777" "9999" "7756" "6855" "9881" "5531" ))) ( map classic input) ; -> (6 0 0 4…

I Wish I'd Written This

Nothing specifically to do with clojure, but I figure that a fair number of readers of this blog must love algorithms and visualizations, and this: http://bost.ocks.org/mike/algorithms/ is one of the best things I've ever read on those subjects. I really wish I'd written this! Or even was capable of writing this.

Planes In Space : Random Sampling

;; My recursion tells me that n planes can divide space into ;; 2, 4, 8, 15, 26, and finally 42 regions. ;; But I'd like some sort of empirical confirmation of this result. ;; Forms in 3-space can be represented as ordered sets of three numbers ( def a-form [1 2 3]) ;; As can vectors ( def a-point [2 3 5]) ;; And we evaluate the form on the vector ( defn contract [form vector] ( reduce + ( map *…

Fizz Buzz : An Interview Question

;; Fizz Buzz ;; My sources ;; http://blog.codinghorror.com/why-cant-programmers-program/ ;; inform me that: ;; The majority of computer science graduates can't solve this problem: ;; Write a program that prints the numbers from 1 to 100. But for ;; multiples of three print "Fizz" instead of the number and for the ;; multiples of five print "Buzz". For numbers which are multiples of ;; both three…

Planes in Space : Checking by Hand

;; Ok, so I reckon: ( defn regions [n m] ( cond ( = n 1) ( list m ( inc m)) ( = m 0) ( concat ( repeat n 0) '(1)) :else ( map + (regions n ( dec m)) ( concat '(0) (regions ( dec n) ( dec m))) ( concat (regions ( dec n) ( dec m)) '(0))))) ;; In fact, I reckon that I can prove it. ;; It's quite easy to prove something that isn't true. Usually when ;; you run across a counterexample, that shows you…

Planes in Spaaace!

;; Into how many regions can six planes divide space? ;; Too hard! ;; So make it harder: ;; Into how many regions can m hyperplanes divide n dimensional space? ;; Now look at the easiest case. ;; Into how many lines can m points divide a line? ;; We start off with one line and no points ;; n = 1 ;; m points lines ;; 0 0 1 ;; Every time we add a point, it splits a line ;; n = 1 ;; m points lines ;;…

Into How Many Regions Can Six Planes Divide Space?

I recently misread an easy recreational puzzle as 'Into how many regions can six planes divide space?'. It took me about half an hour to get an answer. (Which was the correct answer to the question, but not the answer to the real puzzle). But it turned out to be great fun to think about. I'm pretty sure that my answer's correct (and wikipedia agrees), but although the combination of mathematical…

Finite Automata

I did some pictures of automata to go with this post, but Google have managed to bugger up 'Insert Image' in Blogger, which used to be easy. I wonder if their monkeys are even interested in whether their filthy javascript crap actually works before they inflict it on people. God I hate them. They've gone from 'Don't be evil / Awesome' to 'We own you now / But we can't program any more' in a couple…