Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!gatech!news.mathworks.com!uunet!in1.uu.net!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!zs
From: zs@munta.cs.mu.OZ.AU (Zoltan Somogyi)
Subject: Re: Prolog syntax
Message-ID: <9512019.12772@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <9511221.23905@mulga.cs.mu.OZ.AU> <3nkjnc$q0o@goanna.cs.rmit.edu.au>
Date: Sun, 30 Apr 1995 09:21:45 GMT
Lines: 95

fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
> since for common errors such as
>	( X = 0 ->
>		foo,
>		bar,	% oops, extra comma
>	;
>		baz
>	).
>the first incorrect token is not the extraneous comma or even the semicolon,
>it is at `baz', two lines past the actual cause of the error.

ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) writes:
>You call it a "common" error.  I used to see it at most once a year, and it
>was never hard to find.

Different people have different programming styles. You may not make such
errors, but I do; I get syntax errors like this after about one quarter of
my edits. This makes me an "assertive programmer" according to the Weinberg's
"The psychology of computer programming". A large proportion of all programmers
fall into the same category.

As an example, let me show you a syntax error I just got. This is the
predicate involved:

mercury_compile__semantic_pass_by_phases(HLDS1, HLDS9, Proceed0, Proceed) -->
	globals__io_lookup_bool_option(statistics, Statistics),

	mercury_compile__typecheck(HLDS1, HLDS2, FoundTypeError),
	maybe_report_stats(Statistics),
	mercury_compile__maybe_dump_hlds(HLDS, "2", "typecheck"),
	{ bool__not(FoundTypeError, Proceed1) },

	globals__io_lookup_bool_option(modecheck, DoModeCheck),
	( { DoModeCheck = yes } ->
		mercury_compile__modecheck(HLDS2, HLDS3, FoundModeError),
		maybe_report_stats(Statistics),
		mercury_compile__maybe_dump_hlds(HLDS, "3", "modecheck").
		{ bool__not(FoundModeError, Proceed2) },

		globals__io_lookup_bool_option(make_call_graph, MakeCallGraph),
		( { MakeCallGraph = yes } ->
			mercury_compile__make_call_graph(HLDS3),
			maybe_report_stats(Statistics)
		;
			[]
		),

		{ bool__and_list([Proceed0, Proceed1, Proceed2], Proceed) },
		( { Proceed = yes } ->
			mercury_compile__maybe_polymorphism(HLDS3, HLDS4),
			maybe_report_stats(Statistics),
			mercury_compile__maybe_dump_hlds(HLDS, "4", "polymorphism"),

			mercury_compile__detect_switches(HLDS4, HLDS5),
			maybe_report_stats(Statistics),
			mercury_compile__maybe_dump_hlds(HLDS, "5", "switch_detect"),

			mercury_compile__detect_cse(HLDS5, HLDS6),
			maybe_report_stats(Statistics),
			mercury_compile__maybe_dump_hlds(HLDS, "6", "cse"),

			mercury_compile__maybe_detect_common_struct(HLDS6, HLDS7),
			maybe_report_stats(Statistics),
			mercury_compile__maybe_dump_hlds(HLDS, "7", "common"),

			mercury_compile__maybe_do_inlining(HLDS7, HLDS8),
			maybe_report_stats(Statistics),
			mercury_compile__maybe_dump_hlds(HLDS, "8", "inlining"),

			mercury_compile__maybe_migrate_followcode(HLDS8, HLDS9),
			maybe_report_stats(Statistics),
			mercury_compile__maybe_dump_hlds(HLDS, "9", "followcode")
		;
			{ HLDS9 = HLDS3 }
		)
	;
		{ HLDS9 = HLDS2 },
		{ Proceed = no }
	).

Can you spot the error? If yes, how long did it take you? Perhaps it is my
eyesight that is to blame, but I needed about three minutes to find the
error (mercury_compile__maybe_dump_hlds(HLDS, "3", "modecheck") is terminated
with a dot, not a comma; a difference of a couple of pixels). Neither Mercury's
nor NU-Prolog's error message was all that helpful beyond giving me the name
of the predicate that had the error.

In general, such mistakes result from moving code around, which some people
do reasonably frequently (including me). In my opinion, if a language does
not eliminate such errors entirely by using terminators instead of separators,
it should at least allow the implementation to pinpoint the error when you do
make it.

Zoltan Somogyi <zs@cs.mu.OZ.AU> http://www.cs.mu.oz.au/~zs/
Department of Computer Science, University of Melbourne, AUSTRALIA
