On Scheme

Thoughts on Scheme and teaching Scheme

Archive for the ‘Windows’ Category

Actual Code

Posted by Peter on April 27, 2006

I know it seems like my blog has turned into a place for me to talk without actually accomplishing anything. To remedy this I am releasing a working draft of my asynchronous garbage collector. Unfortunately for you it is written in C++, and is meant to be compiled in windows. (Bless me father, for I have sinned. It has been 2 function calls and a continuation since my last garbage collection.) Porting it shouldn’t be that hard if you want to. Anything that is platform dependant is conveniently located in platform_dependant.cpp. Also you need to define the symbol GC_COUNT_POINTERS if you want the sample to compile. Finally I make use of the hash_map and hash_set classes, which may not be part of your compiler’s stl.

How it works

In this system there are two types of references, hard and soft. A hard reference means that you guarantee that the reference will not become part of a cyclic data structure. Usually you want to acquire a hard reference to an object you are using directly. Soft references are references from one object to another. If a cyclic data structure made up of soft references occurs the garbage collector will be able to collect it. When you alter an object’s member pointers you must call gc->ReferenceSoft and gc->DereferenceSoft as appropriate on the pointers as appropriate. Finally when altering member pointers of an object that has existing references pointing to it you must surround the code altering it with gc->BeginEdit and gc->FinishEdit calls.

For more specific details I suggest that you check out the example provided. Note that the functions defined in the sample do not reflect how I actually expect to define Lisp functions (in terms of parameters).

Source is available from Sourceforge (see sidebar ->) under “Garbage Collector”.

Posted in C/C++, Exploring Scheme, Windows | Leave a Comment »

Compiling a PLT Extension With Visual Studio

Posted by Peter on April 2, 2006

If mzc doesn’t work properly for you, and it doesn’t work (completely) for me, or if you simply want to use Visual Studio for your coding and compiling then you have a bit of work ahead of you. Actually the process itself isn’t that complicated, but good luck figuring out how to do it with the documentation, which is a bit sketchy on how to do things without mzc.

First create a new win32 project and choose the .dll option. (the finished extension is a dll file that Scheme will load at run-time).

Next go to tools->options->projects->VC++ directories (in Visual Studio .Net), and add the path for the PLT libraries and include files to the directories searched for .h and .lib files at compile time. (the directories to add are …\PLT\include and …\PLT\lib\msvc respectively).

Thirdly go to Project->Properties->Linker->Input and add the following three files to the additional dependencies: mzdyn.obj, libmzsch301_000.lib, and libmzgc301_000.lib. Actually you don’t need all of these, but it doesn’t hurt to include them just to be sure.

Finally create a new .def file (for example myproject.def) with a text editor. The body of this file should be the following:

LIBRARY   [name of project (the output file minus the extension) goes here]
EXPORTS
   scheme_initialize
   scheme_reload
   scheme_module_name
   scheme_initialize_internal

Now add this file to your project (as if it were a new source file), and go to Project->Properties->Linker->Input again and enter the name of this file for the Module Definition File entry. This .def file tells the compiler that these are functions which the .dll needs to export, and that they have to be named exactly as shown (because the Scheme interpreter expects to find them as such, and if they aren’t present the extension will not be loaded). The scheme_initialize_internal function is provided by a library, you don’t need to write it. The other three functions you must define (as is outlined in the documentation). You don’t need to mark them in any special way for export, the .def file takes care of that.

Now, if you want a tutorial on writing an extension, well that is the job for a different post.

Posted in C/C++, Windows | 3 Comments »

Yawn!

Posted by Peter on April 1, 2006

In case you are wondering why I haven’t been updating for the last few days: I have been working somewhat intensely on my Scheme Direct Graphics package (0.1 version now available on sourceforge). Unfortunately it only works on windows and under Dr. Scheme at the moment, although in the future I may extend it to do more on more platforms. If you use windows and Dr. Scheme and want to give it a try download it from sourceforge and extract it. Inside it, a couple folders deep is a test.scm file that once loaded will allow you to execute the command (go-for-a-drive) which will let you roam arround in the spaceship again, this time much more smoothly and with no flicker. Anyways I am too tired to go more into detail, so sometime tomorrow I’ll give an in depth rundown of what it does, and produce some documentation / tutorials for anyone else who wants to write PLT extensions

Posted in C/C++, Exploring Scheme, Windows | Leave a Comment »

An Interesting Project: Graphic Forms

Posted by Peter on March 19, 2006

I ran across an interesting project, in Common Lisp, which promises to make some cool GUI features available under windows. It doesn’t look like it is far along yet, but hey, it has promise. You can check it out here.

Posted in Common Lisp, Windows | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.