[mercury-users] newbie question: instantiating a type (practicing with the tutorial)

Tomas By tomas at basun.net
Thu Sep 23 18:52:21 AEST 2010


On Thu, September 23, 2010 10:24, Jean-Marc Vanel wrote:
> how to create an empty dictionary , with the right type (string) of key
> and value in variable Dic ?
>         Dic2 = set( Dic, "jmv", "JM Vanel" ),
>         search( Dic2, "jmv", V),
>         io.write_string( "search( dic, jmv, V) : V= ", !IO),
>         io.write_string( V, !IO) .

A set is just a set of single values (well...). What you want here is a
`map,' and then you need more declarations also.

|:- pred main(io.state::di,io.state::uo) is det.
|main(!IO) :-
|  map.init(Dic0)
|  map.insert(Dic0,"jmv","JM Vanel",Dic1),
|  map.search(Dic1,"jmv",V),
|  io.format("search( dic, jmv, V) : V = %s\n",[s(V)],!IO).

But what you really want to do in a case like this is define a file
format data type, like

| :- type dataclause ---> name(string,string).

and then have a file of statements like

| name("jmv","JM Vanel").

which you read into a map. Then you can edit that file separately, and
use Prolog to examine the data.


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