Guile State Machine Compiler Reference Manual

For Guile-SMC 0.6.2

Artyom V. Poptsov

This manual documents Guile-SMC version 0.6.2.

Copyright (C) 2021 Artyom V. Poptsov poptsov.artyom@gmail.com

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License.”


[ < ] [ > ]   [Contents] [Index] [ ? ]

The Guile-SMC Reference Manual

This manual documents Guile-SMC version 0.6.2.

Copyright (C) 2021 Artyom V. Poptsov poptsov.artyom@gmail.com

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License.”



[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1 Introduction

Guile-SMC is a state machine compiler for GNU Guile.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2 Installation

Guile-SMC sources are available from GitHub at https://github.com/artyom-poptsov/guile-smc/. This section describes requirements of Guile-SMC and installation process.

Guile-SMC depends on the following packages:

Get the sources of Guile-Deck from GitHub using Git (a good introduction to Git is Pro Git book, which is available online):

$ git clone git@github.com:artyom-poptsov/guile-smc.git

Configure the sources:

$ cd guile-smc/
$ autoreconf -vif
$ ./configure

Build and install the library:

$ make
$ make install

For a basic explanation of the installation of the package, see the ‘INSTALL’ file.

important You probably want to call configure with the ‘--with-guilesitedir’ option so that this package is installed in Guile’s default path. But, if you don’t know where your Guile site directory is, run configure without the option, and it will give you a suggestion.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3 API Reference


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 FSM


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.1 The main class

Class: <fsm> [#:description=#f] [#:debug-mode?=#f] [#:transition-table='()] [#:event-source=(labmda (context) #t)] [#:current-state=#f]

The main class that describes a finite state machine.

#:current-state (state <state>)

required Current FSM state.

#:description (str <string>)

Optional custom human-readable description for the finite-state machine.

#:debug-mode? (enabled? <boolean>)

Is the debug mode enabled?

#:transition-table (table <hash-table>)

A transition table.

#:event-source (proc <procedure>)

Global state machine event source. The event source is a procedure that accepts a context and returns a next event.

The default value of this parameter is a procedure that always returns #t.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.2 Public API

Scheme Procedure: fsm? (object <top>)

Check if an object is an instance of <fsm> class.

Scheme Procedure: fsm-description (fsm <fsm>)

Get the fsm description.

Scheme Procedure: fsm-description-set! (fsm <fsm>) (description <string>)

Set the fsm description.

Scheme Procedure: fsm-debug-mode? (fsm <fsm>)

Check if the debug mode is enabled for fsm.

Scheme Procedure: fsm-debug-mode-set! (fsm <fsm>) (value <boolean>)

Set the debug mode state for fsm.

Scheme Procedure: fsm-transition-table (fsm <fsm>)

Get the fsm transition table.

Scheme Procedure: fsm-transition-table-set! (fsm <fsm>) (table <hash-table>)

Set the fsm transition hash table.

Scheme Procedure: fsm-event-source (fsm <fsm>)

Get the fsm event source procedure.

Scheme Procedure: fsm-event-source-set! (fsm <fsm>) (proc <procedure>)

Set the fsm event source procedure.

Scheme Procedure: fsm-current-state (fsm <fsm>)

Get the fsm current state.

Scheme Procedure: fsm-current-state-set! (fsm <fsm>) (state <state>)

Set the fsm current state.

Scheme Procedure: fsm-step-counter (fsm <fsm>)

Get the fsm step counter value.

Scheme Procedure: fsm-step-counter-set! (fsm <fsm>) (value <number>)

Set the fsm step counter value.

Scheme Procedure: fsm-transition-counter (fsm <fsm>)

Get the fsm transition counter value.

Scheme Procedure: fsm-transition-counter-set! (fsm <fsm>) (value <number>)

Set the fsm transition counter value.

Scheme Procedure: fsm-parent-fsm (fsm <fsm>)

Get the fsm parent FSM.

Scheme Procedure: fsm-parent-fsm-set! (fsm <fsm>) (value <fsm>)

Set the fsm parent FSM.

Scheme Procedure: fsm-parent-context (fsm <fsm>)

Get the fsm parent FSM context.

Scheme Procedure: fsm-parent-context-set! (fsm <fsm>) (value <top>)

Set the fsm parent FSM context.

Scheme Procedure: fsm-state-add! (fsm <fsm>) (state <state>)

Add a new state to the fsm state table.

Scheme Procedure: fsm-state (fsm <fsm>) (name <symbol>)

Lookup a state by its name from the state table of fsm.

Scheme Procedure: transition-list->hash-table (fsm <fsm>) (transition-list <list>)

Convert a transition-list to a hash table.

Scheme Procedure: hash-table->transition-list table

Convert a hash table to a transition list of the following form:

lisp
   '(((name        . state1)
      (description . "description")
      (transitions . ((guard-procedure      action-procedure      next-state)
                      (guard-procedure      action-procedure      next-state)
                      ...
                      (guard-procedure      action-procedure      next-state))))
     (state1 ...))

Return the transition list.

Scheme Procedure: fsm-transition-add! (self <fsm>) (state-name <symbol>) (tguard <procedure>) (action <procedure>) (next-state-name <top>)

Add a new transition to a state named next-state-name, guarded by a tguard with the specified transition action.

next-state-mame must be a name of a state that is already present in the FSM transition table, or #f (which means that the transition is final.)

Scheme Procedure: fsm-state-description-add! (self <fsm>) (state-name <symbol>) (description <string>)

Add a new description to a state state-name.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.2.1 Executing a FSM

Scheme Procedure: fsm-step! (fsm <fsm>) event context
Scheme Procedure: fsm-step! (fsm <fsm>) context

Perform a single fsm step on the specified event and a context.

If event parameter is missing, then fsm will always use event sources specific for each state during the execution.

Returns two values: new state and new context.

Scheme Procedure: fsm-run! (fsm <fsm>) event-source context
Scheme Procedure: fsm-run! (fsm <fsm>) context

Run an fsm with the given context return the new context.

event-source must be a procedure that accepts a context as a single parameter.

If event-source parameter is missing, then then fsm will always use event sources specific for each state during the execution.

context can be any Scheme object.

Return the context after fsm execution.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.2.2 Getting information about an FSM

Scheme Procedure: fsm-state-count (fsm <fsm>)

Calculate the number of states in a finite state machine fsm. Return the number of states.

Scheme Procedure: fsm-transition-count (self <fsm>)

Calculate the total transition count for a finite state machine fsm. Return the number of transitions.

