how to do simple exclusive open -- don't use negative logic
[1/4] from: arolls:bigpond:au at: 7-Jun-2001 3:39
I would suggest you *not* use negative logic,
as in:
either not exists? semaphore-port [ ; ... does semaphore already exists?
The above question is incorrectly placed, I think.
Anton.
[2/4] from: petr:krenzelok:trz:cz at: 6-Jun-2001 20:44
----- Original Message -----
From: "Anton" <[arolls--bigpond--net--au]>
To: <[rebol-list--rebol--com]>
Sent: Wednesday, June 06, 2001 7:39 PM
Subject: [REBOL] Re: how to do simple exclusive open -- don't use negative
logic
> I would suggest you *not* use negative logic,
> as in:
>
> either not exists? semaphore-port [ ; ... does semaphore already exists?
>
> The above question is incorrectly placed, I think.
Ah, maybe my non english background?
Well, I put my brain into more thinking and built more robust solution. Now
pairs of file semaphores and their opened ports are stored:
lock: context [
sem-port-spec: func [path file-name][to-file join to-string path head
change find copy file-name "." ".SEM"]
locked: copy []
get-lock: func [path file-name][
semaphore: sem-port-spec path file-name
; file doesn't exist, or does exist, but semaphore can be closed
(dead one)
either all [(not exists? semaphore) (not remove-sem-file semaphore)][
; store pair of file-name, opened port
append locked semaphore
append locked open/new/direct semaphore
true
][false] ; can't get lock, sorry ...
]
close-lock: func [path file-name][
semaphore: sem-port-spec path file-name
if found? find locked semaphore [
close select locked semaphore
remove remove find locked semaphore
]
either remove-sem-file semaphore [true][false]
]
remove-sem-file: func [semaphore][either not error? try [delete
semaphore][true][false]]
]
usage:
lock/get-lock %whatever-path "file-name.txt"
print lock/locked
lock/close-lock %whatever-path "file-name.txt
btw: how would you put following line into "non negative" one? :-))
either all [(not exists? semaphore) (not remove-sem-file semaphore)][
either not any [(exists? semaphore) (remove-sem-file semaphore)] ???
If so, I like the first one anyway :-)
Cheers,
-pekr-
[3/4] from: petr:krenzelok:trz:cz at: 6-Jun-2001 21:28
----- Original Message -----
From: "Anton" <[arolls--bigpond--net--au]>
To: <[rebol-list--rebol--com]>
Sent: Wednesday, June 06, 2001 7:39 PM
Subject: [REBOL] Re: how to do simple exclusive open -- don't use negative
logic
> I would suggest you *not* use negative logic,
> as in:
>
> either not exists? semaphore-port [ ; ... does semaphore already exists?
>
> The above question is incorrectly placed, I think.
I am not sure if you mean it's english meaning, so if so, what about this
one?:
->> doesn't: func [arg][not arg]
->> exist?: :exists?
->> if doesn't exist? %/C/bbb.txt [print "No such file"]
No such file
:-)
-pekr-
[4/4] from: arolls::bigpond::net::au at: 7-Jun-2001 17:03
No no!
:-)
I definitely meant that this would be better:
either exists? semaphore-port [
; semaphore exists
][
; no semaphore
]
Anton.