atomic_list_concat/2 and fix some reverse mode ops in atom_concat/3.

This commit is contained in:
Vitor Santos Costa 2009-11-23 10:13:55 +00:00
parent 025ee58f58
commit 2d2fb30167

View File

@ -259,8 +259,7 @@ atom_concat(X,Y,At) :-
atom_concat([X,Y],At) atom_concat([X,Y],At)
; ;
atom(At) -> atom(At) ->
atom_length(At,Len), '$atom_contact_split'(At,X,Y)
'$atom_contact_split'(At,0,Len,X,Y)
; ;
var(At) -> var(At) ->
'$do_error'(instantiation_error,atom_concat(X,Y,At)) '$do_error'(instantiation_error,atom_concat(X,Y,At))
@ -268,6 +267,28 @@ atom_concat(X,Y,At) :-
'$do_error'(type_error(atom,At),atomic_concant(X,Y,At)) '$do_error'(type_error(atom,At),atomic_concant(X,Y,At))
). ).
'$atom_contact_split'(At,X,Y) :-
nonvar(X), !,
atom_codes(At, Codes),
atom_codes(X, Xs),
lists:append(Xs,Ys,Codes),
atom_codes(Y, Ys).
'$atom_contact_split'(At,X,Y) :-
nonvar(Y), !,
atom_codes(At, Codes),
atom_codes(Y, Ys),
once(lists:append(Xs,Ys,Codes)),
atom_codes(Y, Ys).
'$atom_contact_split'(At,X,Y) :-
atom_codes(At, Codes),
'$split_codes'(Codes, Xs, Ys),
atom_codes(X, Xs),
atom_codes(Y, Ys).
atomic_list_concat(L,At) :-
atomic_concat(L, At).
atomic_concat(X,Y,At) :- atomic_concat(X,Y,At) :-
( (
nonvar(X), nonvar(Y) nonvar(X), nonvar(Y)
@ -279,10 +300,7 @@ atomic_concat(X,Y,At) :-
'$atom_contact_split'(At,0,Len,X,Y) '$atom_contact_split'(At,0,Len,X,Y)
; ;
number(At) -> number(At) ->
number_codes(At,Codes), '$number_contact_split'(At,X,Y)
lists:append(X0,Y0,Codes),
name(X,X0),
name(Y,Y0)
; ;
var(At) -> var(At) ->
'$do_error'(instantiation_error,atomic_concat(X,Y,At)) '$do_error'(instantiation_error,atomic_concat(X,Y,At))
@ -290,13 +308,23 @@ atomic_concat(X,Y,At) :-
'$do_error'(type_error(atomic,At),atomic_concant(X,Y,At)) '$do_error'(type_error(atomic,At),atomic_concant(X,Y,At))
). ).
'$atom_contact_split'(At,Len,Len,X,Y) :- !, '$number_contact_split'(At,X,Y) :-
'$atom_split'(At,Len,X,Y). nonvar(X), !,
'$atom_contact_split'(At,Len1,_,X,Y) :- number_codes(At, Codes),
'$atom_split'(At,Len1,X,Y). name(X, Xs),
'$atom_contact_split'(At,Len1,Len,X,Y) :- lists:append(Xs,Ys,Codes),
Len2 is Len1+1, name(Y, Ys).
'$atom_contact_split'(At,Len2,Len,X,Y). '$number_contact_split'(At,X,Y) :-
nonvar(Y), !,
number_codes(At, Codes),
name(Y, Ys),
once(lists:append(Xs,Ys,Codes)),
name(Y, Ys).
'$number_contact_split'(At,X,Y) :-
number_codes(At, Codes),
'$split_codes'(Codes, Xs, Ys),
name(X, Xs),
name(Y, Ys).
sub_atom(At, Bef, Size, After, SubAt) :- sub_atom(At, Bef, Size, After, SubAt) :-
% extract something from an atom % extract something from an atom