FW: [mercury-users] Records

Peter Schachte schachte at cs.mu.OZ.AU
Mon Nov 8 23:49:08 AEDT 1999


On Mon, Nov 08, 1999 at 04:00:49PM +1100, Simon Taylor wrote:
> > > The only complaint I have with using magic function names for which
> > > definitions can be automatically generated by the compiler is that
> > > typos can result in difficult to spot bugs where the programmer's
> > > version is not called.
> 
> :- type foo
> 	---> foo(
> 		field1::int,
> 		field2::int
> 	).
> :- func 'set feild1'(foo, int) = foo.

For starters, there's nothing wrong with this code that the compiler
can find.  But that's true of any function/predicate definition with a
misspelling.  The error shows up where it is used.

A goal

	Foo2 = (Foo ^ field1 := 42)

would be translated to

	Foo2 = 'set field1'(Foo, 42)

so you'd get an error message stating that there's no such function as
'set field1'/2.  That would lead you back to the function definition
("I was sure I wrote that function!"), where hopefully you would find
the error without too much trouble.  I don't see how a declaration
could help with that.  Anyway, I expect whatever form of declaration
you devise will contain the name of the function you are devising the
setter for; it would be just as easy to get that wrong, and IMHO,
no easer to spot when you do.

-- 
Peter Schachte                     A billion here, a couple of billion there
mailto:schachte at cs.mu.OZ.AU        -- first thing you know it adds up to be
http://www.cs.mu.oz.au/~schachte/  real money.
PGP: finger schachte at 128.250.37.3      -- Senator Everett McKinley Dirksen 
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list