Scheme Procedure: fsm-incoming-transition-count self state [#:include-recurrent-links?=#f]

Calculate the incoming transition count for a state. Optionally the procedure can include recurrent links of a state to itself in the calculation if include-recurrent-links? is set to #t.

Scheme Procedure: fsm-state-reachable? (fsm <fsm>) (state <state>)

Check if a state is reachable in the finite state machine fsm.

Scheme Procedure: fsm-validate (fsm <fsm>)

Validate the finite state machine fsm and return the list of errors. If the list is empty then no errors were found.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.2.3 Logging

Scheme Procedure: fsm-log-transition (from <state>) (to <state>)
Scheme Procedure: fsm-log-transition (from <state>) (to <symbol>)
Scheme Procedure: fsm-log-transition (from <state>) (to <boolean>)

Log state transitions.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 PlantUML

The (smc puml) module contains a parser implementation for PlantUML format.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.1 Public API

Scheme Procedure: puml->fsm port [#:module=(current-module)] [#:keep-going?=#f] [#:debug-mode?=#f]

Read a FSM description from a port in the PlantUML format and convert it to Guile-SMC <fsm> instance.

Scheme Procedure: puml-string->fsm port [#:module=(current-module)] [#:keep-going?=#f] [#:debug-mode?=#f]

Convert a string in the PlantUML format and to Guile-SMC <fsm> instance.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.2 The PlantUML context

Class: <puml-context> #:module [#:keep-going?=#f]
#:module

A module which contains state machine procedures.

#:keep-going? (value <boolean>)

Whether the parser should keep going when a procedure cannot be resolved or not.

When set to #t, the parser remembers all unresolved procedures but keeps going without issuing an error. All unresolved procedures are replaced with default variants (guard:t for guards, action:no-op for actions.)

Scheme Procedure: puml-context-fsm (context <puml-context>)

Get the context output finite state machine.

Scheme Procedure: puml-context-fsm-set! (context <puml-context>) (fsm <fsm>)

Set the context output finite state machine.

Scheme Procedure: puml-context-module (context <puml-context>)

Get the context module.

Scheme Procedure: puml-context-keep-going? (context <puml-context>)

Check if “keep going” option is enabled for an PlantUML context.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.2.1 FSM Guards and Actions

Scheme Procedure: title? ctx ch

Check if PlantUML diagram title is found.

Scheme Procedure: add-description ctx ch

Add FSM description.

Scheme Procedure: add-state-transition ctx ch

Add FSM state transition.

Scheme Procedure: process-state-description ctx ch
Scheme Procedure: validate-start-tag ctx ch
Scheme Procedure: validate-end-tag ctx ch

Validate start/end tags in a PlantUML data.

Scheme Procedure: throw-no-start-tag-error ctx ch
Scheme Procedure: throw-unexpected-end-of-file-error ctx ch

PlantUML parser context error reporting.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.2.2 Resolver status

Scheme Procedure: puml-context-resolved-procedures (puml-context <puml-context>)

Return a <set> of resolved procedures. Each element of the set is a pair, where car of the pair is a module from which a procedure is resolved, and cdr is a resolved procedure.

Scheme Procedure: puml-context-unresolved-procedures (puml-context <puml-context>)

Return a <set> of unresolved procedures. Each element of the set an unresolved procedure name.

Scheme Procedure: puml-context-print-resolver-status (puml-context <puml-context>) (port <port>)

Pretty-print a puml-context resolver status to the specified port.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.3 Internal procedures

Scheme Procedure: puml-error ctx message
Scheme Procedure: puml-error ctx message . args

Throw an PlantUML error.

Scheme Procedure: resolve-procedure context proc-name default

This procedure tries to resolve a procedure proc-name in the provided modules of a context. When no procedure available with the given name, returns default procedure.

Scheme Procedure: module-name module

Get the name of a module.

Scheme Procedure: parse-event-source (line <string>)

Try to parse a line as an event source definition. Returns a match or #f if line does not match.

Example event source definition:

event-source: some-event-source
Scheme Procedure: parse-entry-action (line <string>)

Try to parse a line as an entry action definition. Returns a match or #f if line does not match.

Example entry action definition:

entry-action: some-entry-action
Scheme Procedure: parse-exit-action (line <string>)

Try to parse a line as an exit action definition. Returns a match or #f if line does not match.

Example exit action definition:

exit-action: some-exit-action

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 Compiler

The Guile-SMC finite state machines generated from a PlantUML format can be used for their purpose “as is”. But it can be costly to read a PlantUML FSM (Finite-State Machine) description each time a program run.

To solve this problem Guile-SMC provides a compiler that can translate the internal representation of a state machine into a Scheme code.

The procedures below are defined in (smc compiler) module.

Scheme Procedure: fsm-compile fsm [#:fsm-name='custom-fsm] [#:fsm-module=#f] [#:extra-modules='()] [#:target='guile] [#:output-port=(current-output-port)]

Compile a fsm into a Scheme module.

Named parameters:

#:fsm-name (name <symbol>)

Set the name for the output finite state machine. Basically the name turns to the FSM class (like <custom-fsm> for the default value.)

#:fsm-module (module <list>)
#:fsm-module (module <boolean>)

The module to place the output FSM into. The value must be a list like (my-parser my-fsm) or #f if the define-module part should be omitted.

#:extra-modules (modules-list <list>)

A list of extra modules that required to run the output FSM. These modules are added to to the output FSM module requirements.

#:output-port (port <port>)

The port to write the output FSM to.

#:target (value <symbol>)

The compilation target. Allowed values are:

guile

This is the default mode. The output FSM will depend on Guile-SMC and won’t work if it is not installed on a target system.

guile-standalone

This target allows to create a single file FSM that does not depend on Guile-SMC in any way.

The compiler collects the required code from Guile-SMC and then removes all unused parts from it, then the code is being printed to a output-port.

Usage example:

(fsm-compile (puml->fsm (current-input-port)
                        #:module (puml-modules '((context))))
             #:fsm-name      'custom-fsm
             #:fsm-module    '(custom-fsm)
             #:extra-modules '((context)))

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.1 Common Guile Compiler Code

(smc compiler guile-common) module contains the common code for the Guile FSM compiler.

Scheme Procedure: form-feed port

Write a form feed symbol with the following newline to a port.

Scheme Procedure: write-header port

Write a header commentary to a port.

Scheme Procedure: write-section-header description port

Write a section to a port.

Scheme Procedure: write-footer file-name port

Write a file footer to a port.

Scheme Procedure: write-parent-fsm-info (fsm <fsm>) (port <port>)

Print the information about the parent FSM for a fsm to a port.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.2 Guile

(smc compiler guile) module contains the code for “guile” compiler target.

Scheme Procedure: write-module module [#:extra-modules] [#:class-name] [#:port] [#:standalone-mode=#f]

Write a define-module part to a port. class-name is used to export a FSM class in the #:export part. extra-modules allow to specify a list of extra modules that required for the output FSM to work.

Scheme Procedure: write-use-modules extra-modules port

Write use-modules section to the port.

Scheme Procedure: write-transition-table (fsm <fsm>) (port <port>)

Write a fsm transition table to a port.

Scheme Procedure: write-define-class class-name port

Write define-class for a class-name to a port.

Scheme Procedure: write-initialize fsm class-name port

Write the class constructor for class-name to the port.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.3 Guile Standalone

(smc compiler guile-standalone) module contains the code for “guile-standalone” target.

Scheme Procedure: state->standalone-code (fsm <fsm>) (state <list>)

Convert a state to a plain Scheme define that does not depend on Guile-SMC.

Scheme Procedure: fsm-transition-table->standalone-code (fsm <fsm>)

Convert a fsm transition table to a list of Scheme procedures that do not depend on Guile-SMC.

Scheme Procedure: string-drop-both str

Drop one symbol from both left and right parts of a string str

Scheme Procedure: fsm-define-module fsm fsm-name module [#:extra-modules]

Generate a define-module code for an fsm.

Scheme Procedure: tree-contains? root element

Check if a root contains an element.

Scheme Procedure: prune-unused-definitions definitions hardwired-definitions

Remove all the definitions from the definitions list that are not used neither in the definitions nor hardwired-definitions lists.

Scheme Procedure: fsm-get-context-code guile-smc-modules-path [#:type=#f] [#:skip-define-module?=#t]

Read the Guile-SCM context from the guile-smc-modules-path and return the code as a list.

Scheme Procedure: fsm-get-class-code fsm-name

Generate class code for an fsm-name.

Scheme Procedure: fsm->standalone-code (fsm <fsm>) fsm-name

Convert an fsm to a procedure that does not depend on Guile-SMC.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.4 Examples

For more examples, take a look into ‘examples/compiler’ directory in the project repository.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 Version

(smc version) contains procedures that allow to acquire information about the Guile-SMC version in the Semantic Versioning format.

Guile-SMC version consists of three parts: MAJOR.MINOR.PATCH

The procedures below allow to get any of the version part or the version as a whole.

Scheme Procedure: smc-version

Return the Guile-SMC version as a list of the following form:

lisp
'(MAJOR MINOR PATCH)
Scheme Procedure: smc-version/string

Get the raw Guile-SMC version as a string.

Scheme Procedure: smc-version/major

Get the “MAJOR” part of the Guile-SMC version.

Scheme Procedure: smc-version/minor

Get the “MINOR” part of the Guile-SMC version.

Scheme Procedure: smc-version/patch

Get the “PATCH” part of the Guile-SMC version.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5 Log

(smc core log) module contains Guile-SMC logging facilities.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.1 The Precise Logger

Class: <precise-logger>

Guile-SMC precise logger that prints log with microsecond accuracy.

Scheme Procedure: precise-logger? x

Check if x is a <precise-logger> instance.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.2 Log Drivers

Guile-SMC allows to set different log drivers (or handlers). It uses <system-log> by default.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.2.1 System Log

Class: <system-log>

This is a log handler which writes logs to the syslog.

Scheme Procedure: system-log? x

Check if x is a <system-log> instance.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.2.2 Precise Port Log

Class: <precise-port-log>

Microsecond version of <port-log> from (logging port-log).


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.2.3 Standard Error Log

Class: <stderr-log>

Log driver that logs to the standard error port.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.2.4 Null Log

Class: <null-log>

Log driver that logs to the standard error port.

Scheme Procedure: null-log? x

Check if x is a <null-log> instance.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.3 Logging Initialization and Configuration

Scheme Procedure: smc-log-init! (log-driver <string>) (log-options <list>)

Initialize Guile-SMC logging to the specified log-driver with log-options list.

Known log drivers:

Return value is undefined.

Scheme Procedure: log-use-stderr! (value <boolean>)

Change whether the logger must print messages to the stderr as well as to syslog, or not.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.4 Helper Procedures

Scheme Procedure: %precise-log-formatter lvl time str

The precise log formatter for <precise-logger>.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5.5 Logging Procedures

Scheme Procedure: smc-log level fmt . args
Scheme Procedure: log-error fmt . args
Scheme Procedure: log-warning fmt . args
Scheme Procedure: log-info fmt . args
Scheme Procedure: log-debug fmt . args

Log a formatted message of a specified logging level to syslog.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6 State

The (smc core state) module contains FSM state implementation. The state term is very important in the realm of finite-state machines as the FSMs consist of states and transitions between them.

A state can take one of two forms: it can be either a associative list or an instance of <state> class. There are converters between these forms.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.1 Actions

Basically an action is a procedure that is called when some event happen.

The main Guile-SMC allow to attach actions to transitions as well as to the state entry/exit events.

Note that a state does not run its entry/exit actions when state-run method is called because it has insufficient information about when to call entry/exit action procedures. Those procedures are run by a FSM that owns the state.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.2 Default entry/exit actions

Scheme Procedure: %default-entry-action context

Default state entry action that just returns a context.

Scheme Procedure: %default-exit-action context

Default state exit action that just returns a context.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.3 The main class

Class: <state> #:name [#:description=#f] [#:event-source=#f] [#:entry-action=%default-entry-action] [#:exit-action=%default-exit-action] [#:transitions=#f]

This class describes an FSM state.

Constructor parameters:

#:name (name <string>)

required Name of this state.

#:description (description <string>)

Description of this state.

#:event-source (proc <procedure>)

A procedure that returns an event.

It called by the FSM the state belongs to as follows:

lisp
(proc context)
#:entry-action (proc <procedure>)

A procedure that is called by the FSM the state belongs to when a transition occurs to this state from another state, before running the transition table. Note that the procedure is not called on self-transitions.

The procedure MUST return a context, which is passed to the transition table execution.

The procedure called as follows:

lisp
(proc context)
#:exit-action (proc <procedure>)

A procedure that is called by the FSM the state belongs to when a transition occurs from this state to another state, before running the transition table. Note that the procedure is not called on self-transitions.

The procedure MUST return a context.

The procedure called as follows:

lisp
(proc context)
#:transitions (transitions <list>)

The transitions for this state.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.4 Public API

Scheme Procedure: state? object

Check if object is an instance of the <state> class.

Scheme Procedure: equal? state-1 state-2

Check if state-1 is equal to state-2.

Scheme Procedure: state-name (state <state>)

Get the state name as a <string>.

Scheme Procedure: state-name (state <symbol>)

Special version of procedure that return the symbol itself.

Scheme Procedure: state-has-event-source? (state <state>)

Check if a state has an event source.

Scheme Procedure: state-description (state <state>)

Get the state description as a <string> if it is available, return #f otherwise.

Scheme Procedure: state-event-source (state <state>)

Get the state event source procedure.

Scheme Procedure: state-event-source-set! (state <state>)

Set the state event source procedure.

Scheme Procedure: state-entry-action (state <state>)

Get the state entry action procedure.

Scheme Procedure: state-entry-action-set! (state <state>)

Set the state entry action procedure.

Scheme Procedure: state-exit-action (state <state>)

Get the state exit action procedure.

Scheme Procedure: state-exit-action-set! (state <state>)

Set the state exit action procedure.

Scheme Procedure: state-transitions (state <state>)

Get the state transitions as a list.

Scheme Procedure: state-transition-add! (state <state>) (tguard <procedure>) (action <procedure>) next-state

Add a new transition to the state.

A transition consists of a transition guard tguard (which must be a predicate) and a transition action.

Scheme Procedure: state-transition-count (state <state>)
Scheme Procedure: state-transition-count (state <state>) to

Get the transitions count for a state.

Scheme Procedure: state-transition-count/foreign (state <state>)

Get the foreign transitions count for a state. A foreign transition is a transition that points to another state.

Scheme Procedure: state-recurrent-links-count (state <state>)

Get the number of recurrent links (that is, links that point to the state itself) for a state.

Scheme Procedure: state-has-recurrent-links? (state <state>)

Check if a state has recurrent links.

Scheme Procedure: state-final-transitions (state <state>)

Get the number of final transitions for a state.

Scheme Procedure: state-has-final-transitions? (state <state>)

Check if a state has any final transitions.

Scheme Procedure: state-dead-end? (state <state>)

Check if a state is a dead-end state. A state is considered a dead-end if it has no foreign transitions, has recurrent links and has no final transitions.

Scheme Procedure: state-run (state <state>) event context

Run a state. Returns two values: next state (or #f) and new context.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.4.1 State as a list

State serialized to an associative list of the following form:

lisp
   `((name         . state-name)
     (description  . "State description")
     (event-source . ,event-source:state-name)
     (entry-action . ,some-entry-action)
     (transitions
      (,guard:...    ,action:...    next-state-name-1)
      (,guard:...    ,action:...    next-state-name-1)
      (,guard:...    ,action:...    next-state-name-2)))
Scheme Procedure: state:name state
Scheme Procedure: state:description state
Scheme Procedure: state:transitions state
Scheme Procedure: state:event-source state
Scheme Procedure: state:entry-action state
Scheme Procedure: state:exit-action state

Get the corresponding element of a state alist.

Scheme Procedure: state:event-source/name state

Get the name of a state event source procedure. Returns #f when no event source is set.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.4.2 List/state conversion

Scheme Procedure: list->state (lst <list>)

Convert a list lst to a <state> instance, return the new state.

Scheme Procedure: state->list (state <state>)

Convert a state to an associative list.

Scheme Procedure: state->list/serialized (state <state>)

Convert a state to an associative list, replace all the procedures with their names.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7 Transition

The (smc core transition) module contains the implementation of FSM transition class.

In the realm of finite-state machines a transition is a set of actions to be executed when a condition is fulfilled or when an event is received.

A Guile-SMC transition instance contains a transition guard that allows the transition to happen. When the guard returns #t (that is, when the transition condition specified by the guard is fulfilled) a transition action is performed.

Each Guile-SMC transition has single next state that points to the next state to which transition switches the parent finite-state machine.

A single transition take the following form:

lisp
(list guard:some-guard action:some-action 'state1)

The first part of the transition in the example is guard:some-guard that represent a Guile-SMC guard procedure.

The second part is action:some-action – the transition action that is performed when the guard returns #t.

The third part is 'state-1 – the next state to which the transition will switch the parent FSM.

Note that the next state can be either a state name (as a Guile symbol) or a reference to a <state> instance.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7.1 Transition Accessors

A Guile-SMC transition content can be conveniently accessed by means of the following procedures.

Scheme Procedure: transition:guard (transition <list>)

Get the transition guard procedure.

Scheme Procedure: transition:action (transition <list>)

Get the transition action procedure.

Scheme Procedure: transition:next-state (transition <list>)

Get the transition next state.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7.2 Transition Table

Guile-SMC transitions are grouped into transition tables. Let’s take a look at the following example:

lisp
(list (list guard:some-guard action:action-1 'state1)
      (list guard:#t         action:action-2 'state2))

This transition table consists of two possible transitions: to state-1 and to state-2. In the closer look this form resembles classic state-transition tables:

current state | input            | output (action) | next state
--------------+------------------+-----------------+-------------------
state-2       | guard:some-guard | action:action-1 | state-1
state-2       | guard:#t         | action:action-2 | state-2

In the above example of Guile-SMC transition table there’s no “current state” as a <state> instance holds its transition table so there’s no need to store the current state in the transition table itself.

Scheme Procedure: transition-table-count (predicate <procedure>) (tlist <list>)

Return number of the elements in the tlist transition table for which predicate returns #t.

predicate is called on each transition.

To get the total number of transitions in a transition table pass (const #t) procedure as predicate:

lisp
(transition-table-count (const #t) some-transition-table)
Scheme Procedure: transition-table-run (tlist <list>) event context

Run a tlist transition table on the specified event and a context, return two values: the next state and a new context.

If no guards returned #t the procedure returns #f as the next state.

Scheme Procedure: transition-table-append (tlist <list>) @

(tguard <procedure>) @ (action <procedure>) @ next-state)

Append a new transition to the end of a tlist transition table. Return a new transition table with the new transition.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8 Context

(smc context) contains the implementation of contexts that can be used to provide required FSM guards, actions, event sources and some data structures.

In a broad sense a context is an aggregate of an FSM memory that is passed between each state, guards, actions and all the auxiliary procedures that are required for the FSM machinery to work.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8.1 Guards

A guard is a predicate that takes a context and an event and returns #t or #f.

Each transition path in a FSM is guarded by a guard, when a guard returns #t the FSM transitions to the next state guarded by the guard and a transition action is performed.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8.2 Actions

An action can be attached to a state transition (thus producing a transition action) or to a state itself (in the form of either entry action or exit action.)

A transition action is performed when its transition guard returns #t.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8.3 Pre-defined Guards

Note that Guile-SMC can use any Scheme object as the context memory for a finite-state machine. The pre-defined guards and actions do not depend on any specific context memory type.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8.3.1 “common”

Scheme Procedure: guard:#t context event

This is “default” guard that just always returns #t.

Scheme Procedure: action:no-op context event

This is “no operation” action that just returns the context as is.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8.3.2 “char”

(smc context char) module provides guards for working with characters. There are lots of predicates such as char:left-parenthesis?, char:right-parenthesis?, char:single-quote? etc.

Please see the module source code for the full list of predicates.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8.3.3 “u8”

(smc context u8) module provides guards for working with bytes. It contains the same predicates as (smc context char) but the predicates are accepting numbers instead of characters.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9 Context Memory

Some problems are hard to solve (or cannot be solved at all) by an FSM that stores only its state. Thus, some kind of memory is required to approach such tasks.

A stack is often used in such cases but naturally there are cases where several kinds of memory is required.

Although a context memory can be represented by any data type that Scheme supports, Guile-SMC context memory provides pre-defined means for FSMs to store a complex state.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.1 General Concepts

Guile-SMC context memory has three pre-defined stacks:


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.2 Functional Memory


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.2.1 generic

See the (smc context functional generic) module.

Structure: <context> debug-mode? counter buffer stanza result custom-data

Structure fields:

debug-mode?

Flag that specifies whether the debug mode for the context is enabled.

counter

Context counter. Can be used to count incoming events, for example.

buffer

Context buffer to store intermediate values.

stanza

Context stanza to store the chunks of intermediate context data.

result

Context result to store the end result of the parser.

custom-data

Context custom data that can be used by the custom contexts to store different things such as ports or some data structures.

Scheme Procedure: make-context [#:debug-mode?=#f] [#:counter=0] [#:buffer='()] [#:stanza='()] [#:result='()] [#:custom-data='()]

The <context> constructor.

Scheme Procedure: context-buffer/reversed context

Return the reversed context buffer.

Scheme Procedure: context-stanza/reversed context

Return the reversed context stanza.

Scheme Procedure: context-result/reversed context

Return the reversed context result.

Scheme Procedure: context-counter-update context [delta=1]

Increment the context counter by delta value. Return the updated context.

Scheme Procedure: clear-buffer context [event]
Scheme Procedure: clear-stanza context [event]
Scheme Procedure: clear-result context [event]
Scheme Procedure: update-counter context [event]
Scheme Procedure: reverse-buffer context [event]
Scheme Procedure: reverse-stanza context [event]
Scheme Procedure: reverse-result context [event]
Scheme Procedure: push-event-to-buffer context event
Scheme Procedure: push-event-to-stanza context event
Scheme Procedure: push-event-to-result context event

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.2.2 char

(smc context functional char) module provides a memory for FSMs that read and parse a stream of characters.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.2.3 u8

(smc context functional u8) module provides a memory for FSMs that read and parse a stream of bytes.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.3 OOP

(smc context oop) modules provide a memory for FSMs that is written in GOOPS style.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4 Command-Line Interface

Guile-SMC has a CLI (Command-Line Interface) that provides access to its features. It is built upon (smc cli) module that contains API (Application Programming Interface) for the tool.

The CLI tool is called simply ‘smc’. Please see smc --help output or man smc for usage information.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 The Compiler

The state machine compiler allows to compile state machines from a formal description (currently only PlantUML format is supported.)

The compiler can be invoked by smc compile command.

You can get the actual help message for smc compile by passing it the --help option.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1.1 Compilation Targets

A Guile-SMC compilation target changes the compiler behavior so it produces the code in different form.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1.1.1 guile target

The default compilation target. The code produced by the compiler for this target is dependent on the Guile-SMC.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1.1.2 guile-standalone target

This compilation target produces GNU Guile FSM code in a single file that does not dependent on Guile-SMC.

All required Guile-SMC procedures will be copied to the output stream, and the extra procedures that are not used in the output code are removed by pruning.

The output code is similar to hand-crafted recursive code that a Scheme programmer could write given the knowledge of automata-based programming.

Here’s an example of an output FSM (without the auxiliary code copied from Guile-SMC that normally goes before this procedure):

lisp
(define (run-fsm context)
  ""
  (define (DEFAULT context)
    "Count parenthesis."
    (let ((event (event-source context)))
      (cond ((guard:eof-object? context event)
             (let ((context (action:validate context event)))
               (log-debug "[~a] -> [*]" 'DEFAULT)
               context))
            ((guard:semicolon? context event)
             (let ((context (action:no-op context event)))
               (log-debug "[~a] -> [~a]" 'DEFAULT 'COMMENT)
               (COMMENT context)))
            ((guard:double-quote? context event)
             (let ((context (action:no-op context event)))
               (log-debug "[~a] -> [~a]" 'DEFAULT 'STRING)
               (STRING context)))
            ((#{guard:#t}# context event)
             (let ((context (action:count context event)))
               (DEFAULT context))))))
  (define (STRING context)
    "Skip a string."
    (let ((event (event-source context)))
      (cond ((guard:double-quote? context event)
             (let ((context (action:no-op context event)))
               (log-debug "[~a] -> [~a]" 'STRING 'DEFAULT)
               (DEFAULT context)))
            ((#{guard:#t}# context event)
             (let ((context (action:no-op context event)))
               (STRING context))))))
  (define (COMMENT context)
    "Skip a comment."
    (let ((event (event-source context)))
      (cond ((guard:newline? context event)
             (let ((context (action:no-op context event)))
               (log-debug "[~a] -> [~a]" 'COMMENT 'DEFAULT)
               (DEFAULT context)))
            ((#{guard:#t}# context event)
             (let ((context (action:no-op context event)))
               (COMMENT context))))))
  (DEFAULT context))

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 The Context Generator and Analyzer

smc context command allows to generate and analyze Guile-SMC FSM contexts.

There are two modes of context generation: the command either can generate a custom context stub based on an input PlantUML state machine description, or generate a standalone (or intermediate) context that can be used by custom contexts to relax the dependency on Guile-SMC modules

When --resolve option is provided the command prints to the standard output the list of resolved and unresolved procedures based on the input PlantUML file.

Supported options:

--help, -h

Print the help message and exit.

--resolve, -r

Print the resolver status.

--standalone, -s

Generate a standalone compiler context.

--type <type>, -T <type>

Set the context type for the output context.

Expected format: <type>[/<sub-type>]

For example: “functional/char”.

To get the full list of supported formats, see --help.

--generate, -g

Generate a context stub based on a provided state machine description in a PlantUML format.

--guile-smc-path <path>

Set the path where Guile-SMC modules are stored.

--module <module>, -m <module>

Place the output code into a specified module

--load-path <load-path>, -L <load-path>

Add an extra load path.

--log-driver <driver>

Set the log driver.

--log-opt <options>

Set the logging options. The set of options depends on the logging driver.

--debug

Enable the debug mode.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 The Profiler

The profiler allows to analyze state machines using its logs (traces) and thus provides facilities to detect bottlenecks in state machines in terms of running time.

Input data example:

2023-04-22 23:00:09.032625 (DEBUG): [*] -> [read]
2023-04-22 23:00:09.032748 (DEBUG): [read] -> [read_section_title]
2023-04-22 23:00:09.033559 (DEBUG): [read_section_title] -> [read_section_content]
2023-04-22 23:00:09.033613 (DEBUG): [read_section_content] -> [read_section_property_key]
2023-04-22 23:00:09.033675 (DEBUG): [read_section_property_key] -> [trim_section_property_key]
2023-04-22 23:00:09.033717 (DEBUG): [trim_section_property_key] -> [trim_section_property_value]
2023-04-22 23:00:09.033754 (DEBUG): [trim_section_property_value] -> [read_section_property_value]
2023-04-22 23:00:09.033811 (DEBUG): [read_section_property_value] -> [read_section_content]
2023-04-22 23:00:09.033840 (DEBUG): [read_section_content] -> [read_section_property_key]
2023-04-22 23:00:09.033922 (DEBUG): [read_section_property_key] -> [trim_section_property_key]
2023-04-22 23:00:09.034378 (DEBUG): [trim_section_property_key] -> [trim_section_property_value]
2023-04-22 23:00:09.034415 (DEBUG): [trim_section_property_value] -> [read_section_property_value]
2023-04-22 23:00:09.034450 (DEBUG): [read_section_property_value] -> [read_section_content]
2023-04-22 23:00:09.034478 (DEBUG): [read_section_content] -> [read_section_property_key]
2023-04-22 23:00:09.034522 (DEBUG): [read_section_property_key] -> [trim_section_property_key]
2023-04-22 23:00:09.034547 (DEBUG): [trim_section_property_key] -> [trim_section_property_value]
2023-04-22 23:00:09.034574 (DEBUG): [trim_section_property_value] -> [read_section_property_value]
2023-04-22 23:00:09.034661 (DEBUG): [read_section_property_value] -> [read_section_content]
2023-04-22 23:00:09.034700 (DEBUG): [read_section_content] -> [read_section_property_key]
2023-04-22 23:00:09.034738 (DEBUG): [read_section_property_key] -> [trim_section_property_key]
2023-04-22 23:00:09.034765 (DEBUG): [trim_section_property_key] -> [trim_section_property_value]
2023-04-22 23:00:09.034790 (DEBUG): [trim_section_property_value] -> [read_section_property_value]
2023-04-22 23:00:09.034830 (DEBUG): [read_section_property_value] -> [read_section_content]
2023-04-22 23:00:09.034889 (DEBUG): [read_section_content] -> [*]

Usage example:

shell
$ smc profile fsm.log
Total transitions: 99
Total time:        14925 us
Stats:
  read: 3158 us (21.1591 %)
  read_state_transition_guard: 1663 us (11.1424 %)
  read_state_transition_to: 1483 us (9.9363 %)
  read_word: 1259 us (8.4355 %)
  read_state_description: 1014 us (6.7940 %)
  read_state_right_arrow: 839 us (5.6214 %)
  search_state_transition_to: 670 us (4.4891 %)
  search_state_transition: 638 us (4.2747 %)
  read_state_transition_action: 536 us (3.5913 %)
  read_start_tag: 535 us (3.5846 %)
  search_state_transition_guard: 428 us (2.8677 %)
  read_state: 178 us (1.1926 %)
  search_state_transition_action: 139 us (.9313 %)
  read_state_action_arrow: 139 us (.9313 %)
  search_state_action_arrow: 132 us (.8844 %)
  read_end_tag: 125 us (.8375 %)

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 The Finite State Machine Runner

The state machine runner allows to run a state in ad hoc fashion with the minimum amount of supporting code:

shell
$ smc run --help
Usage: smc run [options] <puml-file>

Run a state machine.

Options:
  --help, -h        Print this message and exit.
  --eval, -e <procedure>
                    Eval a procedure with the resulting context as a parameter.
                    Example value:
                      "(lambda (context) (display context))"
  --load-path, -L <load-path>
                    Add an extra load path.
  --context-thunk, -C <procedure>
                    A thunk that produces the initial value for an FSM context.
                    Example value: "(lambda () 0)"
  --modules, -U <modules>
                    Load additional modules.  The value must be the same
                    as for 'use-modules'.  Example value:
                      "((smc context char-context) (smc puml-context))"
  --validate        Validate the output FSM and print the validation result.
                    The exit code is 0 if the validation is passed,
                    and a non-zero value otherwise.
  --log-file <file> Log file to use.  Pass "-" as the file to use the standard
                    error stream (stderr.)
                    'smc run' logs to syslog by default.
  --debug           Enable the debug mode.

Usage example:

shell
$ smc run -L . -U "((context))" -C "(lambda () 0)" fsm.puml

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 Programming API


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.1 (smc cli command-compile)

Scheme Procedure: command-compile args

Handle smc compile command.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.2 (smc cli command-context)

Scheme Procedure: command-context args

Handle smc context command.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.3 (smc cli command-profile)

Scheme Procedure: command-profile args

Handle smc profile command.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.4 (smc cli command-run)

Scheme Procedure: command-run args

Handle smc run command.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Appendix A GNU Free Documentation License

Version 1.3, 3 November 2008

Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
http://fsf.org/

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
  1. PREAMBLE

    The purpose of this License is to make a manual, textbook, or other functional and useful document free in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

    This License is a kind of “copyleft”, which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

    We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.

  2. APPLICABILITY AND DEFINITIONS

    This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The “Document”, below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as “you”. You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law.

    A “Modified Version” of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

    A “Secondary Section” is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document’s overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

    The “Invariant Sections” are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none.

    The “Cover Texts” are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words.

    A “Transparent” copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not “Transparent” is called “Opaque”.

    Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only.

    The “Title Page” means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, “Title Page” means the text near the most prominent appearance of the work’s title, preceding the beginning of the body of the text.

    The “publisher” means any person or entity that distributes copies of the Document to the public.

    A section “Entitled XYZ” means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as “Acknowledgements”, “Dedications”, “Endorsements”, or “History”.) To “Preserve the Title” of such a section when you modify the Document means that it remains a section “Entitled XYZ” according to this definition.

    The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License.

  3. VERBATIM COPYING

    You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.

    You may also lend copies, under the same conditions stated above, and you may publicly display copies.

  4. COPYING IN QUANTITY

    If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document’s license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.

    If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

    If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

    It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

  5. MODIFICATIONS

    You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

    1. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.
    2. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement.
    3. State on the Title page the name of the publisher of the Modified Version, as the publisher.
    4. Preserve all the copyright notices of the Document.
    5. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.
    6. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.
    7. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document’s license notice.
    8. Include an unaltered copy of this License.
    9. Preserve the section Entitled “History”, Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled “History” in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.
    10. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the “History” section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.
    11. For any section Entitled “Acknowledgements” or “Dedications”, Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.
    12. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.
    13. Delete any section Entitled “Endorsements”. Such a section may not be included in the Modified Version.
    14. Do not retitle any existing section to be Entitled “Endorsements” or to conflict in title with any Invariant Section.
    15. Preserve any Warranty Disclaimers.

    If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version’s license notice. These titles must be distinct from any other section titles.

    You may add a section Entitled “Endorsements”, provided it contains nothing but endorsements of your Modified Version by various parties—for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

    You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

    The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.

  6. COMBINING DOCUMENTS

    You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers.

    The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

    In the combination, you must combine any sections Entitled “History” in the various original documents, forming one section Entitled “History”; likewise combine any sections Entitled “Acknowledgements”, and any sections Entitled “Dedications”. You must delete all sections Entitled “Endorsements.”

  7. COLLECTIONS OF DOCUMENTS

    You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

    You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

  8. AGGREGATION WITH INDEPENDENT WORKS

    A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an “aggregate” if the copyright resulting from the compilation is not used to limit the legal rights of the compilation’s users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document.

    If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document’s Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate.

  9. TRANSLATION

    Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail.

    If a section in the Document is Entitled “Acknowledgements”, “Dedications”, or “History”, the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.

  10. TERMINATION

    You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License.

    However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.

    Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.

    Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it.

  11. FUTURE REVISIONS OF THIS LICENSE

    The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.

    Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License “or any later version” applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy’s public statement of acceptance of a version permanently authorizes you to choose that version for the Document.

  12. RELICENSING

    “Massive Multiauthor Collaboration Site” (or “MMC Site”) means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A “Massive Multiauthor Collaboration” (or “MMC”) contained in the site means any set of copyrightable works thus published on the MMC site.

    “CC-BY-SA” means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization.

    “Incorporate” means to publish or republish a Document, in whole or in part, as part of another Document.

    An MMC is “eligible for relicensing” if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008.

    The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing.

ADDENDUM: How to use this License for your documents

To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:

  Copyright (C)  year  your name.
  Permission is granted to copy, distribute and/or modify this document
  under the terms of the GNU Free Documentation License, Version 1.3
  or any later version published by the Free Software Foundation;
  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  Texts.  A copy of the license is included in the section entitled ``GNU
  Free Documentation License''.

If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the “with…Texts.” line with this:

    with the Invariant Sections being list their titles, with
    the Front-Cover Texts being list, and with the Back-Cover Texts
    being list.

If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation.

If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Type Index

Jump to:   <
Index Entry  Section

<
<context> 3.9.2.1 generic
<fsm> 3.1.1 The main class
<null-log> 3.5.2.4 Null Log
<precise-logger> 3.5.1 The Precise Logger
<precise-port-log> 3.5.2.2 Precise Port Log
<puml-context> 3.2.2 The PlantUML context
<state> 3.6.3 The main class
<stderr-log> 3.5.2.3 Standard Error Log
<system-log> 3.5.2.1 System Log

Jump to:   <

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Procedure Index

Jump to:   %  
A   C   E   F   G   H   L   M   N   P   R   S   T   U   V   W  
Index Entry  Section

%
%default-entry-action 3.6.2 Default entry/exit actions
%default-exit-action 3.6.2 Default entry/exit actions
%precise-log-formatter 3.5.4 Helper Procedures

A
action:no-op 3.8.3.1 “common”
add-description 3.2.2.1 FSM Guards and Actions
add-state-transition 3.2.2.1 FSM Guards and Actions

C
clear-buffer 3.9.2.1 generic
clear-result 3.9.2.1 generic
clear-stanza 3.9.2.1 generic
command-compile 4.5.1 (smc cli command-compile)
command-context 4.5.2 (smc cli command-context)
command-profile 4.5.3 (smc cli command-profile)
command-run 4.5.4 (smc cli command-run)
context-buffer/reversed 3.9.2.1 generic
context-counter-update 3.9.2.1 generic
context-result/reversed 3.9.2.1 generic
context-stanza/reversed 3.9.2.1 generic

E
equal? 3.6.4 Public API

F
form-feed 3.3.1 Common Guile Compiler Code
fsm->standalone-code 3.3.3 Guile Standalone
fsm-compile 3.3 Compiler
fsm-current-state 3.1.2 Public API
fsm-current-state-set! 3.1.2 Public API
fsm-debug-mode-set! 3.1.2 Public API
fsm-debug-mode? 3.1.2 Public API
fsm-define-module 3.3.3 Guile Standalone
fsm-description 3.1.2 Public API
fsm-description-set! 3.1.2 Public API
fsm-event-source 3.1.2 Public API
fsm-event-source-set! 3.1.2 Public API
fsm-get-class-code 3.3.3 Guile Standalone
fsm-get-context-code 3.3.3 Guile Standalone
fsm-incoming-transition-count 3.1.2.2 Getting information about an FSM
fsm-log-transition 3.1.2.3 Logging
fsm-log-transition 3.1.2.3 Logging
fsm-log-transition 3.1.2.3 Logging
fsm-parent-context 3.1.2 Public API
fsm-parent-context-set! 3.1.2 Public API
fsm-parent-fsm 3.1.2 Public API
fsm-parent-fsm-set! 3.1.2 Public API
fsm-run! 3.1.2.1 Executing a FSM
fsm-run! 3.1.2.1 Executing a FSM
fsm-state 3.1.2 Public API
fsm-state-add! 3.1.2 Public API
fsm-state-count 3.1.2.2 Getting information about an FSM
fsm-state-description-add! 3.1.2 Public API
fsm-state-reachable? 3.1.2.2 Getting information about an FSM
fsm-step! 3.1.2.1 Executing a FSM
fsm-step! 3.1.2.1 Executing a FSM
fsm-step-counter 3.1.2 Public API
fsm-step-counter-set! 3.1.2 Public API
fsm-transition-add! 3.1.2 Public API
fsm-transition-count 3.1.2.2 Getting information about an FSM
fsm-transition-counter 3.1.2 Public API
fsm-transition-counter-set! 3.1.2 Public API
fsm-transition-table 3.1.2 Public API
fsm-transition-table->standalone-code 3.3.3 Guile Standalone
fsm-transition-table-set! 3.1.2 Public API
fsm-validate 3.1.2.2 Getting information about an FSM
fsm? 3.1.2 Public API

G
guard:#t 3.8.3.1 “common”

H
hash-table->transition-list 3.1.2 Public API

L
list->state 3.6.4.2 List/state conversion
log-debug 3.5.5 Logging Procedures
log-error 3.5.5 Logging Procedures
log-info 3.5.5 Logging Procedures
log-use-stderr! 3.5.3 Logging Initialization and Configuration
log-warning 3.5.5 Logging Procedures

M
make-context 3.9.2.1 generic
module-name 3.2.3 Internal procedures

N
null-log? 3.5.2.4 Null Log

P
parse-entry-action 3.2.3 Internal procedures
parse-event-source 3.2.3 Internal procedures
parse-exit-action 3.2.3 Internal procedures
precise-logger? 3.5.1 The Precise Logger
process-state-description 3.2.2.1 FSM Guards and Actions
prune-unused-definitions 3.3.3 Guile Standalone
puml->fsm 3.2.1 Public API
puml-context-fsm 3.2.2 The PlantUML context
puml-context-fsm-set! 3.2.2 The PlantUML context
puml-context-keep-going? 3.2.2 The PlantUML context
puml-context-module 3.2.2 The PlantUML context
puml-context-print-resolver-status 3.2.2.2 Resolver status
puml-context-resolved-procedures 3.2.2.2 Resolver status
puml-context-unresolved-procedures 3.2.2.2 Resolver status
puml-error 3.2.3 Internal procedures
puml-error 3.2.3 Internal procedures
puml-string->fsm 3.2.1 Public API
push-event-to-buffer 3.9.2.1 generic
push-event-to-result 3.9.2.1 generic
push-event-to-stanza 3.9.2.1 generic

R
resolve-procedure 3.2.3 Internal procedures
reverse-buffer 3.9.2.1 generic
reverse-result 3.9.2.1 generic
reverse-stanza 3.9.2.1 generic

S
smc-log 3.5.5 Logging Procedures
smc-log-init! 3.5.3 Logging Initialization and Configuration
smc-version 3.4 Version
smc-version/major 3.4 Version
smc-version/minor 3.4 Version
smc-version/patch 3.4 Version
smc-version/string 3.4 Version
state->list 3.6.4.2 List/state conversion
state->list/serialized 3.6.4.2 List/state conversion
state->standalone-code 3.3.3 Guile Standalone
state-dead-end? 3.6.4 Public API
state-description 3.6.4 Public API
state-entry-action 3.6.4 Public API
state-entry-action-set! 3.6.4 Public API
state-event-source 3.6.4 Public API
state-event-source-set! 3.6.4 Public API
state-exit-action 3.6.4 Public API
state-exit-action-set! 3.6.4 Public API
state-final-transitions 3.6.4 Public API
state-has-event-source? 3.6.4 Public API
state-has-final-transitions? 3.6.4 Public API
state-has-recurrent-links? 3.6.4 Public API
state-name 3.6.4 Public API
state-name 3.6.4 Public API
state-recurrent-links-count 3.6.4 Public API
state-run 3.6.4 Public API
state-transition-add! 3.6.4 Public API
state-transition-count 3.6.4 Public API
state-transition-count 3.6.4 Public API
state-transition-count/foreign 3.6.4 Public API
state-transitions 3.6.4 Public API
state:description 3.6.4.1 State as a list
state:entry-action 3.6.4.1 State as a list
state:event-source 3.6.4.1 State as a list
state:event-source/name 3.6.4.1 State as a list
state:exit-action 3.6.4.1 State as a list
state:name 3.6.4.1 State as a list
state:transitions 3.6.4.1 State as a list
state? 3.6.4 Public API
string-drop-both 3.3.3 Guile Standalone
system-log? 3.5.2.1 System Log

T
throw-no-start-tag-error 3.2.2.1 FSM Guards and Actions
throw-unexpected-end-of-file-error 3.2.2.1 FSM Guards and Actions
title? 3.2.2.1 FSM Guards and Actions
transition-list->hash-table 3.1.2 Public API
transition-table-append 3.7.2 Transition Table
transition-table-count 3.7.2 Transition Table
transition-table-run 3.7.2 Transition Table
transition:action 3.7.1 Transition Accessors
transition:guard 3.7.1 Transition Accessors
transition:next-state 3.7.1 Transition Accessors
tree-contains? 3.3.3 Guile Standalone

U
update-counter 3.9.2.1 generic

V
validate-end-tag 3.2.2.1 FSM Guards and Actions
validate-start-tag 3.2.2.1 FSM Guards and Actions

W
write-define-class 3.3.2 Guile
write-footer 3.3.1 Common Guile Compiler Code
write-header 3.3.1 Common Guile Compiler Code
write-initialize 3.3.2 Guile
write-module 3.3.2 Guile
write-parent-fsm-info 3.3.1 Common Guile Compiler Code
write-section-header 3.3.1 Common Guile Compiler Code
write-transition-table 3.3.2 Guile
write-use-modules 3.3.2 Guile

Jump to:   %  
A   C   E   F   G   H   L   M   N   P   R   S   T   U   V   W  

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Concept Index

Jump to:   A   C   F   G   P   S   T   V  
Index Entry  Section

A
Action 3.8.1 Guards

C
CLI 4 Command-Line Interface
Compilation Targets 4.1.1 Compilation Targets
Compiler 3.3 Compiler
Context 3.7.2 Transition Table
Context Memory 3.8.3.3 “u8”

F
FSM 3.1 FSM
FSM logging 3.1.2.3 Logging

G
Guard 3.8 Context

P
Profiler 4.3 The Profiler

S
State 3.6 State

T
Transition 3.7 Transition
Transition Action 3.7 Transition
Transition Guard 3.7 Transition
Transition Next State 3.7 Transition
Transition Table 3.7.2 Transition Table

V
Versioning 3.4 Version

Jump to:   A   C   F   G   P   S   T   V  

[Top] [Contents] [Index] [ ? ]

Table of Contents


[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated on August 15, 2023 using texi2html 5.0.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ << ] FastBack Beginning of this chapter or previous chapter 1
[ < ] Back Previous section in reading order 1.2.2
[ Up ] Up Up section 1.2
[ > ] Forward Next section in reading order 1.2.4
[ >> ] FastForward Next chapter 2
[Top] Top Cover (top) of document  
[Contents] Contents Table of contents  
[Index] Index Index  
[ ? ] About About (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:


This document was generated on August 15, 2023 using texi2html 5.0.