このディレクトリの索引
http://hibari.2ch.net/test/read.cgi/tech/1294061094/178
#  【質問テンプレ】  
#  [1] 授業単元:C  
#  [2] 問題文(含コード&リンク):  
#    行の数が同数である(csv1)と(csv2)を横に連結し(csv3)を作成作成せよ 
#  

'行の数が同数である(csv1)と(csv2)を横に連結し(csv3)を作成する'(_csv1,_csv2,_csv3) :-
        open(_csv1,read,Instream1),
        open(_csv2,read,Instream2),
        open(_csv3,write,Outstream),
        'Instream1とInstream2を横に連結しInstream3に書き出す'(Instream1,Instream2,Outstream),
        close(Outstream),
        close(Instream2),
        close(Instream1).

'Instream1とInstream2を横に連結しInstream3に書き出す'(Instream1,Instream2,Outstream) :-
        at_end_of_stream(Instream1),
        at_end_of_stream(Instream2),!.
'Instream1とInstream2を横に連結しInstream3に書き出す'(Instream1,Instream2,Outstream) :-
        get_line(Instream1,Line1),
        get_line(Instream2,Line2),
        'Outstreamに連結して書き出す'(Outstream,Line1,Line2),
        'Instream1とInstream2を横に連結しInstream3に書き出す'(Instream1,Instream2,Outstream).

'Outstreamに連結して書き出す'(Outstream,Line1,Line2) :-
        sub_atom(Line1,_,1,0,','),
        write_formatted(Outstream,'%t%t\n',[Line1,Line2]),!.
'Outstreamに連結して書き出す'(Outstream,Line1,Line2) :-
        \+(sub_atom(Line1,_,1,0,',')),
        write_formatted(Outstream,'%t,%t\n',[Line1,Line2]),!.