2

Hello world!

Well, I've finally done it and installed a blog.  In this blog I have a place to publish my thoughts and accomplishments for anyone who may be interested.  Also I plan to start some discussions about Software Engineering topics and projects as I post about them.

First let's hear from my favorite scripting languages:

#/usr/bin/python
print "Hello World\n"
#/usr/bin/ruby
puts "Hello World\n"
#/usr/bin/php
echo "Hello World\n";

Then a blast from the past. I programmed in QBasic for roughly 6 years. I've since forgotten it all. I even had to look up the syntax for comments.

' This is Q-Basic
CLS
phrase$ = "Hello World!"
LOCATE 13,40
PRINT phrase$
END

And now two of my favorite compiled languages:

(* This is OCaml *)
print_endline "Hello world!";;
// This is C#
using System;
class MyClass
{
  static void Main()
  {
    Console.WriteLine("Hello World!");
  }
}
1

OCaml Oh My…

I'm starting my graduate classes finally.  My school has this cool program called Fast Track where you're allowed to take graduate level classes as an undergrad student and get dual credit.  I finally qualified for the program and signed up for as many classes as I could fit in.

One of those classes is one called Advanced Programming Languages.  It's so advanced that I had to get permission from the Associate Dean.  He said no so I went to the teacher and he said he's out of town but it's ok with him as long as I learn OCaml before the class.  So I went back to the Associate Dean and he finally signed for my class.  Now I'm going through OCaml tutorials.  Having a strong background in procedural programming, it's very different for me.  I've done some work in the past with XSLT (a functional language written in xml, yuck) and used the functional parts of PHP, Ruby, and Python.  I've even tried to read the Neko compiler which is self hosting written in NekoML. NekoML is a variant of OCaml, but a little easier.  Well I couldn't read much of it.

Here is my first OCaml program.  It uses nested functions and takes advantage of the rec keyword to control function namespacing:

let range a b =
  let rec range a b accum =
    if b < a then accum
    else range a (b - 1) (b :: accum)
  in
  range a b [];;
 
range 1 10;;

Pretty cool huh.  I ran it in the interactive interpreter like I do in my scripting languages. The range function defined in the outer can't be used till after it's definition since I didn't include the rec keyword. The inner one uses rec and an extra accumulator so that it will be compiled with tail recursion.  Otherwise my range function would be very limited in what it could do without causing stack overflow.  Once the inner range function is defined, the outer one, which is just a wrapper, can call it directly.