Archive for the ‘Uncategorized’ Category

Lambdavaluator resurrected

Saturday, May 2nd, 2009

It’s not an assignment so I’m putting it back on the internet, because everyone was obviously missing it so much.

http://adradh.org.uk/code/lambda/lambda-0.0c.tar.gz

At least it was a slightly better reason than not being bothered

Tuesday, March 3rd, 2009

Well no endofunctor.net after all, probably. NearlyFreeSpeech.net charge a cent per day for a MySQL database, which of course is nothing in the grand scheme of things, but since the rest of the stuff1 would probably cost less than that per month, it kind of put me off a bit.

I might start posting here again, but I don’t think I need to say how that will work out.

Update! I’m writing an HTTP session library in Haskell, for future use somewhere. I wonder where..?


  1. Other than the domain name, obviously. 

OCaml’s type system is awesome

Friday, September 12th, 2008

…If not just a little bit complex. But for objects, it has some sort of crazy static duck typing thing going on.

let f obj = obj#set_x 4;;
(* f: <set_x: int -> 'a; ..> -> 'a *)

The bit I mean is the argument to f, i.e. the <set_x: int -> 'a; ..> part, which is, broadly speaking, “any object with a set_x function accepting an int“. It’s like C++ templates without all the excessive verbiage (or, alternatively, like a dynamic language).

let obj = object
    val mutable x: int = 0;
    method set_x x': unit = x <- x'
end;;
(* obj: <set_x: int -> unit> *)

Now of course we can apply f to obj and it will automagically work. Also, as you can see, we have singleton objects, which is nice I suppose?

Shame that the rest of the language isn’t so good. Well, I mean, compared to something like C of course it is, but it just feels like such a pain in the ass sometimes. (Why aren’t all my lets rec, and all that.)

In other news: the website’s up for paying again. Hopefully I’ll remember before it’s taken down this time.

Sieve of Eratosthenes as a Regexp

Thursday, September 4th, 2008

No, really.

sub is_prime { ('1' x shift) !~ /^1?$|^(11+?)\1+$/) }

Dialog box of the day

Tuesday, April 15th, 2008

PS. No GSoC for me this year. :effort:

GSoC

Thursday, March 20th, 2008

The deadline for GSoC applications is fast approaching. I’d totally forgotten about it until the obligatory CoC thread, so I hadn’t given it the slightest bit of thought until the last couple of days.

Now that I remember it exists though, I really want to enter. Despite my recent, um, problems with anything resembling writing a program, and the fact that to date I have not written a single program exceeding about five hundred lines. I have to start somewhere, I suppose? A GUI for darcs, written in Haskell, is probably not the best place, though. But it would be fun!

Pros

  • Something to do
  • Might actually *gasp* do something useful
  • Helping darcs
  • CV++
  • Money :v

Cons

  • Difficult
  • Requires attention span
  • Takes time
  • Hindering darcs with half-arsed contributions

So, will I apply? Ideally I’d say I’ll consider it. Really though, inertia means I probably won’t. Maybe next year.

edit: Obviously I don’t absolutely positively have to do a darcs GUI. It’s just something that caught my eye. Also Boost.SafeInt, which looks pretty easy, but if it’s as easy as it looks to me then someone with actual C++ knowledge would’ve done it in about an afternoon, so it’s probably not.

“Programming-language related pun” print

Thursday, March 6th, 2008

Factor is a fun language. It’s postfix, making your code look like mirror-image LISP (or, RPN, which of course is what it is), and for the most part, all the data (and functions, etc) are all on a single stack at once.

An example, which finds the answer to Project Euler problem 5:

USING: math kernel math.ranges sequences ;
 
: gcd ( x y -- z ) dup 0 = [ drop ] [ swap over mod gcd ] if ;
 
: lcm ( x y -- z ) 2dup gcd / * ;
 
: answer ( -- n ) 2 20 [a,b] 1 [ lcm ] reduce ;

Take the gcd function. It looks at the top of the stack, and if it’s equal to zero, deletes it. We have to duplicate it before checking, because = (and < and friends) replace the top two elements with t/f, and we may want to keep it around. If it’s not equal to zero, we swap the top elements, copy the second one over to the top, find the modulus of the top two, and recurse. So it’s basically the Euclidean algorithm in RPN.

Isn’t it funny-looking? The spaces around the brackets and (semi)colons are necessary; the tokens are separated by whitespace but otherwise can contain any character. Like in the above, [a,b] is all one word, a function which makes a range (or interval if you use the one in math.intervals, of course) from the top two stack elements.

For bonus points, it supports functional programming; the blobs in square brackets are ‘quotations’, which are just pushed on the stack as they are to maybe be called later. We need to do this for if, because only one of them is ever used. Similarly for while the quotations (one for the condition, one for the body) are called repeatedly.

A pity my syntax highlighting doesn’t support it. :(

edit: Euclidean algorithm fixed.

Disk failure

Wednesday, October 24th, 2007

Quoth e2fsck /dev/hda6 (which is /):

File /usr/lib/libkdeinit_kicker.so [...]
  has 1 multiply-claimed block(s), shared with 1 file(s):
        <The bad blocks inode>
Clone multiply-claimed blocks<y>?

Well that certainly sounds, um, happy. :suicide: (Also /var/messages.4 and something to do with git, but bleh old logs and I use darcs.)

Though now I have a bad blocks inode (I’d prefer not to have any bad blocks, but whatever), hopefully my disk will stop dying every ten seconds.

Also, why the hell does Fedora 7 change /dev/hdx for /dev/sdx? It just seems to add confusion for no reason.

No more Windows

Thursday, October 18th, 2007

Today I decided that there is little need in keeping an OS that I’ve used perhaps an hour or less total in the last year, so I deleted its partition. My heart belongs to Linux. :unsmith:

To remove it I grabbed the GParted LiveCD; it turns out I didn’t need to, but I was going to expand /home to fit the space. But either way it’s something to have if I need it later.

My plan was to delete Windows’ partition, hda2, and expand /home, which is hda3, to fill its space. I was expecting this to be quite involved: reformatting /windows to ext3, copying the contents of /home over, deleting the latter and expanding it, changing the label on the new partition to /home, deleting hda3, and resizing hda2 in its place. But GParted abstracts all that away. It lets you tell it to expand things backwards and it’ll deal with all that itself. So I told it to delete /windows and expand /home to fill the space. I clicked apply and waited.

Deleting the Windows partition was fast, but since all the data had to be moved backwards, resizing home wasn’t, at all. It stopped about halfway through the test (thankfully not the commit), complaining of an I/O error. I have no idea why, but whatever.1

Plan B time: creating an ext3 partition in the place of /windows and call it misc. Which I did, and I now have a 20 GiB empty partition belonging to my normal account. I might in fact do the moving-it-to-/home the hard way, now at least I know my system boots.

Oh, I also had to edit /etc/fstab. Painless, if only because I copied the line above it replacing LABEL=/home with LABEL=/misc (after e2labelling it, obviously). And removed the windows line.

Now I’m off to sudo cp -Rv /home/* /home/.??* /misc. I foresee this taking quite a while.

Edit: I’m back and with the exception of a couple of unimportant files everything seems intact. :yaay: Though I forgot to preserve ownership and home directory /home/andy does not exist is a less-than-nice way of saying it. (You forgot the -p you twonk would have been much better.)

Icon by Alain Clement.


  1. I was somewhat less apathetic about it at the time, of course. Anything that involves moving partitions makes me paranoid, even if I had backed everything up about ten minutes previously.