Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's a list of <em>atoms</em>, not strings. Strings in Prolog are usually <em>list of character codes</em>, expressed like </p> <pre><code>["f(a,45)", "f(b,13)", "f(c,12)"] </code></pre> <p>Anyway, apply a conversion to each element with a recursive function:</p> <pre><code>convert([], []). convert([Atom|Atoms], [Pair|Pairs]) :- convert_element(Atom, Pair), convert(Atoms, Pairs). </code></pre> <p>Instead of recursion you could use <a href="http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%27A.2%27,swi%28%27/doc/Manual/apply.html%27%29%29" rel="nofollow">maplist</a>/3 in this way:</p> <pre><code>convert(As, Ps) :- maplist(convert_element, As, Ps). </code></pre> <p>To convert an element, you need a parser. DCGs are convenient:</p> <pre><code>convert_element(Atom, [N, A]) :- atom_codes(Atom, Codes), phrase(("f(", atomc(Ac), ",", numc(Nc), ")"), Codes, []), atom_codes(A, Ac), number_codes(N, Nc). atomc(A) --&gt; ([C], {is_lowerc(C)}, atomc(Cs), {A = [C|Cs]}) ; {A = []}. numc(N) --&gt; ([C], {is_numc(C)}, numc(Cs), {N = [C|Cs]}) ; {N = []}. is_lowerc(C) :- C @&gt;= 0'a, C @=&lt; 0'z. is_numc(C) :- C @&gt;= 0'0, C @=&lt; 0'9. </code></pre> <p>test:</p> <pre><code>?- convert(['f(a,45)', 'f(b,13)', 'f(c,12)'],L). L = [[45, a], [13, b], [12, c]] . </code></pre> <p>atomc//1 &amp; numc//1 are expressed in a compact way, but are very simple recursive pattern matching procedures, i.e. atomc//1 could be</p> <pre><code>atomc([C|Cs]) --&gt; [C], {is_lowerc(C)}, !, atomc(Cs). atomc([]) --&gt; []. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload