| /*
A library of useful LPA routines using built-in
LPA predicates */
/* 'str2list/3' turns a string(arg1) containing "separators"(arg2) into a list, while eliminating "white-space characters" as well, so that the output-list does not contain unnecessary spaces. If the "separator" is chosen to be a space, then the output-list becomes a list of words contained in the input; if any another separator is chosen, "most" spaces are again removed from the input... */ /* test:
str2list(Si,Sep,SLx):- nonvar(Si), strscan(SLx,Sep) <~ Si. strscan([],_):- skip_layout, eof, !.
/* del_all_subs/3 deletes all occurrences of a substring (arg2) in a string(arg1). It is (yet) another example of find/3's usefulness (a built-in LPA Prolog predicate): */ del_all_subs(SOURCE,SubStr,STRx):-
addvars/4 is called with arg2 = [], and arg1 = an atom-list containing _some_variables_ (signified by capital initial letters) and "constants" (=anything else); it then produces a new list (arg3) which is a copy of the original (arg1) except that all "variables" have been replaced by authentic (PROLOG-) variables, while arg4 is bound to a list of these variables in pairs of the form [ (ConstantAtomName-VARIABLE)... ] (exactly the same format as used by LPA Prolog's 'vars/2' - predicate); it also sorts the variables (removing duplicates) using sort/2 (a fast LPA Prolog built-in predicate): */ % NOTE: In this particular implementation,
the variables are also
addvars([],VarsList,[],VarsListX):- sort(VarsList,VarsListX),
!.
add_var((CONST,Var),Old,Old):- member((CONST,Var),Old), !.
/* test call:
X = [this,_3452414,isa,good,_3452414,and,_3452602,isa,_3452602]
,
| ?-
% strl2atoms/2 is simple but useful, converting LPA atoms to LPA strings -and vice versa: strl2atoms([],[]):- !.
% 'scan_sentence/3' takes a user-input(string) and turns it into % an atom-list (which also contains "true-Prolog-"variables). It % also produces a list of these "true-Prolog-"variables (arg3) as % pairs of the form [ (ConstantAtomName-VARIABLE)... ] (exactly % the same format as used by LPA Prolog's 'vars/2' - predicate); scan_sentence(String,AtomListWithVARS,VARlistX):-
|
|
OTHER PAGES in this site: |
"What's better than a good plate of spaghetti? Well... two good plates of spaghetti!"