[m-users.] Correct use of solutions.

Julien Fischer jfischer at opturion.com
Sat Jul 29 19:16:12 AEST 2023


Hi,

On Sat, 29 Jul 2023, Sean Charles (emacstheviking) wrote:

> I've been trying to produce a simple list of strings to output as the
> response to a command line argument request to list the supported
> targets of my transpiler, given I have a type and a predicate to
> return the printable string for the language I thought solutions/2 was
> my answer, but not so far! Again, it's a mixture of the terminology to
> my untutored brain and the lack of any really clear guiding examples,
> in Prolog this stuff is trivial!
> 
> 
>     % Does -T / --targets.
>     %
> :- type supported_target
>     --->    language_c
>     ;       language_python
>     ;       language_pythont
>     ;       language_js.
> 
> :- pred show_targets(io::di, io::uo) is det.
> 
> 300:show_targets(!IO) :-
> 301:    io.format("Available target languages:", [], !IO),
> 302:    solutions(
> 303:       (pred(A::out) is nondet :-
> 304:            target_name(_, A)


The predicate target_name/2 (below) only has a (in, out) mode.
According to that mode the first argument must be ground, which it
is not in the call above.

It's what following part of the error message is trying to tell you:

     command_line.m:304:   In clause for `show_targets(di, uo)':
     command_line.m:304:   in argument 1 of call to predicate
     command_line.m:304:   `command_line.target_name'/2:
     command_line.m:304:   mode error: variable `V_5' has instantiatedness `free',
     command_line.m:304:   expected instantiatedness was `ground'.

The problem can be fixed by adding the required mode declaration for
target_name/2, i.e.

      :- mode target_name(out, out) is multi.

(Compiling with -E, in this case, is probably more confusing then the
non-verbose error message.)

Julien.


More information about the users mailing list