ans_203a.pro

来自「prolog,人工智能推理程序,运行环境prolog」· PRO 代码 · 共 41 行

PRO
41
字号
/*
   Turbo Prolog 2.0, Answer to first Exercise on page 203.
   
   Copyright (c) 1986, 88 by Borland International, Inc
*/

Domains
  integerlist = integer*

Predicates
  get_integer_list ( integerlist )
  odd_list ( integerlist, integerlist )  

Clauses

  odd_list([], []) :- !.      % If the input list is empty, 
                              % the output must be empty.

  odd_list([H|T1], [H|T2]) :-
  	1 = H mod 2, ! ,      % Is the head odd? 
  	odd_list(T1, T2).     % If so, add it to the head 
  	                      % of the output list.

  odd_list([_|T1], T2) :-     % If the head is not odd,
  	odd_list(T1, T2).     % try the rest of the list!
  	
  get_integer_list([Int|T]) :-
  	write("Enter an integer: ") ,
  	readint(Int), ! ,
  	get_integer_list(T).
  get_integer_list([]).
  
Goal
  makewindow(1,2,3," Odd List ",0,0,25,80) ,
  write("Enter the integers to make a list.\n",
        " (Enter a non-integer to end list.)\n\n") ,
  get_integer_list(List),
  odd_list(List, Odds) ,
  write("\nThe whole list is: ",List,"\nThe odd list is  : ",Odds) ,
  write("\n\nPress any key...") ,
  readchar(_).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?