Prolog rule assertion with variable name

385 Views Asked by At

I try to assert some rules automatically in SWI-Prolog:

generate_rule_len(FG,SG):- 
    length(FG,L),length(SG,L0), 
    Head = input_len(FG,SG,FS,SS,X),
    Body = (length(FG,L1),L1 is L, length(SG,L2), L2 is L0, X = SS),
    % Rule = (Head :- Body), \+Rule,
    assertz(Head :- Body),
    append('rulesDB.pl'), 
    writeq(Head :- Body),write('.'),nl,
    told.

This works pretty fine, but the asserted result in the rulesDB.pl do not use the names of the variables FG,SG,FS,SS,Xthey are replaced with their memory position (?), this looks like:

input_len(_3078,_3080,_3082,_3084,_3086):-
   length(_3078,_3098),_3098 is 2,length(_3080,_3122),_3122 is 2,_3086=_3084. 

Is it possible to use the names of the variables instead?

Futhermore I want to prevent the duplication of generated rules. Therefore I tried Rule = (Head :- Body), \+Rule, but this give me an Undefined procedure: (:-)/2. Can anybody tell me what´s wrong with my code?

Thanks in advance!

0

There are 0 best solutions below