Prev No Next Up Home Keys Figs Search New

Arrays in Prolog

Appeared in Volume 9/4, November 1996

Keywords: arrays.


rayudur@lincoln.ac.nz
Ramesh Kumar Rayudu
4th April 1996

I am trying to code a neural net in Prolog and wondering how to implement neural units in arrays without losing too much speed and efficiency as compared to C.

I came across David Warren's logarithmic access of array implementation, but could not figure out how to use it.

Can anyone provide me with a small example showing how to implement a two-dimensional array and how to retrieve and update the array.

In case you are wondering about David Warren's implementation, it is available in the public domain, and is part of the SICStus Library.

Any other implementations would be of great help.


jonas@csd.uu.se
Jonas Barklund
15th April 1996

It is possible to add mutable arrays to Prolog with constant time access and update, as shown by Eriksson and Rayner in a paper from 1984. It is based on an idea for the implementation of shallow binding by Henry Baker. You can even provide a quite useful (and clean) mutable array data abstraction in Prolog (no C programming required) by using the (very dirty) setarg/3 primitive. Unfortunately Sicstus structures have a limited (and small) width so you cannot have long arrays that way. [I have a quick hack that I can mail to anyone interested.]

However, Sicstus provides log-time access and update of arrays with some neat properties. If log-time is sufficient for your purposes, check it out.

Personally I wish constant-time access and update of arrays were supported directly as a data structure in Prolog. See our report "Prolog with Arrays and Bounded Quantifications" (ftp://ftp.csd.uu.se/pub/papers/reports/0077.ps.gz) if you are interested in a more detailed proposal.

Prev No Next Up Home Keys Figs Search New