🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1108

Re: Arrays in Prolog

#1108
From: Roland Karlsson
Date: Tue, 28 Aug 1990 06:53
36 lines
2128 bytes
> So it's come to this -- destructive assignment in Prolog!

> There are several methods for implementing arrays in Prolog
> and the one I have implemented is a variant of the setarg/3
> precicate that also appears elsewhere.

> setarg(Index,Term,Value)

> replaces argument ``index'' in ``term'' with ``value'' but
> allows backtracking so that ``term'' may be restored to its
> former state -- no destructuve assignment happens unless you
> 	setarg(X,Y,Z), !.

Setarg/3 is implemented in SICStus Prolog.  But 'setarg,!' will NOT
lead to a destructive assignment.  The correct value is reinstalled
att backtracking.  I would consider it a bug if it did so.

( There is SECRET an DANGEROUS system setarg/4 that can do destructive
  assignment.  Non experts on SICStus implementation shall NOT use it.
  Please don NOT tell anybody (;-) )

Roland Karlsson

PS. I agree that Prolog should benefit from having some unclean data types,
such as arrays, global variables etc.  All with destructive assignment.
They should be typed or (as in ESP Prolog) defined as some type at
creation. (X=1 will give you a normal term X and Y:=1 will give you an
unclean variable Y that can be changed to an other value of compatible
type but any atempt to unify it with anything but itself will fail. That
is 'A:=1,B:=1,A=B' will fail but 'A:=1,B:=1,A==B' and 'A:=1,A=A' 
will succeed.)
--
Roland Karlsson
SICS, PO Box 1263, S-164 28 KISTA, SWEDEN	Internet: roland@sics.se
Tel: +46 8 752 15 40	Ttx: 812 61 54 SICS S	Fax: +46 8 751 72 30
Technical Details
Message-ID: <1990Aug28.065353.13951@sics.se>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!sics.se!sics.se!roland
References: <90239.175243SCHMIED@DB0TUI11.BITNET> <3899@bingvaxu.cc.binghamton.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!sics.se!sics.se!roland
From: roland@sics.se (Roland Karlsson)
Newsgroups: comp.lang.prolog
Subject: Re: Arrays in Prolog
Message-ID: <1990Aug28.065353.13951@sics.se>
Date: 28 Aug 90 06:53:53 GMT
References: <90239.175243SCHMIED@DB0TUI11.BITNET>
 <3899@bingvaxu.cc.binghamton.edu>
Sender: news@sics.se
Organization: Swedish Institute of Computer Science, Kista
Lines: 36
In-Reply-To: vu0310@bingvaxu.cc.binghamton.edu's message of 27 Aug 90 21:20:07 GMT