Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!uunet!mcsun!unido!ecrc!ecrc!thom From: thom@ecrc.de (Thom Fruehwirth) Newsgroups: comp.lang.prolog Subject: Re: why do i need an extra carridge return? Message-ID: <1991Apr30.143208.13228@ecrc.de> Date: 30 Apr 91 14:32:08 GMT References: <9104262300.AA24421@thunder.LakeheadU.Ca> <1991Apr29.102537.12322@canon.co.uk> Sender: news@ecrc.de Reply-To: thom@ecrc.de (Thom Fruehwirth) Organization: ecrc Lines: 30 Bill Imlah proposes > read_line(L):- > get_chars([],L). > > get_chars(IN,OUT):- > get0(C), > get_rest(C,IN,OUT). > > get_rest(10,L,L):- > !. > get_rest(C,IN,[C|OUT]):- > get_chars(IN,OUT). Observing that the first argument of get_chars/2 will be always bound to '[]' when called by read_line/1, we can remove this argument. As get_chars/2 is defined by a single clause, we can unfold it away: read_line(L):- get0(C), get_rest(C,L). get_rest(10,[]):- !. get_rest(C,[C|OUT]):- get0(C1), get_rest(C1,OUT). thom