[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

open ... :direction :output :if-exists :append

Jim Newton

2/1/2016 9:47:00 AM

What would someone suspect that (OPEN path :direction :output :if-exists :append)
in the case that the file does not already exist? Apparently, it signals an error. However, if I
include :if-does-not-exist :create, it works fine.

This seems strange. It would seem to me that if the file does not exist then :if-exists should be ignored.
Right? So that if the file does not exist, (OPEN path :direction :output)
and (OPEN path :direction :output :if-exists :append) should be equivalent???

Here is what I get:

(OPEN #P"/tmp/1.data" :direction :output :if-exists :append)
error opening #P"/tmp/1.data": No such file or directory
[Condition of type SB-INT:SIMPLE-FILE-ERROR]

Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1012F80003}>)

Backtrace:
0: (SB-IMPL::SIMPLE-FILE-PERROR "error opening ~S" #P"/tmp/1.data" 2)
1: ((FLET SB-IMPL::VANILLA-OPEN-ERROR :IN OPEN))
2: (OPEN #P"/tmp/1.data" :DIRECTION :OUTPUT :ELEMENT-TYPE BASE-CHAR :IF-EXISTS :APPEND :IF-DOES-NOT-EXIST NIL :EXTERNAL-FORMAT :DEFAULT :CLASS SB-SYS:FD-STREAM)


4 Answers

rpw3

2/1/2016 11:43:00 AM

0

Jim Newton <jimka.issy@gmail.com> wrote:
+---------------
| What would someone suspect that (OPEN path :direction :output
| :if-exists :append) in the case that the file does not already
| exist? Apparently, it signals an error.
+---------------

Exactly as the CLHS mandates! Did you read it very carefully?

http://www.lispworks.com/documentation/HyperSpec/Body/...
Function OPEN

There are some subtle interactions between the default behavior
of :IF-DOES-NOT-EXIST and the presence of :IF-EXISTS :APPEND.

+---------------
| However, if I include :if-does-not-exist :create, it works fine.
+---------------

Again, exactly as the CLHS mandates.

+---------------
| This seems strange. It would seem to me that if the file
| does not exist then :if-exists should be ignored. Right?
+---------------

Wrong. The CLHS is very clear on what should happen, even if
it doesn't agree with your personal notion of "strange". ;-}

+---------------
| So that if the file does not exist, (OPEN path :direction :output)
| and (OPEN path :direction :output :if-exists :append) should
| be equivalent???
+---------------

Again, incorrect. The CLHS is *quite* explicit that these
two cases are *not* the same.

Read the paragraph on :IF-DOES-NOT-EXIST again very carefully,
especially noting the various semicolon-separated cases and the
conjuctions "or" and "and" within each case. It may help you to
build a truth table [or Karnaugh map] of the various cases from
the prose text. If you do that you will see that the case you
initially describe is behaving just as the spec requires.


-Rob

-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw...
San Mateo, CA 94403

Ben Bacarisse

2/1/2016 11:54:00 AM

0

Jim Newton <jimka.issy@gmail.com> writes:

> What would someone suspect that (OPEN path :direction :output
> :if-exists :append) in the case that the file does not already exist?
> Apparently, it signals an error. However, if I include
> :if-does-not-exist :create, it works fine.
>
> This seems strange. It would seem to me that if the file does not
> exist then :if-exists should be ignored. Right? So that if the file
> does not exist, (OPEN path :direction :output) and (OPEN path
> :direction :output :if-exists :append) should be equivalent???

That's certainly only logical way to look at it. But it's not the only
way. One could argue that the presence of :if-exists :append makes a
different default behaviour for :if-does-not-exist more useful.
Specifying :append makes non-existence more of an error than otherwise.

<snip>
--
Ben.

Jim Newton

2/1/2016 1:25:00 PM

0



>
> Read the paragraph on :IF-DOES-NOT-EXIST again very carefully,
> especially noting the various semicolon-separated cases and the
> conjuctions "or" and "and" within each case. It may help you to
> build a truth table [or Karnaugh map] of the various cases from
> the prose text. If you do that you will see that the case you
> initially describe is behaving just as the spec requires.
>

Thanks for the clarification. I still think it is unintuitive. Especially given the following
sentence in the spec. >>> if-exists specifies the action to be taken if direction is :output or :io and a file of the name filespec already exists.

Yes yes yes it is clarified elsewhere. It seems like if-exists should describe action to take when
the file exists. In this case it seems that if-exists is also describing the action to take when the file does not exist.

Ben Bacarisse

2/1/2016 3:24:00 PM

0

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Jim Newton <jimka.issy@gmail.com> writes:
>
>> What would someone suspect that (OPEN path :direction :output
>> :if-exists :append) in the case that the file does not already exist?
>> Apparently, it signals an error. However, if I include
>> :if-does-not-exist :create, it works fine.
>>
>> This seems strange. It would seem to me that if the file does not
>> exist then :if-exists should be ignored. Right? So that if the file
>> does not exist, (OPEN path :direction :output) and (OPEN path
>> :direction :output :if-exists :append) should be equivalent???
>
> That's certainly only logical way to look at it. But it's not the
> only

I meant "That's certainly _one_ logical way to look at it". I usually
leave my may typos as exercises for the read but this one altered the
meaning too much!

> way. One could argue that the presence of :if-exists :append makes a
> different default behaviour for :if-does-not-exist more useful.
> Specifying :append makes non-existence more of an error than otherwise.
>
> <snip>

--
Ben.