启动和停止Eshell
$ erl
1> halt().
查看/添加代码查找路径
code:get_path().
code:add_patha(Dir).
code:add_pathz(Dir).
erl -pa Dir1 -pa Dir2 ... -pz DirK1 -pz DirK2
查看载入的module和查看出错的module
code:all_loaded().
code:clash().
可以将code:add_patha()和code:add_pathz()扔到.erlang文件
运行Erl程序的几种方式:
hello.erl
-module(hello).
-export([start/0]).
start() ->
io:format("Hello world~n").
%%%%%%%%%%%%%
$ erl
1> c(hello).
2> hello:start().
%%%%%%%%%%%%%
$ erlc hello.erl
$ erl -noshell -s hello start -s init stop
Quick Scripting
erl -eval 'io:format("Memory: ~p~n", [erlang:memory(total)]).' -noshell -s init stop
hello.sh
#!/bin/sh
erl -noshell -pa /home/joe/code -s hello start -s init stop
接受命令行参数
-module(main).
-export([main/1]).
fac(0) -> 1;
fac(N) -> N*fac(N-1).
main([A]) ->
I = list_to_integer(atom_to_list(A)),
F = fac(I),
io:format("factorial ~w = ~w~n", [I, F]),
init:stop().
%%%%%%%%%%%%
$ erlc main.erl
$ erl -noshell -s main main 25
factorial 25 = 15511210043330985984000000
使用Makefile构建Erl程序
% Makefile.template
# leave these lines alone
.SUFFIXED: .erl .beam .yrl
.erl.beam:
erlc -W $<
.yrl.erl:
erlc -W $<
ERL = erl -boot start_clean
# Here's a list of the erlang modules you want compiling
# If the modules don't fit onto one line add a \ character
# to the end of the lien and continue on the next line
# Edit the lines below
MODS = module1 module2 \
module3 ... special1 ...\
...
moduleN
# The first target in any makefile is the default target.
# If you just type "make" then "make all" is assumed (because
# "all" is the first target in this makefile)
all: compile
compile: ${MODS:%=%.beam} subdirs
## special compilation requirements are added here
special1.beam: special1.erl
${ERL} -Dflag1 -WO special1.erl
## run an application from the makefile
application1: compile
${ERL} -pa Dir1 -s application1 start Arg1 Arg2
# the subdirs target compiles any code in
# sub-directories
subdirs:
cd dir1; make
cd dir2; make
...
# remove all the code
clean:
rm -rf *.beam erl_crash.dump
cd dir1; make clean
cd dir2; make clean
Getting Help
$ erl -man lists
不过男人不支持windows
如果Erlang crash掉了,它会生成一个erl_crash.dump文件,有一个基于Web的crash分析工具
1> webtool:start().
分享到:
相关推荐
programming erlang 源码
Programming+Erlang.pdf+ 面对软件错误构建可靠的分布式系统.pdf+ Concurrent Programming in ERLANG
Programming Erlang
我自己在新学erlang,在LeetCode OJ上找了题目练习,题目很适合新手熟悉语言,但是LeetCode OJ里面只有几门主流语言的答案,下面是已完成的erlang源代码,后续有空再做其他问题续传,题目包含:(源码开头都有题目...
Programming Erlang PDF author: Joe Armstrong
In this second edition of the bestselling Programming Erlang, you'll learn how to write parallel programs that scale effortlessly on multicore systems. Using Erlang, you'll be surprised at how easy ...
Erlang运行时环境是一个虚拟机,有点像Java虚拟机,这样代码一经编译,同样可以随处运行。它的运行时系统甚至允许代码在不被中断的情况下更新。另外如果你需要更高效的话,字节代码也可以编译成本地代码运行。 ...
Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book.
Joe Armsrong经典2013首发,Programming Erlang second edition
Erlang Programming 导Erlang Programming 导读.pdf读.pdfErlang Programming 导读.pdf
编写分布式的Erlang程序:陷阱和对策
主要介绍了Erlang程序设计(第2版)读书笔记:Erlang安装和基础语法,需要的朋友可以参考下
Concurrent Programming in ERLANG
erlang官方没有龙芯版本的安装包,这个是用24版本的源码在龙芯3a5000下编译的版本,解压缩以后将bin路径加入PATH环境变量即可使用。
Pragmatic.Programming.Erlang.2nd.Edition
(Programming Erlang) Joe.Armstrong Erlang程序设计 第2版 含中文版、英文版和源码