This package allows the use of structures with field names. It is intended to make programs more readable and easier to modify, without compromising efficiency (it is implemented using ECLiPSe macros). The library is loaded using
A structure is declared by specifying a template like::- lib(structures).
Structures with the functor book/4 can then be written as:- define_struct( book(author, title, year, publisher) ).
which translate to the corresponding formsbook with [] book with title:'tom sawyer' book with [title:'tom sawyer', year:1886, author:twain]
This transformation is done by macro expansion, therefore it can be used in any context and is as efficient as using the structures directly. The argument index of a field in a structure can be obtained using a term of the formbook(_, _, _, _) book(_, 'tom sawyer', _, _) book(twain, 'tom sawyer', 1886, _)
E.g. to access (ie. unify) a single argument of a structure, use arg/3 like this:FieldName of StructName
which is translated intoarg(year of book, B, Y)
For printing structures as with/2 terms, use portray_struct/2:arg(3, B, Y)
which will print something likeportray_struct(output, B)
Remove the structure declaration usingbook with [author : twain, title : tom sawyer, year : 1886, publisher : _g117]
erase_struct(book).