Correct escript for hello world in erlang?

So, I know that the main Hello World program (how to print a line not intended for Erlang training with caviar and other things) looks like this

-module(hello).
-export([start/0]).

start() ->
  io:format("Hello, World!").

Then i run erl

>erl

type

>c(hello)

and then

>hello

For escript version will it be?

#!/usr/bin/env escript
-export([main/1]).

main([]) -> io:format("Hello, World!~n").

Then

chmod u+x hello

Where does the file name greet?

Why can't I use the same format as the module? (main / 0 and main ())?

+3
source share
1 answer

This is how escript works. Your escript must contain a function main/1for runtime. An escrypt needs a way to pass command line arguments to your function, and it does it like a list of strings, so your function needs to maintake one argument.

, - , (start/0 ).

. , .

 hello.

hello. , :

hello:start().
+10

Source: https://habr.com/ru/post/1775735/


All Articles