kivikakk.ee

Mer OCaml

sairyx

This one was quite tricky, and my solution is inelegant, but I’m glad to have gotten it.

Inserting a new word into the trie (data structure as defined earlier):

let rec insert word =
  let first = String.get word 0
  and rest = String.sub word 1 (String.length word - 1)
  in let insert_node = function
    Letter(c,b,nl) as l -> if (first=c) then
                             if (String.length rest)=0 then Letter(c,true,nl)
                             else Letter(c,b,insert rest nl)
                           else l
     in function
         (Letter(c,_,_) as h)::t when (first=c) -> (insert_node h)::t
       | h::t                                   -> h::(insert word t)
       | []                                     -> [insert_node (Letter(first,false,[]))];;

Some helpers for free:

let rec string_of_trie trie =
  let string_of_node = function
    Letter(c,b,nl) -> (String.make 1 c) ^ (if b then "*" else "") ^ " " ^ (string_of_trie nl)
  in "[" ^ (String.concat "; " (List.map string_of_node trie)) ^ "]";;

let print_trie trie =
  print_endline (string_of_trie trie);;

Next I think I have to establish the height of this thing or something, so that’ll let me do a prettier print_trie later.

Style comparison:

let rec construct = function
    []   -> []
  | h::t -> insert h (construct t);;

let construct wl =
  List.fold_left (fun x y -> insert y x) [] wl;;

A trie:

type lex_node = Letter of char * bool * lex_tree
and lex_tree = lex_node list;;

A function to test whether a word belongs in the dictionary (answer to an exercise from the book “Deploying Applications With Objective Caml”):

let exists word trie =
  let rec exists_aux acc nl =
    let exists_inner = function
      Letter(c,b,nl) -> let wc = (acc ^ (String.make 1 c))
                        in if b && (wc=word) then true
                           else exists_aux wc nl
    in List.exists exists_inner nl
  in exists_aux "" trie;;

Now working on “insert”.

tea clouds, er lang (stupid boy), re re re. RE. Religious education (Regular expression). Religion is a regular expression? /religion/g. Religion as a global religious expression. /religion/i; case-insensitive religion. Insensitive expression. Stunning prophecy on p.LXXI.

Don’t get started on labels again. I love jumping to labels. They drive me along on my little way, helping me avoid all actual inclination to do things, but just to say “oh yes I’m X and therefore I can have the opinion Y.”

I have applied the following terms to myself in the past:

girl. felon. agnostic. Australian. wife. solipsist. son. alone. pilot. husband. monk. nihilist. daughter. friendly. Christian. enemy. vegan. Buddhist. assured. right. Estonian. parent. vague. transwoman. lover. man. gay. heterosexual. polyamorist. boyfriend. queer. genderqueer. boy. atheist. girlfriend. unfriendly. wrong. transgender. father. Zen practiser. Sikh. antipatriot. vegetarian. feminist. universalist. woman. omnivore. friend. humanist. relativist. theist. programmer. homosexual. interpreter. Muslim. Mahayana practiser. mother. monogamist. Theravadin.

myself?

That’s one label I should keep.

書く

sairyx

書くのは書くから始まる。 Writing starts with writing.

When I upgraded to Ubuntu 10.10 Beta, my Ruby (1.9.1) and its RubyGems (and thus any loading of any external code) stopped working pretty quickly. Searching around didn’t do a bunch of help, until I stumbled upon a great entry by YAMADA Akira 4 days ago entitled “Ruby 1.9.2とRubyGems 1.3.7とGem.pathの消失”.

I’m providing a translation here for those interested, albeit a very poor one with many inaccuracies.

If you’d like a really short way to get your gem command working again, add this line to the top of your /usr/lib/ruby/1.9.1/rubygems.rb:

Gem::QuickLoader.remove unless !defined?(Gem)

The problem is that it doesn’t actually seem to fix the issue (not on Ubuntu, anyway). While gem runs and installs things, require is still broken. I’m continuing to investigate.

The source text is copyright to its author YAMADA Akira.

Read more

A few weeks back, my flying instructor related a terrifying thing—a full time grade 2 instructor’s pay is somewhere in the range of $32,000 to $34,000.

And, while I’d certainly like to continue flying for the joy of the activity itself, it seems a tad too selfish (and frankly wasteful) to do so when the opportunity cost is so fantastically high.

Hence I’ve decided to give it a (permanent) rest. I definitely enjoyed it while it lasted, and am happy to say that I’ve spent a significant amount of time up in the air flying a plane both with an instructor and on my own, and while I’m a tad annoyed that I haven’t gotten to GFPT standard (where I can take passengers while going solo), and was indeed just about to go on my area solo, there’s no time like the present for directing my energy into something else that I want to continue with.

In other news, I’ve gotten back into Akari in a big way, and look forward to making more time for it in the future.

Områdssolo

sairyx

Jag kanske kan prata om att flyga här. Förra helgen tog jag provet för områdssolo; jag fick 27 av 30 eller något, för ett pass måste man få minst 21 poäng. Denna söndag jag ska göra mitt förhandsområdssolo test (en provflygning med en senior flyginstruktör), och om allt är bra, då ska jag direkt gå ut på mitt områdssolo!

Ska vara bra! Om jag får chansen, kommer jag att posta lite bilder efteråt (om allt går bra, och inget skit väder heller.. det skulle ha hänt förra vecken, duvet..).

Area solo

sairyx

Perhaps I can talk about flying here. Weekend before last I did my theory exam for the area solo; I got 27 of 30 or something, which is a clear pass (minimum mark is 21). This Sunday I’ll be taking my pre-area solo flight (check flight with senior instructor to ensure I won’t kill myself), and assuming that’s all good, I’ll then immediately go out for the area solo.

Should be good! If I get a chance, I’ll post some photos after the event (assuming all goes well, and no crap weather. This was all meant to happen last week, but you know …).