Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!pipex!uknet!newsfeed.ed.ac.uk!hwcee!andrew
From: andrew@cee.hw.ac.uk (Andrew Dinn)
Subject: Re: symbolic global constants (not)
Message-ID: <D8978n.441@cee.hw.ac.uk>
Sender: news@cee.hw.ac.uk (News Administrator)
Organization: Dept of Computing and Electrical Engineering, Heriot-Watt University
X-Newsreader: TIN [version 1.2 PL2]
References: <STEVEW.95Apr27234121@debretts.comp.vuw.ac.nz> <PEREIRA.95Apr29150358@alta.research.att.com>
Date: Mon, 8 May 1995 09:48:21 GMT
Lines: 49

Fernando Pereira (pereira@alta.research.att.com) wrote:

: Pray tell me why you think
: 	eof(-1).
: 	...
: 	scan(C, L, L) :- eof(C).

: is less intuitive, more inconvenient or more ugly than
: 	#define EOF -1
: 	...
: 	TokenList scan(int c, TokenList l)
: 	{
: 		...
: 		if (c == EOF) return l;
: 		...
: 	}

: The difference seems trivial, at least for anyone who is comfortable
: with both languages.

The difference is trivial since you can easily guess what `eof(C)'
means. But when you use something like `global_terminator(C)' or worse
still horrors such as `foobar_compiler_internal_terminate_input(C)'
the lack of any intuitive idea of what the predicate means makes it
hard to know that the call is meant to unify the argument with a
global constant. For all you know, he predicate might operate with
several modes. It might have multiple clauses, which may or may not be
facts. Unfortunately, a predicate call usually carries the implication
that a certain amount of computation and maybe even backtracking might
be performed beneath the call.

Of course the C version could suffer from a similar problem if the
name of the defined constant was badly chosen. However, the ambiguity
which arises from unclear naming in C does not include the possibility
that the defined value is anything other than a reference to a value,
variable or constant. (I am deliberately ignoring *pathological* cases
where someone defines a symbol as an expression mentioning free
variables, rather than using a parameterised macro).

Either way the problem is not one of weak syntax, let alone
aesthetics, but one of convention. A sensible naming scheme, used as
part of a clear coding standard, will usually make things clear,
readable and maybe even pleasing.


Andrew Dinn
-----------
O alter Duft aus Maerchenzeit / Berauschest wieder meine Sinne
Ein naerrisch Heer aus Schelmerein / Durchschwirrt die leichte Luft
