Entity: predicate and function

Entity: predicate and function

print_file(Formatting_File_Name, Arg1, Arg2, ...)
Result is print_file(Formatting_File_Name, Arg1, Arg2, ...)
print_string(Formatting_String, Arg1, Arg2, ...)
Result is print_string(Formatting_String, Arg1, Arg2, ...)

These predicates (functions) are unique for Strawberry Prolog. If you know the language C then you will notice that these predicates work similarly to the function printf but they are much more powerful than printf. The first argument of these predicates is the formatting string (or file). This string will be worked out after being modified by the arguments. All arguments have to be strings.

We will describe the function print_string. The predicate print_string does the same but the result is printed in the standard output instead to be returned as a result. The function and the predicate print_file do the same as print_string but the first argument is not the formatting string but the name of a file which contains this string.

The formatting string is usually in HTML format (or the file is HTML file). That is why the formatting words look like tags. Here is the list of all formatting words and a description on how they affect the output.

<i:Argument> Insert - This tag will be replaced with the argument with number Argument. For example <i:2> will be replaced with the second argument and <i:0> will be replaced with the formatting string (or with the name of formatting file in the case of print_file).
These tags show the beginning of the area which will be worked out only under certain condition. The end of this area could be represented with the tag <v:Argument> or with the other condition tag with the same Argument. You can nest such areas and to use the tag <i:Argument> inside them.
<v:Argument:String> Variant - the area is worked out if the Argument is equal to the String. (Do not put quotes around the string in the tag)
<n:Argument:String> Not Variant - the area is worked out if the Argument is not equal to the String.
<l:Argument:Number> Less than - the area is worked out if the Argument is a string in which a number is written and if this number is less than Number.
<b:Argument:Number> Bigger than - the area is worked out if the Argument is a string in which a number is written and if this number is bigger than Number.
<o:Argument:Condition> Boolean Condition - the area is worked out if some Boolean condition is satisfied between the previous tags with the same Argument. The Condition can be one of the following words: and, or, some not or default. The text after the tag <o:5:and> is worked out if all tags from the types v, n , b, l with argument 5 which are before <o:5:and> gave conditions which are true. Instead the word and you can use the word all. The opposite condition to and is some not. You can use instead of the combination some not the combinations not all or only some. The condition or is true if one of the previous conditions is true and its opposite condition is default. Look at the second example
<r:Argument> Replace - shows the beginning of an area in which the string Argument will be replaced with the string which is in the next argument (i.e. Argument+1 string). The end of area can be shown as <r:>. You cannot nest the replace areas but you can combine them with Insert and Variant tags.
<t: Tag - This will be replaced with <. For example if you want to work out <i:1> then you have to insert in the formatting string <t:i:1>.

Example 1:

?- print_string("<r:1>Text <i:3><r:>", "Text", "Nonsense", "Text").

In output: Nonsense Text

Example 2:

?- print_string("
<n:1:0><o:1:and>and <i:1> not zero
<o:1:default>This will not be printed<v:1>","-1").

In output: -2<-1<10
and -1 not zero

Look at the example:
print_file.spj (in folder Examples)