Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!yuma!csn!nntp-xfer-2.csn.net!symbios.com!southwind.net!news.sprintlink.net!howland.reston.ans.net!agate!newsxfer.itd.umich.edu!newsfeed.internetmci.com!in2.uu.net!munnari.OZ.AU!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: call/N
Message-ID: <9531916.9921@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <483dqi$776@lyra.csx.cam.ac.uk>
Date: Wed, 15 Nov 1995 05:30:39 GMT
Lines: 30

etg10@cl.cam.ac.uk (Edmund Grimley-Evans) writes:

>SICStus doesn't seem to have call/N. What's the best way of
>adding them?

Here's one simple way of adding them:

	call(Goal0, X) :-
		Goal0 =.. List0,
		append(List0, [X], List),
		Goal =.. List,
		call(Goal).
	call(Goal0, X, Y) :-
		Goal0 =.. List0,
		append(List0, [X, Y], List),
		Goal =.. List,
		call(Goal).
	call(Goal0, X, Y, Z) :-
		Goal0 =.. List0,
		append(List0, [X, Y, Z], List),
		Goal =.. List,
		call(Goal).

If efficiency is important, you could try using functor/3 and arg/3
to copy the struct rather than '=..'/2 and append/3. 
But call/N really ought to be builtin predicates.

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
