This page is kept for historical purposes only. Please see the home page for my current situation. —Luca Saiu.

DEVL 2009 - Sixth TP (2009-10-27)

I received just a few submissions for last week's TP; this one is a little easier.

In the lab at Institut Galilée you have to use the usual small hack to add my customized paths to $PATH, so that you can use the version of Guile that I have installed in my home directory:

source ~saiu/add-prefix ~saiu/usr

You have to execute the command line above in each terminal you use, before being able to execute guile or guile-network-game.

Notice that this week's task requires guile-network-game version 0.0.2 (or higher, if a higher version exists).

You can also work at the Institut Galilée lab now. I solved the problem on Tuesday afternoon; sorry for that. Just in case you're interested, the error was not in my code; it was this bug of the freetype library: the version installed in the lab machines had the bug, so as soon as I discovered the problem I hand-compiled and installed a newer version in my home directory. Now everything works if you run the line starting with source above. You shouldn't have any problems if you work at home and you have a recent freetype.

The problem

Take guile-network-game version 0.0.2, and run the demo scm/demos/console-demo.scm. The new console is nice and easy to use as you can see from the demo source, but it can only be used for output, not for input.

Modify scm/console.scm so that the console also supports keyboard input. Remember that there is a main loop, so you can not just add a function which waits until the user enters a text and pushes Enter (Entrée on the French keyboard), because in the mean time the program has to continue to draw everything and possibly update the application state.

Your new function should be called console-ask-user-input must have exactly two parameters:

the function given to console-ask-user-input will be called when the user confirms his/her input string with Enter or cancels with Esc (Echap on the French keyboard).

It would be reasonable to echo what the user is typing (i.e. to write the line that the user is composing on the console); yet I forgot to tell you this when I initially presented the problem to you in class, so this is optional (notice that this feature not being required makes the problem much easier).


You need to add an additional state of the console (see scm/console.scm).

It would be a good idea not to hide the console when input is being requested to the user.

How to test

An easy way of testing console-ask-user-input is modifying the demo scm/console-demo.scm.

Here is a simple echo test: if you write this just before the main loop in console-demo.scm then the system will repeat what the user entered, just one time.

(console-ask-user-input "Please write something" 
                        (lambda (input)
                          (if input
                            (console-write-line! (string-append "You wrote \"" input "\"."))
                            (console-write-line! "You canceled."))))

Of course the main loop is the call to call-with-maximum-frequency.

Back to my home page...

Luca Saiu
Last modified: 2009-10-28
Copyright © 2009 Luca Saiu
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.