On Tuesday 30 April 2013 07:49:57 William S Fulton wrote:

> There is a bit more tidying up to be done with the Guile examples. Geert

> or any other scheme folk, I'd really appreciate some help with the Guile

> code.


> I have just added Examples/guile/class which is the classic C++ example

> which was missing for Guile. The guile code in a runme.scm file needs to

> be added and the test translated from one of the other languages... they

> all output pretty much the same thing.


I still have to look into this one.


> The constants example doesn't display anything. Compare with any of the

> other languages.


The constants example was set up more like a test case. If any of the constants was not giving the proper result, an error would have been raised.


I have now added output very similar to the python example. I did keep the internal tests as well though.


> I can't figure out how to run the multimap example without it giving

> errors. How should it be invoked, or are there some problems in the

> script? Similarly for the port and std_vector examples.


The way to invoke the examples is a little odd at first sight, but nicely illustrates an alternative way to combine guile with c code. Guile allows you to create an augmented version of the guile binary. So it creates a new binary that behaves like the guile binary, but has extra code compiled in.


This is what most examples do: they create a custom augmented binary that includes the code to be wrapped. To run the example, this augmented binary should be invoked with the runtime script as an argument. For example in the constants example, an executable my-guile is built and the example is run by invoking:

./my-guile -s constants.scm

The name of the executable is usually defined in the Makefile.


Contrast to this the test suite runtime scripts: these scripts are invoked with the standard guile command, to the wrapped code is not immediatly available. This means it becomes the script's responsability to load the wrapped code. For this the test suite runtime scripts almost always start with a call similar to:

(dynamic-call "scm_init_casts_module" (dynamic-link "./libcasts.so"))


So much for the theory.


The multimap example is an exception to the above. It is set up to use the test suite mechanism of running. Unfortunately there was also a bug in the runtime script that resulted in a runtime error. I have fixed this now, and adapted the Makefiles slightly to run the example automatically when making it.


If you want all the examples to work the same way that is certainly possible. I'm just not sure what the best strategy is (augmenting the guile binary or loading the wrapped code at runtime). And it may also be nice to demonstrate both forms for interested users.