Hi Alex,

Thanks a lot! I’ll make up my mind re. which one to use.

/Jon

On 4. Aug, 2015, at 15:42, Alexander Burger <a...@software-lab.de> wrote:

> Hi Jon,
> 
>> (client "www.some.com" 80 "page.html"
> 
>> Depending on the chunks I read, I want to write some lines to a
>> certain file on my disk, say "diskfile.txt", and now and then I also
>> want to write a little info to my console with (out NIL (prinl
>> SomeInfo)).
> 
> Good.
> 
>> Are there better/smarter ways to do this than to use (out
>> "+diskfile.txt" . . .) each time new lines shall be written to the
>> file?
> 
> I think that writing with (out "+..." ...) is perfectly all right. This
> is quite efficient, because the file is opened in append mode so that
> the file pointer is immediately at its end.
> 
> If you feel that re-opening the file each time is too expensive, you
> could also open all output channels in the beginning, and close them
> later, e.g.
> 
>   (client "www.some.com" 80 "page.html"
>      (out NIL  # Default to stdout
>         (let (A (open "file1")  B (open "file2"))
>            ...
>            (prinl "toStdout")
>            ...
>            (out A (prinl "to file1"))
>            ...
>            (out B (prinl "to file2"))
>            ...
>            (close A)
>            (close B) ) ) )
> 
> 
> If there is a possibility that the body of client is aborted before
> the ending 'close's are reached (e.g. a 'throw' or and error exit), then
> better use 'finally':
> 
>   (client "www.some.com" 80 "page.html"
>      (out NIL
>         (let? A (open "file1")
>            (finally (close A)
>               (let? B (open "file2")
>                  (finally (close B)
>                     ...
>                     (prinl "toStdout")
>                     ...
>                     (out A (prinl "to file1"))
>                     ...
>                     (out B (prinl "to file2")) ) ) ) ) ) )
> 
> You could 'bench'mark both versions, but I think there'll be no
> significant difference.
> 
> ♪♫ Alex

PԔ � &j)m����X�����zV�u�.n7�

Reply via email to