Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | String interpolation |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 0.1.0 |
SHA1 sum: | 95146f19b4ff6a59bdd3fb39aa9a42a5af00fead |
Author: | Michael Hendricks <michael@ndrix.org> |
Maintainer: | Michael Hendricks <michael@ndrix.org> |
Packager: | Michael Hendricks <michael@ndrix.org> |
Home page: | https://github.com/mndrix/interpolate |
Download URL: | https://github.com/mndrix/interpolate/archive/v0.1.0.zip |
Requires: | function_expansion |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
0.1.0 | 95146f19b4ff6a59bdd3fb39aa9a42a5af00fead | 1 | https://github.com/mndrix/interpolate/archive/v0.1.0.zip |
908a2659544fb17441edfe81b5d862bc0c830c43 | 113 | https://github.com/mndrix/interpolate/archive/v0.1.0.zip | |
0.0.1 | 45739f44c65389537a1fdf838d244ae05133258c | 21 | http://packs.ndrix.com/interpolate/interpolate-0.0.1.tgz |
:- use_module(library(interpolate)). main :- Name = "Johannson", Time = evening, writeln('Hello Mr. $Name. Isn''t it a fine $Time?').
Many languages allow one to construct strings using a built-in, miniature template language in which the values of variables are inserted into an otherwise static template. It's often called string interpolation.
This module provides similar functionality for Prolog. It uses the
same syntax as Unix shell, Perl, PHP, Tcl, etc. Namely, a local
variable name prefixed with $
. Interpolation is supported in all of
the following string types:
double_quotes
flag)Internally the string is constructed with format/2. If a variable's value is a list of codes or a list of chars (single letter atoms), we use the ~s format sequence; otherwise, ~p. This allows compound terms to define their own string representation via the portray/1 hook.
If a string refers to a variable that doesn't exist, that portion of the string is left alone. This behavior may change. In the future it may generate a warning.
Because interpolation hides variables inside of strings, the compiler can't detect that they're being used. This often results in unwanted singleton warnings. You can some choices in how to resolve the problem:
library(func)
string interpolation:- style_check(-singleton).
Once I add quasiquotation support to this module, that will be another option.
Using SWI-Prolog 7.1.1 or later:
?- pack_install(interpolate).
This module uses semantic versioning.
Source code available and pull requests accepted at http://github.com/mndrix/interpolate
Pack contains 6 files holding a total of 7.9K bytes.