CTM: Exercise 2-4

[ Posted by Urban Hafner Thu, 25 Aug 2005 10:06:28 GMT ]

The problem

The if and case statements. This exercise explores the relationship between the if statement and the case statement.

(a) Define the if statement in terms of the case statement. This shows that the conditional does not add any expressiveness over pattern matching. It could have been added as a linguistic abstraction.

(b) Define the case statement in terms of the if statement, using the operations Label, Arity, and '.' (feature selection).

This shows that the if statement is essentially a more primitive version of the case statement.

My solution

(a) What we are trying to emulate is the statement

*if* <x> *then* <s>1 *else* <s>2 *end*

As we are only covering the kernel language we can assume that is either true or false, so the if statement can easily be translated into:

*case* <x> *of* *true* *then* <s>1 *else* <s>2 *end*
(b) What we have to check is, that 1) the labels of and the are the same 2) that the both have the same arity and the field names are the same and 3) that the field values are the same.

  if {Label <x>}=={Label <pattern>} then
    if {Arity <x>}=={Arity <pattern>} then
      if <x>.first==<pattern>.first then
        if <x>.second=<pattern>.second then
          ...
          <s>1
        else <s>2 end
      else <s>2 end
    else <s>2 end
  else <s>2 end

If course this is not exactly right, because Arity returns a list which (I think) cannot be compared with ==, but the idea should be right.

Tags , ,

Quote of the day I

[ Posted by Urban Hafner Tue, 23 Aug 2005 12:43:00 GMT ]

My girlfriend’s (Ioanna) uncle asking his wife who swept the bathroom floor:

“It was either Ioanna or she made Urban do it.”

Tags

NARCL 0.4.1

[ Posted by Urban Hafner Wed, 10 Aug 2005 11:47:00 GMT ]

This release just adds a better README, actually a README that should be useable.

Download: narcl-0.4.1.tar.bz2

Have fun.

Tags , , , , , ,

Started reading CTM again

[ Posted by Urban Hafner Tue, 09 Aug 2005 11:21:28 GMT ]

I’ve started reading CTM earlier this year but didn’t get farther than the second chapter. The book is just a bit too CS and too mathy to be read lightly.

But a few days ago I got an email from Martin Maney from the Chicago Python Users Group. Apparently they have started a book club and chose CTM as their first book.

Martin asked if I wanted to join and I agreed because I thought I should take the chance to actually start reading the book. Naturally you might wonder how I’ll attend their meetings in Chicago, after all it’s not that near to Munich (or Athens). Fortunately they have a mailing list which means I can try this new hip internet thingie :)

Tags , ,

NARCL 0.4.0

[ Posted by Urban Hafner Sun, 07 Aug 2005 17:07:39 GMT ]

This is the release of version 0.4.0 of NARCL.

The tarball can be found here: narcl-0.4.0.tar.bz2.

The darcs repository is at http://www.cip.ifi.lmu.de/~hafner/darcs/narcl

What’s new?

This release is almost a complete rewrite of the whole library. The main purpose was the speedup of the rule mining. I have come quite far in this direction but I am by no means finished with it.

The aim is to allow association rule mining of data sets with at least 125,000 transactions and about the same number of items in reasonable time.

Have fun with the program and of course feedback is welcome.

Tags , , , , , ,

How Much is Inside?

[ Posted by Urban Hafner Sat, 06 Aug 2005 11:47:43 GMT ]

This is one of my favorite fun websites. Ever wondered how many rice crispy treats you can wrap with one roll of plastic wrap? Or how much fizz is in one bottle of Coke?

Well, probably not but it’s much fun to find out at How Much is Inside? .

Tags

CiteULike - A free online service to organise your academic papers

[ Posted by urban Fri, 22 Apr 2005 17:48:00 GMT ]

From the website:

CiteULike is a free service to help academics to share, store, and organise the academic papers they are reading. When you see a paper on the web that interests you, you can click one button and have it added to your personal library. CiteULike automatically extracts the citation details, so there’s no need to type them in yourself. It all works from within your web browser. There’s no need to install any special software.

It works similar to del.icio.us insofar as you are able to assign tags to each of your papers (or books, you can actually add every book from Amazon) and search for the tags.

Check it out!

Tags ,

Practical Common Lisp

[ Posted by urban Sun, 17 Apr 2005 20:37:50 GMT ]

So you want to know what it’s all about this language with the weird syntax (and I’m not talking about Perl here :))? Then Practical Common Lisp by Peter Seibel might be just the right book for you.

It gives you everything you will need to start your lisp hacking. And contrary to many other programming language books it’s really a book about practical stuff. And if you don’t want to spend the money for the dead tree version just yet, you can get the complete text from the books website.

Tags ,

Fico 0.1.1

[ Posted by urban Mon, 11 Apr 2005 19:29:58 GMT ]

This release is just a point release that makes the following changes:

  • Added script to run tournaments of AIs
  • Fixed bug that prevented the Board class from recognizing certain finished board positions.
  • Added support for draws

As before the tarball can be gotten from bettong.net/fico/ and the latest development version from the darcs repository at http://www.cip.ifi.lmu.de/~hafner/darcs/fico .

Tags , , , , ,

Fico Version 0.1.0

[ Posted by urban Sun, 10 Apr 2005 14:17:54 GMT ]

Fico is an implementation of the board game Havannah. It is completley written in Ruby.

The aim is to write a fairly strong AI for the game. At the moment the only features are that the program can play according to the rules and that a random player exists.

How to get it

There are two ways to get the program.

  1. Get fico-0.1.0.tar.bz2, the latest release tarball (generally new releases can be found at bettong.net/fico/)
  1. Get the latest development from the darcs repository: darcs get http://www.cip.ifi.lmu.de/~hafner/darcs/fico.

How to run it

To run fico against itself on a board of size 10 run the command ./fico in the toplevel directory. Run ./fico -h to see all possible command line options.

If you want to play against the program use the -b or -w switch to select your colour. You will then be asked to enter your moves in the terminal. Be sure to enter them in the form <char><number> (e.g. a1 or c4).

Hacking

You are of course welcome to write your own AI. But don’t expect to much (yet :)) from the framework that binds your bot into the rest of the application.

How to build your own AI

Look at src/player/RandomPlayer.rb for a simple AI. The necessary steps to get your own bot running are:

  • create a sublcass of ComputerPlayer
  • include TermComputerPlayer
  • define the method internal_generate_move. This method should return the next move of your AI.
  • patch src/fico.rb so that it uses your AI instead of RandomPlayer or Simple1Ply

Contact

You can contact me at urban@bettong.net. Watch this place for announcements of new versions.

Tags , , , , ,

Older posts: 1 ... 5 6 7 8 9