|
From: | Daniel Diaz |
Subject: | Re: Style guide / optimisation... |
Date: | Tue, 14 Oct 2014 08:57:21 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 |
Hi
You are right =.. is not very efficient. You can use call/2-N to avoid this http://www.gprolog.org/manual/html_node/gprolog042.html#sec194 Also the reverse is time and space consuming. This is strange because you use an accumulator: this is generally used to avoid append or reverse. In fact the accumulator is not needed and avoids the use of reverse. Here is the resulting version: file_codes(From, Out) :- open(From, read, S), file_read_buf(S, get_code, -1, Out), close(S). file_chars(From, Out) :- open(From, read, S), file_read_buf(S, get_char, end_of_file, Out), close(S). file_read_buf(S, Fetcher, Eof, Out) :- call(Fetcher, S, Chr), ( Chr \== Eof -> Out = [Chr|Out1], file_read_buf(S, Fetcher, Eof, Out1) ; Out = [] ). Daniel Le 14/10/2014 00:42, emacstheviking a écrit :
-- Ce message a été vérifié par MailScanner pour des virus ou des polluriels et rien de suspect n'a été trouvé. |
[Prev in Thread] | Current Thread | [Next in Thread] |