interesting increment_key failure
Alan Baljeu <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
In gensym.pl, we find this:
increment_key(Key, New) :-
flag(Key, Old, Old),
record_gensym(Key, Old),
succ(Old, New),
flag(Key, _, New).
In my program I have this:
make_id(N) :-
(var(N)
-> with_mutex('make_id', gensym:increment_key('ab_id_', N) ),
write(N), write(' '), flush
;true).
And when running my program, I get this as part of the output (I added the * for this email):
351 352 353 354 355 356 357 358 359 360 361 *362 357* 358 359 360 361 362 363 364 365 366 367 368 369 370
I could not fathom what causes the increment to go back 5 numbers, and was stuck.
Then on a whim, I guessed CHR was involved. succ(Old, New) bound New, triggered a wait, and the last flag()
didn't happen until the triggered constraint completed. The solution then is to introduce a new variable and delay
unification of New until the variable is recorded. Since increment_key is part of what's supposed to be an atomic
predicate (gensym), maybe this ought to be updated.
Alan Baljeu