Wednesday, April 14, 2010

The Tcl War

Weird thing came up twice on the web in the past two days. First was a search for "Tcl nntps", the second was on Reddit.

I've always been an admirer of Richard Stallman. Although I prefer vi to emacs, and GNU Hurd seems like total vaporware, you have to admire the impact Stallman has had, and his consistent application of his values.

But now, I'm afraid I will have to charge him with heinous war crimes against humanity!

His objections are pretty weak (no linked lists?, slow adds?). And to suggest Lisp as a replacement is just silly. Tcl syntax is weird, but Lisp (from Wikipedia)?

(let loop ((n 1))
(if (<= n 10)
(begin
(display n)(newline)
(loop (+ n 1)))))

I have no idea what that does. I think it prints the numbers one to ten...
In Tcl:
for {set i 0} {$i <= 10} {incr i} {
puts $i
}

A lot closer to C. Actually, Tcl has gotten a lot easier for me once I started thinking of it as a prefix type language (like Lisp). Just with [] and {} instead of ().

Saturday, April 10, 2010

Delight

(Continuing my experiences with the D programming language) Hmm, missing some back links before this.

I have been looking into what it will take to program my video card (Nvidia GeForce FX 5200). It's embarrassing how little information is out there. Nvidia used to maintain an open source driver - which only supported 2D. Given their refusal to support 3D, I have to wonder about the quality of the 2D support. There is a project to develop 3D support, but their focus is newer cards (and they are short-staffed).

I've been itching to write a cycle based processor model, and it seems now would be the best time. To mix things up a little, I've decided to write in D.

I've been working (on and off) about a week now, and I must say that programming in D is quite delightful.

Best parts:
  • No IDE needed - I use vi and make, and its no problem at all
  • Enums auto-namespace - all the enums are like RegBytes.BH, no need for crazy C++ kung-fu
  • Built-in array - being able to write:
    mem_[startAddr..startAddr+img.length] = img;

    with auto-bounds checking is a lot nicer than fighting with the dangers of memcopy
  • Writefln - writefln("Null in decoder for byte: ", "%x", op); (format as needed)
I haven't had any real negative experiences. I need to figure out how dependencies work. I'm not sure when I need to recompile a module based on what it imports. I've had to do some make cleans.
There are some gotchas for hardened C++ users, but they are related to improvements:
  • struct and class are different - this is a good thing, but it can be easy to forget. A struct is plain-old-data (like an int), so it is allocated automatically. A class is a pointer, so it defaults to null. You need "ptr = new Class" before you can use it. I ran into this once.
  • Circular import dependencies - you have to avoid them. Sometimes this means you need to break some stuff into a separate file. C++ solves this by using includes to toss everything into one big stewpot and doing multiple passes.

Friday, April 02, 2010

Hello, Graphics World

Of course, a screen shot can make it look like you are much further along than you really are...

I don't have interrupts (so no disk, or keyboard) and I can't create processes, but I can (almost) print "Hello world".

Except, I can't print capital letters, or spaces...