[erlang-questions] Escript and spawn

Julian Fondren ayrnieu@REDACTED
Sat Apr 28 08:08:50 CEST 2007


On 4/28/07, Erik de Castro Lopo <mle+erlang@REDACTED> wrote:
>     #!/usr/bin/env escript
>
>     -module (test).
>     -export ([ main/1, new_process/0 ]).
>
>     new_process () ->
>         io:format ("new_process\n"),
>         exit ("Done").
>
>     main (_) ->
>         spawn (?MODULE, new_process, []),
>         timer:sleep (5000),
>         ok.

You can avoid

  1. needing the preprocessor, which escript doesn't provide;
  2. hard-coding your module name; and
  3. needing to export new_process/0,

by writing this, instead:

    spawn(fun () -> new_process() end),

Cheers,
Julian

ps. putting a space before the open-paren is really, really,
really really, weird and uncomfortable.  Only funs look like
that.

pps. escript doesn't like this, either:

    spawn(fun new_process/0),



More information about the erlang-questions mailing list