print_file
Entity: predicate and function

print_string
Entity: predicate and function


Usage:
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 are strings or numbers.

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 Arg2.
<x:Argument>
<y:Argument>
 
Insert parameters in the link - These tags are the same as Insert, but they are more convenient for inserting parameters into links because they put the symbols ? and & when necessary.

For example: The result of <a href="/home.pro<x:1><y:2><y:3>"> will be <a href="/home.pro?a=1&b=2&c=3"> if Arg1, Arg2 and Arg3 are "a=1", "b=2" and "c=3".

<v:Argument:String>
<e:Argument:Number>
<l:Argument:Number>
<b:Argument:Number>
<p:Argument:Position>
<m:Argument:Mask=Value>
<o:Argument:Condition>
 
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.

If you want the opposite condition, use the symbol ^. For example: <^v:Argument> is the opposite of <v:Argument>.

If you want to write a hexadecimal number, use the symbols 0x. For example: <e:1:0x2a> is the same as <e:1:42>.

<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)
<e:Argument:Number>
 
Equal - the same as Variant, but it works only with numbers instead of Strings. For example: <e:1:zero> will return an error, while <v:1:zero> will work fine.
<l:Argument:Number>
 
Less than - the area is worked out if the Argument is a number which is less than Number.
<b:Argument:Number>
 
Bigger than - the area is worked out if the Argument is a number which is bigger than Number.
<p:Argument:Position>
 
Bit Position - the area is worked out if the bit is true. This bit which is at position Position in the number which is in Argument. Here the Position must be between 1 and 64.
<m:Argument:Mask=Value>
 
Bit Mask - the area is worked out if the bits of Argument that are defined with a Mask are equal to Value. For example: If Arg1 is 0x10 or 0x110 then <m:1:0x11=0x10> is true but <m:1:0x11=0x11> is not true.
<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: some or all.

The text after the tag <o:5:all> is worked out if all tags from the types v, e, l, b, p, m with argument 5 which are before <o:5:all> gave conditions which are true.

Instead the words some and all you can use the words or and and. The opposite condition to all is some not or not all. For example: <o:1:all> is the same as <^o:1:some not>.

The condition some is true if one of the previous conditions is true and its opposite condition is default. For example: <o:1:default> is the same as <^o:1:some>.

Look at the second example below.

<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("
      
<b:1:-2><l:1:10><o:1:all> -2 < <i:1> < 10 <v:1>
      
<^e:1:0><o:1:some> 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)