条件を満たす行を取り除く
Posted feedbacks - Prolog
とりあえず、ライブラリを使わずに。
1 2 3 4 5 6 7 8 | lineLoop:-peek_char(end_of_file).
lineLoop:- line(B),(B=['#'|_]->write('');string_to_list(Str,B),write(Str)),lineLoop.
line([]):-peek_char(end_of_file).
line(['\n']):-peek_char('\n'),get_char(_).
line([C|Cs]):-get_char(C),line(Cs).
:- prompt(_,''),lineLoop, halt.
|
read_line_to_codeを使うと、ユーザー入力にした場合、入力を待ってくれないのをどうすればよいのか判らないのです。
1 2 3 4 5 6 | lineLoop(Str):-
read_line_to_codes(Str,Line),
(Line=[35|_]->write("");
(not(Line=end_of_file)->string_to_list(S,Line),writeln(S),lineLoop(Str); true)).
:- prompt(_,''),current_stream(_,'read',Str),lineLoop(Str), halt.
|





にしお
#3366()
Rating0/0=0.00
サンプル入力
サンプル出力[ reply ]