/core/engine/tools.erl

http://erlbattle.googlecode.com/ · Erlang · 31 lines · 20 code · 8 blank · 3 comment · 3 complexity · 4524ddfe958bdc10bb28941831963165 MD5 · raw file

  1. -module(tools).
  2. -export([sleep/1,getLongDate/0,keyfind/3,for/3]).
  3. %% Sleep ????
  4. sleep(Sleep) ->
  5. receive
  6. after Sleep -> true
  7. end.
  8. getLongDate() ->
  9. {MegaSecs, Secs, MicroSecs} = now(),
  10. Seed = 1000 * 1000,
  11. (MegaSecs * Seed + Secs) *Seed + MicroSecs.
  12. %% ????
  13. keyfind(Key, N, List) ->
  14. case lists:keysearch(Key, N, List) of
  15. false -> false;
  16. {_Val, Result} -> Result;
  17. _ELSE -> false
  18. end.
  19. %% ????for ????
  20. for(I, I, Fun) -> Fun(I);
  21. for(I, N, Fun) ->
  22. Fun(I),
  23. for(I+1, N, Fun).