% If you have your prolog rules in file "filename.pl", to load it in the % prolog interpreter, key in : % prolog -l filename.pl % +,? are just symbolic, not to be used in implementing predicates % Prolog has in-built predicates number() and var() for checking numbers and variables repectively % Note that the following functions can be implemented in different and better ways % The car function in prolog car([X|L],X). % The cdr function in prolog cdr([X|L],L). % A function that pushes X onto a list as num(X) % Example invokation : push(1,[2,3,4], Output). push(X,L,[num(X)|L]). % A function that returns the first "number" on the input list firstnumber([X|L],X):-number(X). firstnumber([X|L],Y):- firstnumber(L,Y). % A function that returns a list of all the numbers contained in the input list % Example invokation : numbers([1,2,3,a,b,c,+], [], Output). numbers([], Accum, Accum). numbers([X|L], Accum, Output):- number(X), numbers(L, [Accum|X], Output). numbers([X|L], Accum, Output) :- numbers(L, Accum, Output). % A function that returns two lists, one containing all the operators and the other containing all non-operators contained in the input list % Example invokation : r(Output1, Output2, [], [], [1,2,3,a,b,+,-,a]). r(Ops, Args, Ops, Args, []). r(Output1, Output2, Ops, Args, [Top|Stack]):- operator(Top), r(Output1, Output2, [Top|Ops], Args, Stack). r(Output1, Output2, Ops, Args, [Top|Stack]):- r(Output1, Output2, Ops, [Top|Args], Stack).