[mercury-users] clause/1, functor/3, arg/3 ...
bromage at cs.mu.oz.au
Tue Jul 8 21:13:25 AEST 1997
Ralph Becket wrote:
> I'm sure I'm being a bit dense here, but given Mercury's type scheme,
> surely one can just use a switch and pattern matching to decide the
> functor/arity/arguments of any structure? I thought Prolog only
> needed them *because* it doesn't have a (strong) type scheme.
> What does functor/3 and arg/3 get you in Mercury? I'm intrigued (or
> very dim)!
Functor/arg and type_to_term/term_to_type can be expressed in terms of
each other (some tricky typing issues ignored for the purposes of
discussion), and so if you have one it costs you little to put the
other one in too. Type <-> term conversion predicates have been
provided in previous releases of Mercury but disabled by default
because of code bloat.
Of course the real reason looks extremely like Mallory's excuse for
attempting to climb Everest: "Because it's there". Okay, that's a bit
unfair. We needed the meta-information for the forthcoming native
garbage collector, and given that, functor/arg (more correctly, a
slightly different set of primitives; functor, arg and =.. are
implemented in terms of these) were straightforward to add.
Apart from that, you're right: having functor and arg in Mercury is not
as important for "getting the job done" as it is in Prolog. But the
time will come that someone wants to do some tricky meta-programming
for which these seem the least worst solution, so the constructs are
More information about the users