[mercury-users] Libraries and DCG convenience...

Luke Evans Luke.Evans at seagatesoftware.com
Wed Jun 23 03:37:08 AEST 1999


Thanks Peter.  This still falls under my general definition of 'writing a
wrapper', but the higher order approach will of course deal with patterns of
arguments and therefore kills several birds with one stone (so to speak).

It also still involves a lot of syntactic overhead (though much less than
having to write individual '1st order' wrappers for a large subset of the
graph predicates).  Also, to a certain extent it obfuscates the call we're
really interested in.  However, if there's no general solution available for
time being (and I find I'm using more groups of library predicates like
this), then I think I might include such a to_DCG_style modifier in my code.


Obviously the original question of the 'rightness' of using DCG in this
context remains.

Lwe

-----Original Message-----
From: Peter Ross [mailto:petdr at cs.mu.OZ.AU]
Sent: 22 June 1999 14:27
To: mercury-users at cs.mu.OZ.AU
Subject: Re: [mercury-users] Libraries and DCG convenience...


On 21-Jun-1999, Luke Evans <Luke.Evans at seagatesoftware.com> wrote:
> Threading the graph variables through all this is painful and seems (IMHO)
> to be exactly what DCG's were designed for.   Of course, I can write
> wrappers for the standard predicates which reorder the arguments to
present
> the <Graph state before> and <Graph state after> arguments at the end of
the
> argument list, but this becomes a real overhead to using the standard
> library.
> 
You can use higher-order functions to avoid writing wrapper functions.

:- module main.

:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- import_module graph, std_util.

main -->
	{ graph__init(G0) },
	{ create_graph(G0, G) },
	io__write(G).

:- pred create_graph(graph(int), graph(int)) is det.

create_graph -->
	switch(graph__det_insert_node, 1, Node1),
	switch(graph__det_insert_node, 2, Node2),
	switch(graph__det_insert_node, 3, Node3),
	switch(graph__det_insert_edge, Node1, Node2, unit, _Arc12),
	switch(graph__det_insert_edge, Node2, Node3, unit, _Arc23).

:- pred switch(pred(T, A, B, T), A, B, T, T).
:- mode switch(pred(in, in, out, out) is det, in, out, in, out) is det.

switch(P, A, B, T0, T) :-
	P(T0, A, B, T).

:- pred switch(pred(T, A, B, C, D, T), A, B, C, D, T, T).
:- mode switch(pred(in, in, in, in, out, out) is det,
		in, in, in, out, in, out) is det.

switch(P, A, B, C, D, T0, T) :-
	P(T0, A, B, C, D, T).
--------------------------------------------------------------------------
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
--------------------------------------------------------------------------
--------------------------------------------------------------------------
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