The recent smartphones have quite impressive specs. E.g. the Samsung Galaxy S III comes with a 1.5 GHz quad-core processor and a GPU. It would be interesting though to run a real programming language on one of those phones. I am quite interested in the Racket programming language (also see Wikipedia) which offers full meta-programming and compile-time macros. I managed to cross-compile Racket to run on an Android phone HTC Desire S. I’ll describe the steps here. Hopefully I’ll find time to improve things and package it in some way.
Build
To cross-compile Racket for ARM you first need to compile Racket for the host system. The GCC cross-compiler and the Racket interpreter are then used during the cross-compilation.
#!/bin/shARCHIVE=$HOME/Documents/programming/racket-5.2.1-src-unix.tgz
rm-Rf /tmp/build
mkdir-p /tmp/build/host
cd /tmp/build/host
tar xzf $ARCHIVEBUILD_HOST=/tmp/build/host/racket*cd$BUILD_HOST/src
./configure
make install
mkdir-p /tmp/build/cross
cd /tmp/build/cross
tar xzf $ARCHIVEBUILD_CROSS=/tmp/build/cross/racket*cd$BUILD_CROSS/src
./configure --host=arm-linux-gnueabi
make \RUN_THIS_RACKET_CGC=$BUILD_HOST/src/racket/racketcgc \RUN_THIS_RACKET_MMM=$BUILD_HOST/src/racket/racket3m \RUN_THIS_RACKET_MAIN_VARIANT=$BUILD_HOST/src/racket/racket3m \HOSTCC=/usr/bin/gcc \HOSTCFLAGS="-g -O2 -Wall -pthread -I./include"\STRIP_DEBUG="arm-linux-gnueabi-strip -S"
make \RUN_THIS_RACKET_CGC=$BUILD_HOST/src/racket/racketcgc \RUN_THIS_RACKET_MMM=$BUILD_HOST/src/racket/racket3m \RUN_THIS_RACKET_MAIN_VARIANT=$BUILD_HOST/src/racket/racket3m \HOSTCC=/usr/bin/gcc \HOSTCFLAGS="-g -O2 -Wall -pthread -I./include"\STRIP_DEBUG="arm-linux-gnueabi-strip -S"\install
cd$BUILD_CROSS/src/racket
arm-linux-gnueabi-gcc -static-o racket3m gc2/main.o libracket3m.a -ldl-lm-ldl-lm-rdynamic
The last command is used to replace the racket3m binary with a statically linked version.
Installation
First I installed Android Terminal Emulator. I also installed Kevin Boone’s kbox_shell which allows you to run BusyBox without requiring to jailbreak the phone (I don’t think BusyBox is required to run Racket but it is nice to have the various Linux shell utilities). I really recommend to install Hacker’s Keyboard to have a full PC keyboard on your phone.
Then one needs to copy the following files to the mobile phone:
The racket3m binary is copied to the mobile in a location where it can be accessed from the terminal (e.g./data/data/jackpal.androidterm/shared_prefs/kbox/bin/racket if you have kbox_shell installed).
Several Racket modules located in /tmp/build/cross/racket-5.2.1/collects/… need to be copied to $HOME/.racket/5.2.1/collects on the mobile phone. The libraries are
racket
syntax
setup
config
compiler
planet
mzlib
scheme
unstable
mzscheme
Racket on Android
Unfortunately the full Racket language takes 90 seconds (!) to load on the HTC Desire S. Once loaded, the REPL is very responsive though.
Hopefully I get ffi and the readline library working to have an improved command line.
Any comments and suggestions are welcome
Update
It is possible to only load the Racket base language. Running the following command
racket -I racket/base
brings up the REPL in 7 seconds. Thanks Robby for the helpful comment!
Update
Racket 5.3.0 furthermore needs the following module to be installed:
s-exp
Update
I haven’t managed to build Racket with the Android NDK (see my thread on the Racket mailing list). Building Racket with the Android NDK would be preferable because otherwise it is impossible to dynamically load Android libraries in order to access Android specific functionality.
Recently I found a video of an interesting presentation by David Nolen (homepage, blog) (comparing the Clojure programming language with Scheme (Racket). Some important points made in the talk are:
Clojure does not support optimisation of tail-recursion leading to stack overflows. However one can use lazy sequences instead.
Clojure does not support continuations.
The frequent destructuring of data using car and cdr in Scheme is cumbersome. Clojure on the other hand has syntax support for various immutable data structures (lists, vectors, hashes, and sets) which makes for more readable code.
Clojure is a great platform for exploring concurrency (atoms, refs, agents, promises, and futures).
David Nolen concludes that it is not a question of either/or.
Can we attract good and bad things with our mind? - No!
This is one piece of certified bullshit which I have encountered one time too many.
There seem to be quite a number of people who chose to belief that you somehow can attract good stuff (health, love, money, …) by positive thinking (previously known as wishful thinking).
Initially there was the (comparatively harmless) concept of positive thinking. I.e. some psychology experts observed that successful people seem to generally have an optimistic attitude. So they came up with the notion that you could be successful in life by thinking positive thoughts.
This is simply a confusion of cause and effect. But this didn’t stop some people from taking this idea further and coming up with the law of attraction. It finally culminated with a movie called the The Secret. According to this movie, mankind (except for a select few such as Rhonda Byrne of course) has somehow missed out on the fact that it is possible to attract wealth, health, and happiness by changing one’s thoughts and feelings.
So what’s the harm? Well, this is not about threading a fine line between healthy optimism and wishful thinking. This is serious bullshit. There are people trying to cure dangerous diseases using positive thoughts. For example a recent article suggests that Steve Jobs tried to fight cancer using magical thinking.
Here’s a nice artist’s animation based on a talk by Barbara Ehrenreich. Barbara Ehrenreich points out that positive thinking might even be the root cause for the financial meltdown.
Camera calibration is a fundamental problem in computer vision. In the third episode of the Computer Vision for the Robotic Age podcast I am demonstrating a robust algorithm for identifying the corners of a chequerboard pattern. Identifying the corners of a calibration grid is the initial step for camera calibration.
require'rubygems'require'hornetseye_ffmpeg'require'hornetseye_xorg'includeHornetseyeclassNode# Non-maxima suppression for cornersdefnms(threshold)# compare image with dilated image and thresholdself>=dilate.major(threshold)end# Find a component with 'n' cornersdefhave(n,corners)# compute number of corners for each componenthist=mask(corners).histogrammax+1# compare number of corners with desired numbermsk=hist.eqnifmsk.inject:or# get label of connected componentid=argmax{|i|msk.to_ubyte[i]}.first# get component maskeqidelse# return nilnilendenddefcorners(sigma=5.0,size=21)size2=size/2# generate chequer patternf1=finalise(size,size)do|i,j|x,y=i-size2,j-size2x*y*Math.exp(-(x**2+y**2)/sigma**2)end# generate chequer pattern rotated by 45°f2=finalise(size,size)do|i,j|x,y=i-size2,j-size20.5*(x**2-y**2)*Math.exp(-(x**2+y**2)/sigma**2)end# apply filter pair and compute corner strengthMath.hypotconvolve(f1),convolve(f2)endend# relative threshold for corner imageCORNERS=0.6# absolute threshold for greylevel imageTHRESHOLD=90# width and height of calibration gridW,H=8,5W2,H2=0.5*(W-1),0.5*(H-1)N=W*H# dilation constantGRID=7# open input videoinput=AVInput.new'calibration.avi'width,height=input.width,input.heightX11Display.showdo# read colour imageimg=input.read_ubytergb# convert to greyscalegrey=img.to_ubyte# call method for computing corner imagecorners=grey.corners# call method for non-maxima suppressionnms=corners.nmsCORNERS*corners.max# threshold imagebinary=grey>THRESHOLD# find edges using dilation and erosionedges=binary.dilate(GRID).andbinary.erode(GRID).not# find connected edgescomponents=edges.components# check for edge region with 'N' cornersgrid=components.haveN,nmsifgrid# visualise calibration gridgrid.and(nms).dilate.conditionalRGB(255,255,0),imgelse# visualise detected cornersnms.dilate.conditionalRGB(255,0,0),imgendend
You can download a better quality version of the video here