一、安装Erlang语言编译系统
要学习它,首先就要安装其编译系统。不用多说,Windows系统的话直接到其官网下载与安装,一路NEXT下去就行;安装完成后要在环境变量PATH中添加其安装目录的路径。如果是Linux系统的话,可以尝试apt-get(yum) install erlang。
二、Erlang程序文本型的.erl的源文件在shell中运行方法
1.在Erlang shell中编译运行用文本型的.erl的源文件。
第一步:编译源文件为.beam文件,命令为(源文件为hello.erl):
c(hello).
第二步:直接运行其中导出的方法start():
hello:start().
2.在命令提示符下编译运行用文本型的.erl的源文件(Win下需要添加环境变量)。
第一步:编译源文件,命令为:
erlc hello.erl
第二步:运行指定模块和指定方法(调用hello模块中的start方法,如果不给出方法名,默认会调用start方法):
erl -noshell -run hello start -run init stop
(其中-run也可用-s代替)
3.用escript运行(默认运行源文件中的main/1方法)
escript hello_e.erl
附hello.erl源代码:
-module(hello).
-export([start/0]).
start() ->io:format("Hello World!~n").
hello_e.erl源文件
-module(hello).
-export([start/0]).
main(_) ->io:format("Hello World!~n").