From ok@atlas.otago.ac.nz  Fri Sep 22 05:07:48 2000
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id FAA27200
	for <prolog@swi.psy.uva.nl>; Fri, 22 Sep 2000 05:07:47 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id PAA10772;
	Fri, 22 Sep 2000 15:08:06 +1200 (NZST)
Date: Fri, 22 Sep 2000 15:08:06 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200009220308.PAA10772@atlas.otago.ac.nz>
To: prolog@swi.psy.uva.nl, waseem@isk.kth.se
Subject: Re:  tree and _X

	What is wrong in this fragment of Prolog: ( Thinking in dictionary, that is
	a map of pairs Key -> Value)
	
	tree(Key, Value, Left, Right).

What is that line meant to do?

	lookup(Key, tree(Key1, Value1, Left, Right), Value) :-
	Key < Key1, lookup(Key, Left, Value).
	lookup(Key, tree(Key1, Value1, Left, Right), Value) :-
	Key > Key1, lookup(Key, Left, Value).
	
There are three problems here.
1.  No indentation.
2.  Some Prologs will realise this is (semi-)deterministic, but some won't.
3.  There is no clause that handles equality.

Best:

	lookup(Key, tree(K,V,L,R), Value) :-
	    compare(Ord, Key, K),
	    lookup_case(Ord, Key, Value, V, L, R).

	lookup_case(<, Key, Value, _, L, _) :-
	    lookup(Key, L, Value).
	lookup_case(>, Key, Value, _, _, R) :-
	    lookup(Key, R, Value).
	lookup_case(=, _, Value, Value, _, _).


	What is the difference between a variable wriiten as X and _X ?
	
This difference only:  if there is only one occurrences of a variable
in a clause, and that variable's name does NOT begin with an underscore,
Quintus and later Prologs will warn you that you have a "singleton
variable", because that's often the result of a spelling mistake.
There is no behavioural difference, and it is very bad style to use
leading underscores for variables that are intended to occur more than once.

