🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1684

Re: Abstract Type in Prolog ?

#1684
From: Jens Kilian
Date: Thu, 03 Jan 1991 19:39
40 lines
1688 bytes
Sure, you can represent abstract data types in Prolog. The main problem is
that axiomatic specifications of abstract data types are functional, so you
have to add an output argument to each of the functions to get the
corresponding Prolog predicates. The stack example is straightforward :

%	Create an empty stack

createstack(createstack).

%	Check if a stack is empty (succeeds iff true)

isemptystack(createstack).

%	Push an item

push(Item, Stack, push(Item, Stack)).

%	Retrieve the top of a stack, fail if it's empty

top(push(Item, _), Item).

%	Pop an item off a stack, fail if the stack is empty

pop(push(_, Stack), Stack).

If you'd like an error indication for top() or pop() applied to an empty
stack (instead of failure), you can do something like

	pop(push(_, Stack), Stack).
	pop(createstack, Stack).

This predicate still fails if it is applied to something which isn't a stack.


				Jens Kilian
--
Internet: kilian@seas.gwu.edu		SnailMail: 4715 MacArthur Blvd.
(I don't know any other addresses ...)		   Washington, DC 20007
"Sie hawwe-mer so e bekannt Physionomie, ich mahn, ich misst Ihne kenne.
 Sinn-Se net, um Vergebung, der Herr Assesser Ranft ?"
Technical Details
Message-ID: <2493@sparko.gwu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!seas.gwu.edu!kilian
References: <1991Jan3.154717.27057@watserv1.waterloo.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!seas.gwu.edu!kilian
From: kilian@seas.gwu.edu (Jens Kilian)
Newsgroups: comp.lang.prolog
Subject: Re: Abstract Type in Prolog ?
Message-ID: <2493@sparko.gwu.edu>
Date: 3 Jan 91 19:39:18 GMT
References: <1991Jan3.154717.27057@watserv1.waterloo.edu>
Sender: news@seas.gwu.edu
Reply-To: kilian@seas.gwu.edu (Jens Kilian)
Organization: The George Washington University, Washington, D.C.
Lines: 40