coachhaa.blogg.se

Visual prolog expression is used when a formula is expected
Visual prolog expression is used when a formula is expected







visual prolog expression is used when a formula is expected

In this section, we will see how we can use files to read from, and write into the files. Program | ?- write('hello'),tab(15),write('world').hello worldyes| ?- write('We'),tab(5),write('will'),tab(5),write('use'),tab(5),write('tabs').We will use tabsyes| ?- Reading/Writing Files So it takes a number as an argument, and prints those many number of blank spaces. The tab() is one additional predicate that can be used to put some blank-spaces while we write something. compiling D:/TP Prolog/Sample_Codes/read_ for byte code.D:/TP Prolog/Sample_Codes/read_ compiled, 9 lines read - 1226 bytes written, 12 ms(15 ms) yes| ?- cube.Write a number: 2.Cube of 2: 8Write a number: 10.Cube of 10: 1000Write a number: 12.Cube of 12: 1728Write a number: 8.Cube of 8: 512Write a number: stop.(31 ms) yes| ?- The tab() Predicate Program cube :- write('Write a number: '), read(Number), process(Number).process(stop) :- !.process(Number) :- C is Number * Number * Number, write('Cube of '),write(Number),write(': '),write(C),nl, cube. Now let us see one example to see how read() works. The read() is generally used to read from console, but this can also be used to read from files. User can write something in the console, that can be taken as input and process it. The read() predicate is used to read from console. But if we use double quote (“string”), then it will return a list of ASCII values. And from this example, it is clear that, if we want to print some string on the console, we have to use single quotes (‘string‘). Program | ?- write(56).56yes| ?- write('hello').helloyes| ?- write('hello'),nl,write('world').helloworldyes| ?- write("ABCDE").yesįrom the above example, we can see that the write() predicate can write the contents into the console. Let us see some examples of write() function.

visual prolog expression is used when a formula is expected

This predicate takes the parameter as input, and writes the content into the console by default. To write the output we can use the write() predicate. So this will be the input and output handling techniques. So here we will see that writing and reading tasks in more detail using prolog. In some cases, we print something on the console, that are written in our prolog code. So far we have seen that we can write a program and the query on the console to execute. Using some external file to read lines and termsĬharacter manipulation for input and outputĬonsulting prolog files into other prolog program techniques. We will use some built in predicates to do these tasks, and also see file handling techniques.įollowing topics will be discussed in detail − In this chapter, we will see some techniques to handle inputs and outputs through prolog.









Visual prolog expression is used when a formula is expected