# Examples 8.11.3.1:
ANSWERS

The features of the required library class ANSWERS are used in individual examples. None of the examples given is a complete class nor necessarily a 'complete' method.

In all of the examples it will be assumed where appropriate that the code shown is in a class called, say, EXAMPLE.

#### create

This feature would typically be used in creating a recognizer for not only some 'yes/no' string possibilities but for other situations too. Consider the need to differentiate between a word in the dictionary sense and a word which may contain low lines and digits - as a programming language identifier, say. The creation code for the recognizer could then be -

#### create

This form of creation from a binary string presumes that the binaey string is a correct representation of the object (in this case an answer) in binary form. A simple sequence of code where the current octet in some binary stream cursor indicates the count of octets containing the answer might be written as -

#### build

The example above could have been written as follows - directly - assuming that the implementation-defined form of binary string had such a leading count octet -

#### read

This feature provides for optional reading of a value dependent upon whether tor not the next octet in the stream represents the truth value true (whien it will be read) or false (when void is returned). Some simple code for handling an optional value could be -

#### yes

This is the first of two predicates which only determine a correct match if they return true. If success is of prime importance then -

#### no

The corresponding code for the importance of failure could then be similarly written as -

#### response

This routine could be used to implement the two previous predicates as follows -

#### binstr

This feature provides the inverse operation to building. An answer value converted into a binary form is returned, thus -

#### write

Exporting an answer recogniser to a binary file may be done using this feature as -

which could be implemented as

if desired!

| Specification Index |  | Language Index |  | Section 8 Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Tuesday, 30 May 2000. |