09/07/10 03:33:50
>>419
% Prolog
t419_1 :- user_parameters(L),split(L,[','],L1),length(L1,2),write_formatted('%t %t\n',L1),!.
t419_1 :- tell(user_error),write(引数エラー),told.
t419_2 :-
user_parameters(L),
split(L,[','],L1),
length(L1,Len),
引数長さ検査(Len),
引数のすべてが整数(L1),
sum(L1,Sum),
write_formatted('引数に与えられた整数の合計は%tです\n',[Sum]).
引数の長さ検査(Len) :- Len > 0,!.
引数の長さ検査(Len) :- Len < 1,tell(user_error),write('引数がありません\n'),told,!,fail.
引数のすべてが整数([]) :- !.
引数のすべてが整数([N|R]) :- integer(N),引数のすべてが整数(R).
引数のすべてが整数([A|R]) :- tell(user_error),write('引数に整数でない%tがあります\n',[A]),told,!,fail.
sum([],0).
sum([N|R],X) :- sum(R,Y),X is N + Y.