WiiScheme

Friday, May 9, 2008

New Instructions!

We received new instructions from Sinan last week on Monday. Since there's been no posting here for a while I decided to post about the progress of our research.

On monday, during a regular “poking session” with Sinan about preparing the official papers to buy some Wii Remote for the department, he told me they were almost ready and we should start preparing a dummy teachpack. He also told that it was not as easy as it looks and we should do some research about them first. I've been going through some MzScheme manuals and Help Files on my free times and found out that there are two ways of extending DrScheme: Teachpacks and Tools. Tools are designed for extensions on DrScheme's functionality, like a debugger, syntax checker, or buttons for some other stuff, so we won't be needing them in our project. What we actually need are:

Teachpacks

Teachpacks are sets of procedures which place themselves into a language in DrScheme. They are basically libraries, providing the coders to use previously defined functions for them to use when needed. As an example, the world.ss teachpack is a library and the Big-Bang is a defined function within the library, which we can use if we add the teachpack to the programming language in DrScheme. That and the other functions in the teachpack are basically defined functions, like the ones we do in our projects, but built into a single file in a stack for use.

Why use Teachpacks?

There are three main opportunities teachpacks provide us;

1- The academic use of DrScheme may require students to implement codes they won't be able to.

Let's say a teacher wants his first year students to prepare a project in DrScheme every week. Think of how boring it would be to design and implement functions which only calculate some stuff and return values based on the input. Anyone could easily get bored within 3 weeks maximum and I can bet on that everyone will start to lose motivation rapidly. Because everyone still knows only the basics of Scheme, no one is able to implement some code which provides visual output, or use mouse movements, clicks or keyboard events as input to prepare a project which's fun in the end. Right here come teachpacks into the scene; They provide the functions necessary to do all those fun stuff so the students can focus on their work and have fun at the same time. They even can create simple games (such as breakout) using only their knowledge and the teachpacks with the necessary codes built in.

2- The most commonly used functions can be implemented into and called from teachpacks.(Or “Abstraction” if you like to use no more then one word)

In our projects, we always try to implement generalised functions to be able to use them in our later projects. If we, let's say, create multiple teachpacks for each kind of theme (such as list processing, drawing, playing sounds ect.), we'd just need to add the teachpack to DrScheme and use the functions whenever we need them, without having to design and implement them over and over again. This is a commonly used thing during the development process of any kind of software. I am building libraries of the things I do a lot when I'm programming as well, and I'm using them on other projects when I need.

3- The more powerful implementations of Scheme may be used within the less powerful ones

Well, the title says it all. You can prepare a teachpack with the advanced student language in DrScheme with keywords, which don't exist in the beginning student language. Let's say we want to draw a circle to the screen using the beginning student language. Because the beginning student language doesn't have the “circle” function defined within, we can't do that without using a teachpack which was written in a more powerful teachpack which provides us the function needed. (Think or world.ss: It needs lots of imperative functions to be able to run, but when you add world.ss into Dr.Scheme, you don't even have to know what “imperative” means when you're designing and implementing an animation.)

Why do we need to prepare a teachpack?

Our ultimate goal is providing a way to use the WiiMote on the DrScheme environment to be able to do stuff like these, which should be as simple as a first year student's regular project. Well, that's not possible without the use of a library. It's a pretty big and complex job to do that, and to simplify it, we're going to use the help of teachpacks. Just like we use world.ss for mouse and keyboard inputs, we want the students to be able to use the input from WiiMote as well. Without teachpacks, they would have to design and implement complex functions to “listen to what WiiMote says”. We will also have to use a more powerful language to access the input the computer receives from WiiMote to do that.

Alright, we're going to prepare a teachpack, but how?

It's not that much different from everything we did in class this year. First we should build a module, in which we will place everything else. Just like this:

(module dummy mzscheme

...)

The “module” function is the main function of the teachpack; everything in the teachpack must be in that function, otherwise it wouldn't work. The first parameter the function receives is the name of the teachpack, and it should be the same with the name of the teachpa

ck file we are going to create: “dummy.ss”. The second paramether is the language of the teachpack we are going to use. I chose mzscheme for the example teachpack. Note that the language you are using during the implementation of the code should be mzscheme also. Now let's keep going:

(module dummy mzscheme

(require (lib "defmacro.ss" "mzlib"))

...)

The “require” function adds the requested library to the code, just like adding a teachpack into a project. The “defmacro.ss” library is required for defining macros. The “lib” function just calls the file in the folder in DrScheme's “collects” folder. In our example, it calls “.../PLT/collects/mzlib/defmacro.ss” file and lets us use it. Let's define a function now:

(module dummy mzscheme

(require (lib "defmacro.ss" "mzlib"))

(provide addfive addthree)

(define-macro (addfive n)

(+ 5 n))

(define (addthree n)

(+ 3 n))

(define (addtwo n)

(+ 2 n))

)

With the “provide” function we're telling the program that we're going to define “addfive” and “addthree” functions for external use (external use as in the user will be able to call those functions). Just below that, we define a macro and some functions. Defining a macro is not necessary actually, I defined one just so you can see the benefits of the library we added. After doing that, we can now save our file with the .ss extension and use it as a teachpack. Note that the addtwo function cannot be used because it was not provided to the user.

We, of course, are not limited to defining functions. We can define variables and keywords for use as well.

(module dummy mzscheme

(require (lib "defmacro.ss" "mzlib"))

(provide addfive addthree helloworld)

(define-macro (addfive n)

(+ 5 n))

(define (addthree n)

(+ 3 n))

(define (addtwo n)

(+ 2 n))

(define helloworld "Hello World!")

)

Here's what happens when we call the functions built into the teachpack we've just prepared:









As you can see above, we can call the addfive function, addthree function and helloworld variable without any problem. But addtwo does not work, because it was not provided to the user.


The teachpack for the use of WiiMote will not be this simple of course, it will require a way more complex type of coding. But the main idea is the same. The next step in our project is hopefully getting our hands on a WiiMote, and find a way to receive input into DrScheme from it.

0 Comments:

Post a Comment

<< Home