[mercury-users] Pred defns

Ralph Becket rwab1 at cam.sri.com
Mon Mar 30 23:31:57 AEST 1998


Just a word in my defence: while Fergus' syntax uses atoms to denote
accumulators and #x to refer to the current value of acc. x, my
expansion does indeed provide the same functionality:

	#x	<=>	X
	##x	<=>	X`
	###x	<=>	X``

Also, my expansion is the same as Fergus' revised notation re:
accumulators in the head:

	foo(###x) :- ...<=>	foo(X``) :- ...<=>	foo(X0, X) :- ...

Personally I'd prefer keeping capitalised names for accumulators -
since this is a syntactic expansion before compilation it doesn't
really matter what you pick.  And #s are #ugly#!  But people are
always telling me I have no taste.

Fergus Henderson wrote on 30 Mar:
> 
> So, an alternative would be to drop `#{' and `#:-', and to
> distinguish between `#<' (head state pair) and `#>'
> (state pair) based on their position.  This would leave us
> with just 3 operators (`#?', `#^', and `#>') rather than 6,
> and so we could perhaps use just `#', `##', and `###' for
> "current state", "next state", and "state pair"
> (= current state plus next state) respectively.
> 
> For example:
> 
> 	main(###io) :-
> 		print("Hello world\n", ###io),
> 		#x = 42,
> 		##x = #x + 1,
> 		print("42 + 1 =", ###io), print(#x, ###io).
> 
> With this proposal, `,' doesn't necessarily mean conjunction anymore,
> but if a sub-goal (A,B) has no `##'s or `###'s, then the `,' is
> indeed conjunction.  I suppose that in practice the `##'s or `###'s in
> the body would be enough of a red flag that using `#{...}' or `#:-'
> would not really be needed.

Same problem with DCG expansion, so at least there's precedent.

A suggestion: why not decide upon a notation (if this proposal has
support) and provide a preprocessor.  Postfix files written in the
above notation with .m+ and add an (m)make rule

%.m: %.m+
	m_acc_expand $< > $@

m_acc_expand (pick a better name)  will preserve accumulator names
modulo capitalisation and numbering.

This way we do not commit to a new style prematurely: anybody that
doesn't like it can expand .m+ files and edit pure Mercury.  I have to
say right now that I don't have time to write this!

Cheers,

Ralph

p.s. If there *are* higher order alternatives that are as clear then I
really would like to hear about them.

-- 
Ralph Becket  |  rwab1 at cam.sri.com  |  http://www.cam.sri.com/people/becket.html



More information about the users mailing list