


In this case, we can say that prolog allow to writes two ‘write’ commands one after the other and the output is continuous, which means it will not take space or comma automatically. Let us see how to use two write/1 commands in prolog, o write(m),write(n). This is a case where we can give values to the term, here we given the value to the E and that will also be shown in the output because it contains the variable. Now we will see when it will returns the contains variables, o write(D).Īs above when we call the variable it will return the contains variable with its value prefix with _(underscore). If we want elements to be arranged in a user-friendly format then we can follow the above examples as per the needs. The above query will give output as shown above. This one does the rounding, and allows trailing zeroes, but I can find no way to force right alignment using the "format" function, and I can't find a way to combine the functionality of writef (alignment) with format (rounding and zero display).The working of built-in predicate write/1 is as following, it taking terms and that will print on the screen with user-friendly notations so that user can understand it. Also, I have to do the rounding manually before passing the rounded value to writef(). ^^^ This comes very close to what I want, but unfortunately it does display any trailing zeroes (it will always omit them). I can accomplish some of these things individually, but not all at once. For example: 2.500 (trailing zeroes displayed)ģ4.432 (rounded from a much longer decimal value)Īll 3 are right aligned in a 7 character wide space, with 3 decimal places displayed (even when those are zero). My desire is to be able to format numbers that are output such that I am controlling total # decimal digits displayed and also right aligning the numbers in a given character width. I have spent a significant amount of time in the SWI-Prolog documentation and am getting nowhere.
