Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!sci.ccny.cuny.edu!phri!cmcl2!yale!husc6!bunny!tomf From: tomf@GTE.COM (Tom Fawcett) Newsgroups: comp.lang.prolog Subject: Re: Arrays in Prolog Message-ID: <9653@bunny.GTE.COM> Date: 27 Aug 90 23:33:04 GMT References: <90239.175243SCHMIED@DB0TUI11.BITNET> Organization: GTE Laboratories, Waltham MA Lines: 34 I too have needed to use arrays in Prolog, and have been generally dissatisfied with what I've found. I'm using Quintus Prolog, which has two separate library files that implement arrays in different ways. Neither have constant-time access and update, and the one that claims to be better requires that you retract, modify, and re-assert the array for every modification. When asking about this deficiency, the reaction I've gotten is that you shouldn't need to use arrays - there is no logical interpretation of destructive modifications to a data structure. I suppose this is generally true; for most applications there is a more natural and elegant way to accomplish what you want without resorting to arrays. Nevertheless, for some applications Prolog's indexing mechanism simply isn't fast enough, and you need the speed of arrays. The solution I've settled on is to use a library file provided by Quintus called vectors.pl, which allows you to create and access single dimension arrays of arbitrary length. I haven't looked closely at the code, but it uses Unix's malloc and free routines to do storage management inside Prolog's heap. The package was designed to be used to pass data between C and Prolog, and not be a general array management package, but it seems to do the job. It should be fairly easy to write one yourself. Unfortunately, besides having to write the code yourself, you'll end up with a system split across two languages. You have to make sure that the split is fairly clean, since you don't want to spend a lot of time passing data between C and Prolog. -- -Tom Fawcett GTE Labs, and UMass/Amherst