|
/* PDC/Visual Prolog predicates
emulating LPA Prolog predicates */
/* DESCRIPTION: This file contains some new predicates for PDC/Visual
Prolog 5.* which emulate precisely certain built-in
LPA Win Prolog 4.1 predicates of exactly the same functors
and arities, as well as "flow patterns" (structures of inputs
and outputs allowed in their arguments). The intent is not
to... discourage the use of LPA Prolog, but -on the contrary- to encourage
the optimal use of both these good compilers, offering some help
to people who (like myself) wish to take advantage of both, and/or have
written code in one compiler which is tedious to translate into the other.
In any case -to be fair- many
LPA Prolog analogs of PDC/Visual Prolog
predicates have been listed, in another page of this site. */
% cat/3 emulates precisely the LPA-Prolog
built-in predicate
% of the same functor and arity; it is essentially
a somewhat
% more flexible "concat_string" type of function;
takes (any)
% number of input-strings ( list arg1) and concatenates
them
% producing a single output-string(arg2) as well
as (in arg3)
% a list of (integer-)positions that describe
the "structure"
% of the string_in_arg2. In the latter flow-variant
-(o,i,i),
% we can split any string into many substrings
of given length:
GLOBAL PREDICATES
cat(SL,STR,IL) -(i,o,o),(i,o,i) %EXACT
SIMULATION of LPA Prolog's cat/3
cat(SL,STR,STR,IL) -(i,i,o,o),(i,i,o,i) %
"Augmented" SIMULATION of LPA's cat/3
CLAUSES
cat([],"",[]):- !.
cat([S|SL],Sx,[Lenx|LenL]):- bound(S), str_len(S,Lenx),
cat(SL,Sx1,LenL), concat(S,Sx1,Sx), !.
cat([S|SL],Si,[Len|LenL]):- bound(Len), bound(Si),
frontstr(Len,Si,S,More), !, cat(SL,More,LenL).
% cat/4
also emulates built-in LPA-Prolog predicate
cat/3, while
% offering one additional feature: - It can
include an additional
% "separator-string" between each two pair
of input-strings
% when concatenating them. (If this separator-string
is "", then
% this predicate is exactly similar in behaviour
to LPA's cat/3).
cat([],_,"",[]):- !.
cat([S],_,S,[Lenx]):- bound(S), str_len(S,Lenx), !.
cat([S|SL],Sep,Sx,[Lenx|LenL]):- bound(S), str_len(S,Lenx),
cat(SL,Sep,Sx1,LenL), concat(S,Sep,Sa), concat(Sa,Sx1,Sx),
!.
/*
cat([S|SL],Sep,Si,[Len|LenL]):- bound(Len), bound(Si),
frontstr(Len,Si,S,More), !, cat(SL,Sep,More,LenL).
*/
% cat/4 was written with the need of writing
lists in mind
% (e.g. lists of words separated by commas
or spaces)
% nonvar(i)
GLOBAL PREDICATES
nonvar(STRING) -(i)
nonvar(INTEGER) -(i)
/* ... and/or other domains of your choice... */
CLAUSES
nonvar(VAR):- bound(VAR).
% file/3
GLOBAL PREDICATES
file(STRING,INTEGER,unsigned) -(i,i,o)
CLAUSES
file(File,Type,Result):- Type=-1, existfile(File), Result=1,
!;
Type = -4, filesize(File,Result), !.
% number_string/2
GLOBAL PREDICATES
number_string(STRING,INTEGER) -(i,o),(o,i),(i,i)
CLAUSES
number_string(Num,STR):- str_int(STR,Num).
% len.2
GLOBAL PREDICATES
len(STRING,unsigned) -(i,o)
CLAUSES
len(Str,Len):- nonvar(Str), str_len(Str,L), Len=L, !
% upper_lower(i,o),(o,i),(i,i)
GLOBAL PREDICATES
lwrupr(STRING,STRING)
CLAUSES
lwrupr(LOW,UP):- upper_lower(UP,LOW).
|