fix buggy jubk

This commit is contained in:
Vítor Santos Costa 2018-11-06 22:47:44 +00:00
parent 54e16f6f19
commit 8d226bbfde

View File

@ -2,10 +2,10 @@
* @file gensym.yap * @file gensym.yap
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan> * @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
* @date Tue Nov 17 18:37:13 2015 * @date Tue Nov 17 18:37:13 2015
* *
* @brief Generate a new atom. * @brief Generate a new atom.
* *
* *
*/ */
:- module(gensym, [ :- module(gensym, [
init_gensym/1, init_gensym/1,
@ -20,7 +20,7 @@
* *
* Predicates to create new atoms based on the prefix _Atom_. * Predicates to create new atoms based on the prefix _Atom_.
* They use a counter, stored as a * They use a counter, stored as a
* dynamic predicate, to construct the atom's suffix. * dynamic predicate, to construct the atom's suffix.
* *
*/ */
@ -28,21 +28,20 @@
:- dynamic gensym_key/2. :- dynamic gensym_key/2.
init_gensym(Key) :- init_gensym(Key) :-
assert(gensym_key(Atom,0) ). retractall(gensym_key(Key,_)),
assert(gensym_key(Key,0) ).
gensym(Atom, New) :- gensym(Key, New) :-
retract(gensym_key(Atom,Id)), !, retract(gensym_key(Key,Id)), !,
atomic_concat(Atom,Id,New), atomic_concat(Key,Id,New),
NId is Id+1, NId is Id+1,
assert(gensym_key(Atom,NId)). assert(gensym_key(Key,NId)).
gensym(Atom, New) :- gensym(Atom, New) :-
atomic_concat(Atom,1,New), atomic_concat(Atom,0,New),
assert(gensym_key(Atom,2)). assert(gensym_key(Atom,1)).
reset_gensym(Atom) :- reset_gensym(Atom) :-
retract(gensym_key(Atom,_)). retract(gensym_key(Atom,_)).
reset_gensym :- reset_gensym :-
retractall(gensym_key(_,_)). retractall(gensym_key(_,_)).