You could get the definition of foldl/4 from swi-prolog library. Try - on SWI console - to enter
?- edit(foldl/4).
then you can study/copy the definition, that I paste here
foldl(Goal, List, V0, V) :-
foldl_(List, Goal, V0, V).
foldl_([], _, V, V).
foldl_([H|T], Goal, V0, V) :-
call(Goal, H, V0, V1),
foldl_(T, Goal, V1, V).
I then tried in gprolog, and it's working:
| ?- consult('prolog/foldl').
compiling /home/carlo/prolog/foldl.pl for byte code...
/home/carlo/prolog/foldl.pl compiled, 12 lines read - 1464 bytes written, 22 ms
yes
| ?- lmax([1,4,2],X).
X = 4
yes
Of course a less general version is easier to get working
lmax([A,B|T], X):-
X #= max(A, Exp),
lmax([B|T], Exp).
lmax([X], X).
works as well, without foldl.