[mercury-users] Pred defns

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Apr 3 02:03:52 AEST 1998


On 31-Mar-1998, Peter Schachte <pets at students.cs.mu.OZ.AU> wrote:
> A bulk reply to several messages:
> 
> On Mon, 30 Mar 1998, Fergus Henderson wrote:
> > I agree that the hidden argument proposals do make it somewhat easier
> > to write code.  Only somewhat, mind you, since often you will still need to
> > *examine* every part of the code to see that it threads the hidden arguments
> > in the right order, even if you don't need to change it.
> 
> By this I assume you mean that you need to check that a certain thread has
> the "right" value at the time you want to use it.

I mean that for example if the traversal code contains multiple calls
to the low-level code which updates the state of the hidden
argument(s), then you may need to ensure that these calls occur in the
correct order.

> > But my main criticism is that I think making it easier to add hidden
> > arguments in this way often this comes at the expense of making the
> > modified code harder to read.  Because the arguments are hidden, it is
> > harder to understand the program's data flow.
> 
> Balancing this, it also does the opposite:  by removing many arguments from
> your code, it makes it easier to see the important bits.

That is a fair point.

> On Mon, 30 Mar 1998, Fergus Henderson wrote:
> 
> > For example:
> > 
> > 	main(###io) :-
> > 		print("Hello world\n", ###io),
> > 		#x = 42,
> > 		##x = #x + 1,
> > 		print("42 + 1 =", ###io), print(#x, ###io).

In fact there is a bug in the above code; I said that '##' worked
strictly left-to-right, so in `##x = #x + 1' the `#x' would expand
to the same variable as the `##x'.  To make it would you need to
write `#x + 1 = ##x'.

> OK, let's look at this.  That "##x = #x + 1" line behaves a lot like an
> assignment.  We can get rid of the need for ## by adding a more orthodox
> looking assignment operator.

`:=' would certainly be a good idea, especially given the issue with
left-to-right ordering and `##'.  And `:=' would be enough for this
particular case.  But '##' or some equivalent would still be needed
in other cases, e.g.

	map__set(#map, Key1, Value1, ##map),
	map__set(#map, Key2, Value2, ##map)
	...

What does your global variables package do for situations like that?

> In fact, the first assignment of a value to
> thread x refers to it as #x, and the second as ##x, but they are really
> doing the same thing.  I think they should look the same:  both should be
> assignments.

Well, the first one is just a unification; but an assignment would work
equally well there.

> Oh, one more thing:  how about replacing #x by $x and ###x by
> $$x (a gratuitous change, but I think $x just looks better, and $$x is
> suggestive of two $x's)?

I used ### because it was suggestive of # + ##.
I'd be happy with $ instead of #.
But I think we still need some equivalent to ##.

Perhaps "$", "$$", and "$`" for "#", "###", and "##".

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the users mailing list