From p.singleton@keele.ac.uk  Thu Aug 10 21:14:46 2000
Received: from mail1.svr.pol.co.uk (mail1.svr.pol.co.uk [195.92.193.18])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id VAA04661
	for <prolog@swi.psy.uva.nl>; Thu, 10 Aug 2000 21:14:31 +0200 (MET DST)
Received: from modem4294967272.people.dialup.pol.co.uk ([195.92.3.24] helo=keele.ac.uk)
	by mail1.svr.pol.co.uk with esmtp (Exim 3.13 #0)
	id 13Mxmn-0006Rc-00
	for prolog@swi.psy.uva.nl; Thu, 10 Aug 2000 20:14:37 +0100
Message-ID: <3992CFAE.CA2ADFB2@keele.ac.uk>
Date: Thu, 10 Aug 2000 16:52:14 +0100
From: Paul Singleton <p.singleton@keele.ac.uk>
Organization: SmartArts Computing Consultancy
X-Mailer: Mozilla 4.74 [en] (WinNT; U)
X-Accept-Language: en
MIME-Version: 1.0
To: SWI Prolog <prolog@swi.psy.uva.nl>
Subject: runtime detection of singleton variables
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I use an ODBC interface to retrieve attribute values from RDBMS tables and
views by unification.

It is Prolog-like and convenient (at least sometimes :-) to specify attributes
by position rather than by name, e.g.

  odbc_rspec_tuple(
      'CarShare':'MSysObjects',
      [_,_,_,_,_,_,Id,_,_,_,_,Name,_,_,_,_,5]
  )

but in general the interface retrieves values which are not subsequently used,
which is a waste of time and memory resources (some may be of LONG types,
fetched piecemeal, reassembled, and interned as atoms).

I could lash up an ad hoc notation for "don't bother getting this attribute"
but it wouldn't be relational, nor readily amenable to being mechanically
generated, nor very satisfying...

What I think I *really* want is a new metalogical built-in predicate to detect
singleton variables in a goal (there are fourteen in the example above) so my
code can avoid wasting effort instantiating them.

I guess there may be problems identifying all variables whose instantiation can
serve no purpose, and there may even be problems formalising this requirement,
but a "sound-but-incomplete"/"fail-safe" test for e.g. easy-to-spot cases could
be of value.

NB I floated this idea on c.l.p several years ago, with a pure Prolog example
like append( _, Tail, List) and the only followup I recall suggested I should
wait for smarter compilers which do static analysis and optimise my code for me.
I now realise this isn't a general (let alone a realistic) solution, 'cos it
can hardly optimise my foreign (ODBC-interfacing) code too :-)

Paul Singleton


