Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!fauern!tumuc!guug!ecrc!micha From: micha@ecrc.de (Micha Meier) Newsgroups: comp.lang.prolog Subject: Re: Arrays in Prolog Message-ID: <990@ecrc.de> Date: 29 Aug 90 11:02:22 GMT References: <90239.175243SCHMIED@DB0TUI11.BITNET> <9653@bunny.GTE.COM> Sender: news@ecrc.de Reply-To: micha@ecrc.de (Micha Meier) Organization: ECRC Lines: 56 In article <9653@bunny.GTE.COM> tomf@GTE.COM (Tom Fawcett) writes: > >I too have needed to use arrays in Prolog, and have been generally >dissatisfied with what I've found. ... >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. In every Prolog system, it is possible to use the arg/3 predicate to have a constant-time access to a structure argument, and so for example instead of having char_in_sequence4(1, c). char_in_sequence4(2, u). char_in_sequence4(3, c). ... one can write char_in_sequence4(I, Element) :- arg(I, chars(c, u, c, ...), Element). however in many Prolog systems the arity of functors is limited, and some of the structure-copying compilers will try to construct the whole chars/N structure on every char_in_sequence4/2 call. The ECRC SEPIA 3.0 system provides both these logical arrays (implemented efficiently when the array structure is ground), and real arrays. The latter are mainly a means to pass compound terms between Prolog and C, so that e.g. C structures can be mapped on Prolog arrays and handled in Prolog, however the arrays can also be used only in Prolog. For example, the sequence :- make_array(rotate(3, 3), integer), setval(rotate(0, 0), 1), setval(rotate(1, 2), -1), setval(rotate(2, 1), 1). creates a matrix for a rotation about the x-axis, the predicate getval/2 can be used to retrieve elements of the array. The SEPIA system is available for a nominal fee to academic sites and it has a number of other very useful features. -- Micha Meier USA micha%ecrc.de@pyramid.com MAIL Micha Meier ECRC, Arabellastr. 17 EUROPE micha@ecrc.de 8000 Munich 81 West Germany -- USA micha%ecrc.de@pyramid.com MAIL Micha Meier ECRC, Arabellastr. 17 EUROPE micha@ecrc.de 8000 Munich 81 West Germany