Re: [m-users.] Correct use of solutions.
Volker Wysk <[email protected]>
| Newsgroups | gmane.comp.lang.mercury.general |
|---|---|
| Message-ID | <[email protected]> |
Am Samstag, dem 29.07.2023 um 09:27 +0100 schrieb Sean Charles
(emacstheviking):
> 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)
> 305: ),
> 306: Targets
> 307: ),
> 308: io.print_line(Targets, !IO).
>
>
>
> :- pred target_name(supported_target, string).
> :- mode target_name(in, out) is det.
>
> target_name(language_c, "Vanilla C").
> target_name(language_python, "Vanilla Python").
> target_name(language_pythont, "Typed Python").
> target_name(language_js, "Vanilla JavaScript").
I don't know if there's a way to return (nondeterministically) all things of
an enumeration type. If there isn't, define one:
:- pred get_target(supported_target::out) is multi.
get_target(language_c).
get_target(language_python).
get_target(language_pythont).
get_target(language_js).
Then you can do:
solutions(
(pred(A::out) is multi :-
get_target(T),
target_name(T, A)
),
Targets)
Cheers,
Volker
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmTE2f4ACgkQ+K4ydFOs HoUzEQ/+JNaSuLPhGA5VUwpkpcZY80pd1zISvOreZWhX2JVtd6P7cFg4W5uUQl0q jujDt1aDEOCDCm6dlE7N8RU0SpDc2gkdY4zEtYxQYqo7jeKk7RPphL2aDdTZFS8r P8dkI+QaHy1RT1e5npWpoBk3+NSJtmZbcg4tNZr4HBJRIktGl439NAUh3/xIGMFI O4tlh3E9N6KtUuKnb+jWMN4s+cYLZgrix7hWq9hlwDQXZ5uD1Md2MhsAjv8bhcZP XW8Jf7oK7dRiFdDc+XcuBNmUf4yGlQf3W1Q5huzaQunp0TqRd7j/lcZfVWc5ElLp 6BS63+Z3GRyqWudrkd/Lkvf4K2XRwYVnOmz8Oby+NUioyD0RrhxM6WBFxNJkcyx9 Hs2SmjXeFYwaMsYu1xzOpLNdLgaFHnyzethXmJ7u4FQ8t9jPlFZfI+yOr2jvCmWL 3ObiQ9L1SpuVuQskmky6EpSvrVWizl2Kx4hOoOZ7/1kBzjPwfJhPpaklcwlLuPRm wyq6Xibpcg1qL0Is3j0Txgv2HOlVNuQa8SGmHXMNZQDzaXwtkmmDT4fKUK9rSR7K ZAsWytLZ+c1TeWr6ZQPo198T6PwH5B8H40kH4KEnequVOsCzsusvTl4MsxmxrkzI Ib9LLT8A3W4fNDfn194fBq8C/fH5dvAJcEuLw+N33JNGk1qyOQc= =sXd6 -----END PGP SIGNATURE-----