[erlang-questions] ?DATE and ?TIME MACROs

Mats Cronqvist <>
Tue Oct 7 21:14:15 CEST 2008


Kenneth Lundin wrote:
> [...]
> So in summary. The CompileDateAndTime is a little unsafe to rely on
> because it might be changed.
> I actually don't understand why you are interested in ?DATE and ?TIME
> macros or similar info [...]
  here's one use case. distel contains this snippet;

%%% reload all modules that are out of date
%%% compare the compile time of the loaded beam and the beam on disk
reload_modules() ->
    T = fun(L) -> [X || X <- L, element(1,X)==time] end,
    Tm = fun(M) -> T(M:module_info(compile)) end,
    Tf = fun(F) -> 
{ok,{_,[{_,I}]}}=beam_lib:chunks(F,[compile_info]),T(I) end,
    Load = fun(M) -> c:l(M),M end,
   
    [Load(M) || {M,F} <- code:all_loaded(), is_beamfile(F), Tm(M)<Tf(F)].

is_beamfile(F) ->
    ok == element(1,file:read_file_info(F)) andalso
    ".beam" == filename:extension(F).

  if one manages to penetrate its general horribleness, it does a pretty 
useful thing; for every loaded beam, compare the compile time with that 
of the corresponding beam file on disk, and reload the ones that are out 
of date.

  this would of course work equally well if erlc stuck the modification 
time of the erl file into the beam file.

  mats



More information about the erlang-questions mailing list