<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Below is an alternative, which has pros and cons. <br>
</p>
<p>A bit more concise, but you have to align the data carefully to
avoid input errors.</p>
<p>Or, if you have lots of data, you can write a database in a file,
and parse (use the GH csv library for example).<br>
</p>
<p>%%<br>
</p>
<p>:-module map_test.<br>
:-interface.<br>
:-import_module io.<br>
:-import_module map.<br>
:-import_module string.<br>
:-pred create_maps(map(string, string), map(string, string)).<br>
:-mode create_maps(out, out) is det.<br>
<br>
:-pred main(io::di, io::uo) is det.<br>
<br>
:-implementation.<br>
</p>
<p>:-import_module list.<br>
<br>
%% create<br>
<br>
create_maps(Types, Vars) :-<br>
K1 = ["i", "psz", " v", "pv",<br>
"c", "sc", "uc", "pc",<br>
"ppc", "cpc", "cppc"],<br>
V1 = ["int", "char*", "void", "void*",<br>
"char", "signed char", "unsigned char", "char*",<br>
"char**", "const char*", "const char**"],<br>
K2 = ["argc", "argv"],<br>
V2 = ["int", "ppc"],<br>
det_insert_from_corresponding_lists(K1, V1, map.init, Types),<br>
det_insert_from_corresponding_lists(K2, V2, map.init, Vars).<br>
<br>
%% test<br>
<br>
main(!IO) :- create_maps(Types, Vars),<br>
write_string(Types^det_elem("cpc"), !IO),<br>
nl(!IO),<br>
write_string(Vars^det_elem("argc"), !IO),<br>
nl(!IO).</p>
<p>:-end_module<br>
</p>
<p>%%</p>
<p>$ ./map_test</p>
<p>const char*<br>
int</p>
<p>%%<br>
</p>
<p>Fabrice</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:0A280606-7937-41AA-B4BB-9B2540322678@gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Is there a more concise way of creating a map full of static data?
The best I have obtained is this:
<div class=""><br class="">
</div>
<div class=""><font class="" face="Courier New">default_typemap =
Out :-<br class="">
map.from_assoc_list([<br class="">
("i" - "int"),<br class="">
("psz" - "char*"),<br class="">
("v" - "void"),<br class="">
("pv" - "void*"),<br class="">
("c" - "char"),<br class="">
("sc" - "signed char"),<br class="">
("uc" - "unsigned char"),<br class="">
("pc" - "char*"),<br class="">
("ppc" - "char**"),<br class="">
("cpc" - "const char*"),<br class="">
("cppc" - "const char**")<br class="">
],<br class="">
Types),<br class="">
map.from_assoc_list([<br class="">
("argc" - "int"),<br class="">
("argv" - "ppc")<br class="">
],<br class="">
Vars),</font></div>
<div class=""><font class="" face="Courier New">:</font></div>
<div class=""><font class="" face="Courier New">: .. more code..</font></div>
<div class=""><font class="" face="Courier New">:</font></div>
<div class=""><br class="">
</div>
<div class="">Each backend coder that is a for typed language will
be providing an initial lookup of both variables and types so it
can infer necessary typing at code render time.</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">Sean</div>
<div class=""><br class="">
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.mercurylang.org">users@lists.mercurylang.org</a>
<a class="moz-txt-link-freetext" href="https://lists.mercurylang.org/listinfo/users">https://lists.mercurylang.org/listinfo/users</a>
</pre>
</blockquote>
</body>
</html>