Let’s modify our Hello World program.
Instead of writing “Hello World” as the output, we want it to write “Hello Name” where name is a parameter we provide to the function hello_world.
The original code is the following:
-module(hello). -export([hello_world/0]). hello_world() -> io:fwrite("hello, world\n").
Since we want to pass a parameter, we have to modify the export line as follows:
-export([hello_world/1]).
Then we have to instruct the hello_world function to handle the parameter:
hello_world(Name) -> io:fwrite("Hello, ~s\n", [Name]).
save the file and run the erlang shell.
compile the program:
12> c(hello). {ok,hello}
and then, run it
13> hello:hello_world("dude"). Hello, dude ok
Gg1