Unicode

Amzi! Prolog + Logic Server 4.0 is a full Unicode implementation. This means that, internally, all strings are stored as wide (Unicode) character strings. Further, Prolog source text can be stored in Unicode format, enabling the inclusion of Unicode characters directly in Prolog programs. The complete single-byte ANSI interface is totally preserved as well, so there is no impact on existing applications, and no reason not to continue to develop and implement ANSI applications in the future.

Interactive Development Environment (IDE)

  • The editor in the IDE will accept either Unicode or ANSI files, and save a file in the same format it was originally read in. New files can be saved as either ANSI or Unicode and the SAVE_AS dialog box gives you that option.
  • To view Unicode characters it is necessary to set the IDE font to a Unicode font. Lucida Console has a large number of Unicode characters. Gulim is a font included on the NT 4.0 distribution disks that has Japanese characters in it.

    Logic Server API (LSAPI)

    The Logic Server API supports both Unicode and ANSI calls for those functions that take strings as arguments. For the C++ class, C++ function overloading is used to provide both types of support. For the C functions, two versions are included for each string function, one ending in 'A' for the ANSI version and one ending in 'W' for the wide character Unicode version. AMZI4.H has an #IFDEF that maps the normal names of each of these functions to the appropriate version, depending on whether your application is built with _UNICODE defined or not.

    For those functions that map a generic pointer to a C type using the indicator cSTR, the code cSTR will map to and from a single-byte string. The new type, cWSTR has been added for applications that map to and from wide character strings. Similarly, cWATOM allows atoms to be mapped to and from wide characters.

    Character Constants

    Because Unicode characters are unsigned ints and are often referred to by their hexadecimal value, a new integer constant has been added to Amzi! Prolog. Internally it is an unsigned 2-byte integer. They are entered using a similar syntax to hex numbers, only using a 'w' where hex uses an 'x'. They are always displayed in that syntax.

    atom_codes/2, string_list/2 and the back quote character notation (`c) all use the character constants. For example, to create the atom duck:

    ?- atom_codes(duck, X).

    X = [0w0064,0w0075,0w0063,0w006b]

    yes

    ?- atom_codes(X, [0w64, 0w75, 0w63, 0w6b]).

    X = duck

    yes

    To create an atom with Japanese characters:

    ?- atom_codes(X, [0wf900, 0wf901, 0wf902]).

    Character constants can be used in arithmetic and will unify with integers.

    fopen/3

    For text files that are open in read mode, fopen/3 determines the type of file from the data in the file. For text files to be written, you must add a 'u' onto the mode:

    fopen(H, 'pekingduck.pro', wu).

    Sample - Babel

    A sample program, BABEL.PRO, is include that does machine translation between a number of different languages for a small number of sentence types.