[mercury-users] partial instantiation?
Mark Brown
mark at csse.unimelb.edu.au
Tue Apr 20 03:56:29 AEST 2010
On 19-Apr-2010, Tomas By <tomas at basun.net> wrote:
> On Mon, April 19, 2010 09:39, Ralph Becket wrote:
> > Tomas, Monday, 19 April 2010:
> >>
> >> Also, the way you have written it, the parameters are not passed to the
> >> commands.
> >
> > One of is mistaken here!
>
> Well, my comment above was about your code, where the N was all alone by
> itself.
>
> > Given,
> >
> > :- pred cmd(string,list(cmdarg),cmdproc).
> > :- mode cmd(out,out,out) is nondet.
> >
> > cmd( "command", [], dosomething(0,"filename") ).
> > cmd( "command", [str(F)], dosomething(0,F) ).
> > cmd( "command", [int(N)], dosomething(N,"filename") ).
> > cmd( "command", [str(F),int(N)], dosomething(N,F) ).
> >
> > if I have
> >
> > CmdNamd = "command",
> > F = "foo",
> > N = 42,
> > Args = [str(F), int(N)],
> > cmd(CmdNamd, Args, Command)
> >
> > then Command will be unified with dosomething(42, "foo"). Isn't
> > that what you need?
>
> I thought we had established that the above will not compile,
I think Ralph meant
:- mode cmd(in, in, out) is semidet.
> but in the
> alternative universe where it works it is still not what I mean, because:
>
> What I get on the command line is ["command","foo","42"],
So cmd is called with the (ground) value [str("foo"), int(42)] as the
second argument, and dosomething(42, "foo") is returned.
> but it could
> have been just ["command","42"]
In this case it is called with value [int(42)], and dosomething(42, "filename")
is returned.
> where "42" could have been a filename.
>
> This is for experimentation. I want to be able to modify the commands
> and parameters easily. Doing a lot of fancy interpretation of the command
> line before I get to cmd/X seems misguided.
Thankfully Mercury does deep switch detection, so this simple implementation
is also compiled to efficient code. :-)
Cheers,
Mark.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list