# [m-dev.] searching for equivalent procedures [was: for review: prelim support for hash consing]

Erwan Jahier Erwan.Jahier at irisa.fr
Wed Aug 25 21:51:00 AEST 1999

Fergus wrote:
| > > +	% sym_name_to_term(SymName, Args, Term):
| > > +	%	convert a symbol name with an associated list of terms
| > > +	%	into a term.
| > > +:- pred prog_out__sym_name_to_term(sym_name, list(prog_term), prog_term).
| > > +:- mode prog_out__sym_name_to_term(in, in, out) is det.
| >
| > Isn't there already something like this somewhere else?
|
| Yes, I think prog_util__construct_qualified_term is what you are looking for.

Did you ever consider implementing a tool that would search into a set of files
for a procedure, given its mode, type and determinism ?
The tool would search for a procedure equivalent' to the requested one, where
the notion of equivalence' (*) would be based on type, mode and determinism
declarations.

(*) To be a little bit more precise, by equivalent' procedures, I mean
something like: "2 procedures are equivalent iff they have the same
determinism, the same number of arguments and each argument have (modulo
arguments reordering) the same mode and equivalent types (**)"

(**) And 2 types are equivalent if one the following conditions holds:
o they are the same (e.g. integer \equiv integer)
o they are nearly the same' i.e. there exists a declaration such as:
:- type type1 == type2.
o 2 discriminated union types are equivalent if
1) they have the same number of branches and the same
number of leaves on each branch, and
2) each "corresponding" leave have equivalent types.
for example, if we have the following declarations:
:- type type1 ---> foo ; bar(age).
:- type type2 ---> foo ; bar(integer).
:- type age == integer.
then type1 \equiv type2

-o-

Of course, 2 such equivalent procedures migth  be different (ex: +' \equiv
*'), but it would considerably help the search when one wonders if a given
procedure exists.

Another application of such a tool could be to detect duplicated code.

--
R1.

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au