.


:




:

































 

 

 

 


-




read. ; ; . ( ):

?- read(X). |: atom. X = atom.

?- read(X). |: 123. X = 123.

?- read(X). |: 1+ |: 2+ |: 3. X = 1+2+3.

?- read(X). |: .(1, []). X = [1].

?- read([X, Y]). |: [1, 2]. X = 1, Y = 2.

?- read([X, Y]). |: 1. false.

?- read(E), X is E. |: 1 + 2. E = 1+2, X = 3.

write. . . :

?- write(atom). atom true.

?- write('Hello World!'). Hello World! true.

?- write('Hello'), write(' World!'). Hello World! true.

?- write(1 + 2 * 3). 1+2*3 true.

?- write(X). _G283 true.

write_canonical. :

?- write_canonical(atom). atom true.

?- write_canonical('Hello World!'). 'Hello World!' true.

?- write_canonical('Hello'), write_canonical(' World!'). 'Hello'' World!' true.

?- write_canonical(1 + 2 * 3). +(1,*(2,3)) true.

?- write_canonical(X). _ true.

- , ; , . get_char. . :

?- get_char(X). |: a X = a

?- get_char(X). |: A X = 'A'.

?- get_char(X). |: abc X = a.

?- get_char(X). |: 123 X = '1'.

?- get_char(X), get_char(Y). |: abc X = a, Y = b.

?- get_char(X), get_char(Y). |: a X = a, Y = '\n'.

get_char , get_char end_of_file ( , Control + D).

put_char. , . :

?- put_char(a). a true.

?- put_char(A). ERROR: put_char/1: Arguments are not sufficiently instantiated

?- put_char('A'). A true.

?- put_char(abc). ERROR: put_char/1: Type error: `character' expected, found `abc'

?- put_char('\n'). true.

?- put_char(65). A true.

nl, .

( ):

get_line(L):- get_char(C), get_rest_of_line(C, L).

get_rest_of_line(C, L):- C = '\n',!, L = [].

get_rest_of_line(C, L):- get_line(M), L = [C | M].

?- get_line(L). |: Hello! L = ['H', e, l, l, o,!].

?- get_line(L). |: L = [].

:

put_line([]):- nl.

put_line([C | L]):- put_char(C), put_line(L).

?- put_line(['H', e, l, l, o,!]). Hello! true.

?- put_line([]). true.

- , , . atom_chars number_chars . :

?- atom_chars(abc, X). X = [a, b, c].

?- atom_chars(X, [a, b, c]). X = abc.

?- atom_chars(X, ['A', b, c]). X = 'Abc'.

?- atom_chars(X, [a, 'B', c]). X = aBc.

?- atom_chars(X, a). ERROR: atom_chars/2: Type error: `list' expected, found `a'

?- number_chars(12.3, X). X = ['1', '2', '.', '3'].

?- number_chars(X, ['1', '2', '.', '3']). X = 12.3.

?- number_chars(X, ['a', 'b', 'c']). ERROR: number_chars/2: Syntax error: Illegal number





:


: 2015-10-01; !; : 331 |


:

:

, ,
==> ...

1509 - | 1490 -


© 2015-2024 lektsii.org - -

: 0.011 .