Wondrous Functional Languages

My colleague Matt wrote about a recent Ruby Quiz which emphasised short, elegant solutions. He was particularly impressed with a solution which used a property of Ruby hashes to generate a wondrous number sequence for any given integer in a single line of code.

That got me thinking about the solution in Scheme, a language I find very appealing, and Haskell, which I had started picking up a few months ago but had to abandon due to lack of time. Even so I managed to remember enough to get this basic solution within a few minutes:

wondrous :: Int -> [Int]
wondrous 1 = [1]
wondrous x
	| even x = x : wondrous (x `div` 2)
	| otherwise = x : wondrous (3*x+1)

Here is the most obvious implementation in Scheme:

(define wondrous
  (lambda (x)
    (cond
      ((= x 1) ‘(1))
      ((= (modulo x 2) 0) (cons x (wondrous (quotient x 2))))
      (else (cons x (wondrous (+ (* 3 x) 1))))
    )
  )
)

As you can see both of these functional languages are really suited to expressing such algorithms, particularly Haskell with its excellent pattern matching expressions. I have no doubts that there are far more elegant solutions in both languages; I’ll post them if I get suitably inspired.

Felis Chrisus

In some aspects of my life I feel like the proverbial cat: when I am inside I want to be outside, and when I am out I want to be in. I know not from where this decisive indecision comes from. Often I find I can oscillate between my two states of indecision freely, some mad pendulum motivated by chaos alone it would seem. The thing that gets me though is sometimes, just sometimes, I walk through the door to the other side, turn around, and find the door shut and unyielding; locked forever and never to be open again no matter how longingly I peer through the window.

Then one day, beyond prediction and imagination and without context: a house is built around me while I thought I was outside, giving me two places I want to be rather than here. A new turmoil to be sure; one that leaves me reeling: wondrous, breathless and afraid.

NCSS 2007

Yesterday saw the conclusion of the 2007 iteration of the National Computer Science School. The NCSS is a week long event held at the University of Sydney that sees a cohort of 70-odd senior high school students from around Australia (some from as far away as Broome) develop a search engine and web site from scratch. That’s right, a search engine, fully featured with crawler, indexer, stemmer, stop lists and recursive descent query parser. It’s a truly amazing feat considering that the implementation language for the search engine is Python, a language which most of the students have not used before.

My involvement revolves around a series of four lectures that I give to the students involved in designing the web site hosting the search engine, in which I cover topics such as:

  • The World Wide Web: Past, Present and Future
  • HTML: Semantics and validation
  • CSS: Joy from the separation of content and presentation
  • Accessibility: Making the web truly world wide

On the Thursday night of the school we hold a programming competition over two hours where students break up into teams of three to tackle a series of programming and web design questions. Scott and Matt from Atlassian were kind enough to volunteer as mentors for the night. The mentor’s role during the competition is to provide encouragement and direction to the team that they are assigned to as well as to discuss career options within the IT industry. It was particularly awesome to see Scott and one of his students working feverishly with pen and paper (and later a laptop) over dinner, discussing how to implement a recursive descent parser.

The event culminates in an all night work-a-thon on the Friday night where students and tutors stay up all night to complete their work followed by a presentation to parents and the client the next day. This is the most satisfying part of the experience for teachers and tutors as we get to sit back and enjoy the efforts of these talented students. I was absolutely thrilled to see students using fully CSS based layouts for their web site designs. One team even managed to add a touch of AJAX to their search form with search suggestions as you type, with no input from me I might add!

Huge congratulations are in order for Drs. James Curran and Tara Murphy whose tireless efforts every year are critical to the success of this event and to the many tutors who attend to guide their teams through the grueling program that is the NCSS.

The monarchists have much to answer

The Barmy Army love giving it to us Aussies (let’s face it, their cricket team can’t). Just have a look at this excerpt from their chant “The Aussies Love the English”

Long to reign over you
God save your Queen

The next time that we go to a referendum the pro-republic campaigners should rub our noses in this; the motion ought to pass by a light year. To allow this rubbish to continue would be downright un-australian.