Laborator 7

Laborator 7

:- op(300,xfx, was).

:- op(200,fx, the).

:- op(250,xfx, of).

john was the secretary of the department.

:- op(400, fx, deleting).

:- op(300, xfx, from).

:- op(350, xfx, gives).

:- op(375, fx, concatenating).

:- op(200 ,xfy ,and).

deleting _ from [] gives [].

deleting X from [X|T] gives NewT :- deleting X from T gives NewT.

deleting X from [H|T] gives [H|NewT] :- H\=X, deleting X from T gives NewT.

concatenating X and [] gives X.

concatenating [] and X gives X.

concatenating List1 and List2 gives Result :- is_list(List2),append(List1, List2, Result).

concatenating List1 and Expression gives Result :- concatenating Expression gives List2,

append(List1, List2, Result).

calculator :- repeat,

write('-------MENU-------'), nl,

write('1. Square a number : '), nl,

write('2. Exit'), nl,

write('Choose : '),

read(Z),

( Z = 2 -> !, fail ; true ), % fail without backtrack if Z = 3

write('Insert your number to square'),

read(K),

square(K, Result), write("Result="),write(Result),nl,

fail.

square(X, Y) :- Y is X*X.

writeList([]) :- !.

writeList([H|T]) :- write(H), write(" "), writeList(T).