Quick start guide

Once installed, AmOS can be loaded into your Lisp environment by means of ASDF:

(asdf:operate 'asdf:load-op 'amos)

Sample programs are available in the demo directory.

A dynamically adaptable Hello World

The following “hello world” application demonstrates basic features of AmOS. This example takes context information into account to modify the greeting given by the application.

It is handy to define have the current package use amos-cl so that basic AmOS constructs such as `defcontext’ are visible. The starting point is thus a package definition:

(in-package #:cl-user)
(defpackage #:hello-world (:use #:amos-cl))
(in-package #:hello-world)

Now we define the context that we will use in our application:

(defcontext @different-greeting)

The line above defines a prototypical context object called @different-greeting. By convention, prototype names are prefixed with the @ symbol in AmOS.

Methods are defined as follows:

(defmethod say-hello ()
   (format t "Hello World!~%"))

Method invocation resembles plain function calls (as in CLOS):

(say-hello) --> "Hello World!"

Now we want to change the greeting for certain special cases. We can do this by re-implementing the say-hello method in the context of @different-greeting.

(with-contexts (@different-greeting)
   (defmethod say-hello ()
      (format t "This is a different Hello World!")))

This new version will be available only when the @different-greeting context is active. The with-contexts construct receives in its first argument the list of contexts to be activated.

In order to dynamically activate and deactivate contexts at run time, AmOS provides the following methods:

(activate-context @context)
(deactivate-context @context)

We can try now invoking say-hello with different activations of @different-greeting:

(say-hello) --> "Hello World!"
(activate-context @different-greeting)
(say-hello) --> "This is a different Hello World!"
(deactivate-context @different-greeting)
(say-hello) --> "Hello World!"

This minimalistic example can be found in the distribution of AmOS.