Changeset 4499 for trunk/examples

Show
Ignore:
Timestamp:
10/11/08 12:21:40 (3 months ago)
Author:
pmoura
Message:

Improved performance of generating and testing new object identifiers in the "roots" example.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/roots/classes.lgt

    r3179 r4499  
    170170    instance_base_name(i). 
    171171 
    172     instance_counter_(0). 
     172    instance_counter_(1). 
    173173 
    174174    valid_new_identifier(Identifier) :- 
     
    176176        retract(instance_counter_(Last)), 
    177177        ::instance_base_name(Base), 
    178         functor(Base, Functor, Arity), 
    179         number_codes(Arity, Codes), 
    180         atom_codes(Atom, Codes), 
    181178        repeat, 
    182179            next_integer(Last, Next), 
    183             number_codes(Next, Codes2), 
    184             atom_codes(Atom2, Codes2), 
    185             atom_concat(Functor, Atom2, Identifier), 
    186             atom_concat(Identifier, Atom, Prefix), 
    187             \+ {current_predicate(Prefix/_)}, 
    188             asserta(instance_counter_(Next)), 
     180            number_codes(Next, Codes), 
     181            atom_codes(Atom, Codes), 
     182            atom_concat(Base, Atom, Identifier), 
     183        \+ current_object(Identifier), 
     184        \+ current_category(Identifier), 
     185        \+ current_protocol(Identifier), 
     186        asserta(instance_counter_(Next)), 
    189187        !. 
    190188    valid_new_identifier(Identifier) :- 
    191189        once((atom(Identifier); compound(Identifier))), 
    192         functor(Identifier, Functor, Arity), 
    193         number_codes(Arity, Codes), 
    194         atom_codes(Atom, Codes), 
    195         atom_concat(Functor, Atom, Prefix), 
    196         \+ {current_predicate(Prefix/_)}. 
    197  
    198     next_integer(N, N1) :- 
    199         N1 is N + 1. 
     190        \+ current_object(Identifier), 
     191        \+ current_category(Identifier), 
     192        \+ current_protocol(Identifier). 
     193 
     194    next_integer(N, N). 
    200195    next_integer(N, N2) :- 
    201196        N1 is N + 1,