Subject: runtime detection of singleton variables

From: Paul Singleton <[email-masked]>
Date: Thu, 10 Aug 2000 16:52:14 +0100

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