[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] REPL

On Fri, Nov 16, 2012 at 4:18 PM, Helmut Eller <eller.helmut@x> wrote:

So how are we going to make (example life) available?  The only way I
know is to exit from Chibi Scheme, create a directory example/, move
life.scm to example/life.sld, restart Chibi with extra command line

Chibi's module system is based on Scheme48.  It supports
pre-defined modules, modules inferred from file lookups, and
direct manipulation of the (meta) module (which in Scheme48
is called config).  There's a shortcut to do this from the extended
repl provided by (chibi repl):

> @meta (define-library (math) (export pi) (import (scheme base)) (begin (define pi 3.14)))
> (import (math))
> pi

OK, that was easy.  But how do we run the modified program?  Redefinition
of the 'life function, as you suggested, is not an option as the
life-print function is not even exported.

Again, Chibi provides many ways to do this.  Probably the
most appropriate here is the (chibi reload) module:

> (import (chibi reload))
> (reload-modified-modules)

From the (chibi repl) you could enter the (example life) module
and edit it interactively:

> @in (example life)
(example life)> (define life-print ...)
(example life)> @in

Alternately you can use the module introspection from the
(chibi modules) library which is how (chibi repl) does its work.

These extensions are more powerful than simply mutating
imported bindings.  Moreover, they preserve abstraction.
It is possible in Chibi to use modules as a security mechanism,
to run untrusted code, controlling exactly which bindings
are available and not allowing the code to affect other parts
of the system.


Scheme-reports mailing list