::::: : the wood : davidrobins.net

Programming languages and OCaml

News, Technical, School, Trading ·Tuesday December 30, 2008 @ 20:38 EST (link)

"Never get out!" he yelled. "That's it. Of course. We shall never get out. What a fool I was to have thought they would let me go as easily as that. No, no, we shall never get out."
—C. S. Lewis, Voyage of the Dawn Treader.

20081228: The plow came today, while we were sleeping (we're nocturnal over holidays). Fortunately, our neighbo(u)r, AH, rang the doorbell and woke me up. When I say fortunately, I'm being sarcastic, since there's nothing we could do (can't move the car, it's already at the top of the driveway and there's too much snow and ice around it to move it back any further, even if I were inclined to put it back in the driveway, which I'm not, given the work of getting it out). We should be able to get out tomorrow, God willing. It's been a long time.

My course next quarter is CSE P 505: Programming Languages (Dan Grossman). It looks interesting. I worked on "homework 0" (no points, just "get to know you" questions), and read the syllabus (about as expected for a programming languages course; I was happy to read words like "elegance" and "minimalist", though).

I installed OCaml on my home machine, since it appears to be the primary language for the course, and tried to install the UWa. research "SEMINAL" patch (it's supposed to improve error messages, although unfortunately it only works against 3.08.4, not newer versions, latest being 3.11.0 at time of writing). I was able to use Gentoo's ebuild utility to fetch and unpack the base, then I applied the patch, then used ebuild again to compile (meaning build), install (to a temporary location as usual with Gentoo), and qmerge (merge the install tree with the live system). However, the install stage got stuck in an infinite loop (keeps spawning make, had to kill a huge nested stack of processes); that didn't happen without the SEMINAL patch, so the patch is probably causing the problem. I went back and installed the latest version, without the borked patch.

Sample OCaml code (this is a function from the second homework for the class, but it's not required to turn in; it's something I wrote for fun to converts a sequence of turtle graphics coordinates—generated by other parts of the assignment that interpret a subset of Logo (note time travel)—into an image using ImageMagick; it's not especially graceful, but it gives the general idea of the language; in the .NET world, F# is based on OCaml, except it has useful libraries):
(* for fun, build a canvas and draw the moves on it using ImageMagick *)
(* in standard logo we'd have pu/pd to tell when we're drawing; here we have
   to just draw everything *)
(* tested with interpLarge/interpSmall/runTrans *)
let draw_cmd file size movelist = let pl = interpLarge movelist in
  let o = (float size)/.2. (* origin *)
  in let line x y =        (* generate ImageMagick MVG path line command *)
    "L " ^ string_of_float (o +. x) ^ "," ^ string_of_float (o +. y)
  in (String.concat " " (["convert"; "-size";
    (string_of_int size) ^ "x" ^ (string_of_int size); "xc:white";
    "-draw"; "\"stroke black fill none";
    "path 'M"; (string_of_float o); (string_of_float o)] @
    (List.map (fun (x,y) -> line x y) pl) @ ["'\""; file]))

(* test function for ease of use: draw on an 800x800 canvas to a web-accessible file generated from the given name *) let draw name movelist = Sys.command (draw_cmd ("/home/static/htdocs/dbrobins/tmp/" ^ name ^ ".gif") 800 movelist)
Burned some DVDs of some episodes sitting on the MythTV HD that we've already watched: mainly Stargate Atlantis. Wrote filldvd.pl to chunk a set of files into DVD-sized blocks, using Filesys::DiskUsage, Number::Human::Bytes, and File::Copy.

20081229: Found this new economy/finance blog, Pomp and Surkanstance (by two brothers Surkan), via the Investment Club internal mailing list. Looks interesting, especially his recent predictions for the technology industry in 2009. If he's right, I need to short GOOG, RIMM, AAPL, VZ and other tech firms (including MSFT), oil (OIL/USO/futures?), local (S&P, NASDAQ, DOW) and foreign indexes, and EUR/USD, and go long pay-as-you-go IT support and mobile phone companies. He predicts volatility, which is usually good for traders.

We finally got out (!): went to Safeway (groceries), Target (Wii game for Honey with birthday money, but they were sold out so she got a game at Circuit City), Half Price Books (extra 20% off), Circuit City (looked at monitors, bought another battery backup to replace one that died), Hard Drives Northwest (looked at computers and monitors, towards building a new trading system), Estate Arms (gun store nearby; closed), and Costco (bulk groceries). ViewSonic monitors look a bit fuzzy; HP and Dell looked good, but Acer looked the best; maybe it's just taste, but Acer looked sharper and clearer at Circuit City and HDNW. We got the following books at Half Price Books: Called my mother in the morning, since she was gone (she and Emily were taking Grandma Martin to other relatives Toronto) when I called Christmas Day.

20081230: Got out to the library today (it's closed Monday). Logged into work just before midnight to enter vacation time and avoid forfeiting time over the max allowed to keep.

Books finished: Safe Strategies For Financial Freedom, Beyond Candlesticks.

DVDs finished: Daylight, The Transporter.