
efface(X, [X|T], T) :- true.
efface(X, [H|T], [H|Teff]) :- efface(X, T, Teff).

foreach([], _, []).
foreach([H|T], Function, [HErg|TErg]) :-
    X =.. [Function,H,HErg], 
    X,
    foreach(T, Function, TErg).

foreach(up_to(X, Y), Function, Erg) :-
    is_list(L, up_to(X, Y)),
    foreach(L, Function, Erg).



rm(E, E, []) :- !.
rm(_, H, [H]) :- !.

lmap([], _, _, []).
lmap([H|T], Function, Param, Erg) :-
    L1 <= append([Function], Param),
    L2 <= append(L1, [H, HErg]),
    X =.. L2,
    X,
    lmap(T, Function, Param, TErg),
    append(HErg, TErg, Erg).


lquadriere(X, [Y]) :- Y is X*X.
quadriere(X, Y) :- Y is X*X.

up_to(_,_).
is_list([To], up_to(To, To)) :- !.
is_list([From|T], up_to(From, To)) :- Next is From + 1, !, is_list(T, up_to(Next, To)).


to(From, _, From).
to(From, To, X) :- From < To, Next is From+1, to(Next, To, X).
sum(X, Y, Z) :- to(1,20,X), to(1,20,Y), Z is X+Y.


class(rectangle,
    public(
        x,
        y,
        w,
        h
)).

new(Classname, X) :- 
    class(Classname,_),!,
    write('new '),write(Classname),
    assert(object(Classname, X)),!.
new(Classname, _) :-
    \+ class(Classname,_),
    write('Exception in thread "main" java.lang.NoClassDefFoundError: '),
    write(Classname),
    nl,
    !,fail.

delete(Object) :-
    retract(object(_, Object)).



'<='(Erg, Function) :- 
    Function =.. List,
    append(List, [Erg], NewList),
    NewFunction =.. NewList,
    !,
    NewFunction.

%:-op(50, xfy, '->').
:-op(50, fx, delete).
:-op(50, fx, new).
:-op(100, xfy, '<=').
:-op(32, xfy, is_list).
:-op(25, xfy, up_to).

% vim: syntax=lprolog
