Logical State Threads (Prev: EDCG) 
Author Message
 Logical State Threads (Prev: EDCG)

I hereby announce the first beta release (0.1) of the

              Logical State Thread package

                  For SICStus Prolog

The Logical State Threads package is a powerful tool to simplify the
development of large Prolog programs. It provides a way to avoid many of
the arguments in your predicates whose main purpose is to thread state
information through your program. These arguments otherwise often make
your predicate definitions unnecessarily complicated and difficult to
read and modify.

Instead of adding all those threaded state variables the Logical State
Threads package provides you with a way to just declare what predicates
should use what state thread and then the package adds these threaded
variables for you.

Main features:

   -  Higher abstraction level than EDCGs. The programmer will not need
      to be as aware of the underlying transformation since it is never
      necessary to access the threaded arguments directly.

   -  Threads may be arbitrarily combined and accessed across nested

   -  Flexible accessing/modification of the thread state.  Multiple
      'methods' can be defined for the same thread, which allows the
      thread to be modified in different ways.

   -  Much improved consistency checking at loading time with many new
      warning/error messages.

   -  Better integration with the SICStus Prolog module system.  Threads
      with the same name defined in separate modules are kept separate.

   -  Design based on formal semantics, rewriting accumulator clause
      syntax to a core language and defining a transformation from the
      core language to standard Horn clauses.

The Logical State Threads package currently works for SICStus Prolog
versions 2.1 and 3, but support for other Prolog systems should not be
difficult to add as long as they provide a hook predicate like
user:term_expansion/2, which defines transformations on terms read while
a program is consulted or compiled.

If you have WWW access, direct your browser to


where you can read more about the package and download the system.

If you only have FTP you can find the system at ftp.cs.arizona.edu in
directory /people/andka/ as the file threads-0.1.tar.gz (if you have
problems with compressed files you can just omit the .gz suffix which
will make the FTP server here uncompress it before sending it to you).

Below I include the initial part of the tutorial as a "teaser".

As noted above, this is still beta software and comments and error


/Andreas K?gedal



                          The Introduction to

                               A Tutorial

                                 of the

                     Logical State Threads package

                          for SICStus Prolog



The Logical State Threads package is a powerful tool to simplify the
development of large programs.  It makes a source-to-source
transformation of your program adding new arguments to your predicates
according to your specifications.

A First Example

Suppose you want to write a program that traverses a binary tree which
has integers in the leaves and names of animals in the internal nodes.
The basic ``skeleton'' of the traversing predicate would look something

   traverse_tree( Tree ) :-
        traverse( Tree ).

   traverse( leaf(Int) ).
   traverse( tree(Animal,LeftBranch,RightBranch) ) :-
        traverse( LeftBranch ),
        traverse( RightBranch ).

This program still does not really do anything. If we for instance want
to calculate the sum of all the leaves we can add two more arguments to
the traverse predicate.  We *thread* the value calculated so far through
the predicate:

   traverse_tree( Tree, LeafSum) :-
        traverse( Tree, 0, LeafSum ).

   traverse( leaf(Int), OldSum, NewSum) :-
        NewSum is OldSum + Int.
   traverse( tree(Animal,LeftBranch,RightBranch), OldSum, NewSum ) :-
        traverse( LeftBranch, OldSum, TmpSum ),
        traverse( RightBranch, TmpSum, NewSum ).

This is a very common way of dealing with *state* in a Prolog
program. The threaded sum arguments models the current state of the
calculated sum of the leaves.  If you have written larger applications
in Prolog you have probably used this technique many times. There is one
obvious disadvantage with this approach. It easily makes predicates have
lots of arguments. This makes them difficult to read, especially as most
arguments are not really used in most clauses except that they are
threaded through the body. Try for instance to imagine what this program
would look like if there were two kinds of internal nodes, one with
names of animals and one with colours, and we wanted to compute not only
the sum of the leaves but also the maximal leaf, the number of
occurrences of the colour `blue' and a list of all animals in the tree.

        This is the problem that the Logical State Threads
                   package helps you avoid!


Sun, 04 Jul 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. logical*4 and logical*8?

2. Threading a state through a fold?

3. Lazy Functional State Threads

4. Lazy State Threads in Haskell

5. Lazy State Threads in Haskell

6. the state of threading in eiffel

7. Problems with thread state

8. Global interpreter locks, thread states et al...

9. Embedding Pythonwin: Thread State Problems with Nested Calls

10. thread state and the global interpreter lock

11. Thread State Problem

12. Thread State and the Global Interpreter Lock


Powered by phpBB® Forum Software