1% dal manuale di SWI: file://localhost/home/marco/lib/pl-5.7.12/doc/Manual/flags.html#current_prolog_flag/2
    2%The code below is a reliable and portable way to detect SWI-Prolog. 
    3%is_dialect(swi) :-
    4%        catch(current_prolog_flag(dialect, swi), _, fail).
    5
    6:- module(prolog_version,
    7    [is_dialect/1, is_unix/1]).    8
    9is_dialect(X) :-
   10        catch(current_prolog_flag(dialect, X), _, fail),
   11        !.
   12is_dialect(sicstus) :-
   13        catch(( current_prolog_flag(version, X),
   14                 atom_concat('SICStus',_,X)
   15              )
   16            , _, fail).
   17
   18
   19is_unix(X):-
   20    is_dialect(swi),!, current_prolog_flag(unix,X).
   21is_unix(X):-
   22    current_prolog_flag(host_type,HostType),
   23    % In SICStus, I suppose the host is Unix if the returned atom begins with 'x86'
   24    % but I am not sure this is the right way to do this check
   25    ((atom_concat(x86,_,HostType) ;
   26    % SWI recognizes Darwin (Mac) as Unix, so I will impose that also in SICStus
   27    % On Mac OSX 10.5.8 (Leopard) on MacBook (Intel), SICStus returns i38664-darwin-8.9.1
   28      atom_concat(_,B,HostType), atom_concat(darwin,_,B)
   29     )
   30    ->  X = true
   31    ;   X = false
   32    )