[mercury-users] Functor(Arg) Terms Construction (Not Partially Instantitated?)

Ralph Becket rafe at cs.mu.OZ.AU
Mon May 19 09:47:41 AEST 2003


Goncalo Jorge Coelho e Silva, Sunday, 18 May 2003:
> 
> run_instr(set_value(Address, Value))-->
>         io__write_string("Address"),
>         {
>         string__int_to_string(Address, Addstring)
>         },
>         io__write_string(Addstring),
> 	...

Take a look at the io module interface.  There, you'll find such gems as
io__write_int//1.

>  But, would I be able to construct a functor(arguments) term
> using a one-fits-all predicate like this one? (which wouldn't
> take a partially instantiated term as an argument, would it?
> Because both X,Y and Z are grounded at that time...)
> 
> (using this example of non-compilable Mercury, just to show 
>  what I'd like) 
> 
> :- type address == int.
> :- type value == int.
> :- type my_things ---> set_value(address, value).
> 
> main -->
>          {
>          X = 1,
>          Y = 1,
>          Z = "set_value",
>          Term = Z(X, Y)
>          },
>          run_instr(Term).

The manual will tell you that an expression - Z - adjacent to an
argument list - (X, Y) - is taken to be the application of the closure Z
to arguments X and Y.  Which is what the type error you were given is
telling you.

You could do something like this

:- type instr ---> instr(string, int, int).

main -->
	{ X = 1, Y = 1, Z = "set_value", Instr = instr(Z, X, Y) },
	run_instr(Term).

run_instr(instr(Name, Arg1, Arg2)) -->
	...

but this *really* isn't what you want.  Why do you need to take such a
convoluted route?  What's wrong with the original suggestion of having
one data constructor for each kind of instruction?

>  So, would it be possible to create a one-fits-all
> functor(arg) creation predicate in Mercury? 

Not the way you're thinking of.  And I suspect this line of thinking is
making your problem much harder than it really is.

- Ralph
--------------------------------------------------------------------------
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