I was chasing links concerning the lack of tail recursion optimization in ruby and ran across a math problem: Find the smallest positive integer n such that n % x = x-1 for x from 2 to 18 i.e. The remainder is one less than the divisor for all integral divisors from 2 to 18. [...]
Archives for erlang
Erlang surprises me.
I recently wanted to calculate some binomial coefficients in Erlang, and so needed an implementation of the factorial function. No problem. The factorial function is the canonical illustration of how to define a recursive function in Erlang. It goes something like this: fac(0) -> 1; fac(N) -> N * fac(N-1). I have to confess that [...]
erl process handling commands
Note to self: some handy erlang shell commands for dealing with processes. process_info(Pid) i() erlang:processes(), or better yet, rp(erlang:processes()). Sometimes long lists show “…” to represent the tail elements. Wrapping in rp() shows the whole list. Finally, exit(Pid, kill) to kill the process represented by Pid. For a while I thought that exit(Pid) sufficed, but [...]
man page support in erlang-mode
I want to record what I had to do to get man page support working correctly in emacs erlang-mode under Ubuntu Hardy Heron. First, set the erlang root directory for erlang-mode: (setq erlang-root-dir “/usr/lib/erlang”) Next put a symbolic link to the man pages in the erlang root directory. cd /usr/lib/erlang sudo rmdir man #the man [...]
OOP in erlang
I read this quote on the blog of Isaiah Perumalla, in the post called My Journey to Smalltalk: “OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this [...]
ejabberd
I’m interested in learning a bit about the Jabber/XMPP protocol. There’s only one way I know to do so, and that is to mess with it. So I decided to install a Jabber server, ejabberd. Installing ejabberd on Ubuntu is easy, but I hit an immediate roadblock: ejabberd has a web-based administrative interface, but following [...]
recursion in erlang
Some months ago Kevin (check him out at Hypothetical Labs) started the RDU erlounge, a monthly meeting of area erlang enthusiasts. The meetings were organized via a mailing list. Recently one of the guys on the list, Jared (Alloy Code), asked for a bit of help. He was working an exercise (a function to compute [...]
sum of file sizes
This was recently posted to the erlang-questions mailing list I am trying to grok how to write a simple ‘du’ like program that walks a directory structure ( not just one but all nested directories ) and calculates a sum of all the file sizes. I found some sum() code that I understand how that [...]
generating random permutations
I want to consider the simulation of dealing a deck of cards. The deck is simply the list of integers D = [1,2,...,52]. Dealing the cards amounts to generating a random permutation of D. Here’s how I would do it in java. public class Shuffle { private static java.util.Random rand = new java.util.Random(); // construct [...]
Posts