Programming Erlang读书笔记6: 编译和运行Erl程序

news/2024/5/19 0:43:38 标签: Erlang, 读书, Windows, Web, F#
启动和停止Eshell
[code]
$ erl

1> halt().
[/code]

查看/添加代码查找路径
[code]
code:get_path().
code:add_patha(Dir).
code:add_pathz(Dir).

erl -pa Dir1 -pa Dir2 ... -pz DirK1 -pz DirK2
[/code]

查看载入的module和查看出错的module
[code]
code:all_loaded().
code:clash().
[/code]

可以将code:add_patha()和code:add_pathz()扔到.erlang文件

运行Erl程序的几种方式:
hello.erl
[code]
-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
[/code]

Quick Scripting
[code]
erl -eval 'io:format("Memory: ~p~n", [erlang:memory(total)]).' -noshell -s init stop
[/code]

hello.sh
[code]
#!/bin/sh
erl -noshell -pa /home/joe/code -s hello start -s init stop
[/code]

接受命令行参数
[code]
-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
[/code]

使用Makefile构建Erl程序
[code]
% 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
[/code]

Getting Help
[code]
$ erl -man lists
[/code]
不过男人不支持windows

如果Erlang crash掉了,它会生成一个erl_crash.dump文件,有一个基于Web的crash分析工具
[code]
1> webtool:start().
[/code]

http://www.niftyadmin.cn/n/727656.html

相关文章

在职场老板最不喜欢这十种人

要做一位称职的员工&#xff0c;“先做人后做事”是起码的职业守则&#xff0c;毕竟要让老板能够感觉到你人品的可靠并且值得他去信任&#xff0c;然后&#xff0c;还得让老板欣赏你的才华。那么&#xff0c;如何做一个让老板欣赏的好部下&#xff0c;让老板和你部门的领导能够…

java 发送带视频的邮件_java 带文件的 邮件发送

带文件上传的简单邮件发送案例,这个案例还得导入mail.jar包,这个可以去百度上download一个.其中要注意的是:①:name-->只是个名字,不要带上什么的,②:smtp的地址:QQ邮箱-->smtp.qq.com163邮箱-->smtp.163.com126邮箱-->smtp.126.comyeah邮箱-->smtp.yeah.net即:…

asp.net网站配置工具,点“安全”选项卡出错

提示的错误信息&#xff1a; 选定的数据存储区出现问题&#xff0c;原因可能是服务器名称或凭据无效&#xff0c;或者权限不足。也可能是未启用角色管理器功能造成的。请单击下面的按钮&#xff0c;以重定向到可以选择新数据存储区的页。 下面的消息可能会有助于诊断问题: 无法…

Programming Erlang读书笔记7: Concurrency

1, Erlang程序由许多进程组成&#xff0c;这些进程可以相互发送消息2&#xff0c;这些消息可能接收并理解也可能不接收不理解&#xff0c;如果你希望消息被接收并理解&#xff0c;你必须等待应答3&#xff0c;进程组可以连在一起&#xff0c;如果一组进程中的一个死掉&#xff…

什么是项目管理以及项目集管理呢?

项目集管理也属于项目管理&#xff0c;只不过属于更高层次的项目管理。    项目就是一种组织进行的活动&#xff0c;这种活动具有一定的开始和结束时间&#xff0c;并且需要整合资源&#xff0c;不能单靠一个人来完成。项目会有有实体或软件系统&#xff0c;以及其他结果的产…

java输出希腊字符表_java 命令行窗口输出希腊字母表

/*** author Administrator* 编写程序&#xff0c;命令行窗口输出希腊字母表。(希腊字母表开始为α&#xff0c;最后一个为ω)*/public class OutGreekLetter {public static void main (String args[ ]){int startPosition;int endPosition;char cStartα,cEndω;startPositio…

Ubuntu命令备忘

sudo apt-get install language-pack-gnome-zh language-pack-gnome-zh-base language-pack-zh language-pack-zh-base language-support-zh 安装中文支持dpkg 包管理命令NetBeans中文乱码解决办法&#xff0c;在jre安装目录中的lib/fonts/中建立fallback目录&#xff0c;并将中…

Programming Erlang读书笔记8: Concurrency Programming

在Erlang里: 1&#xff0c;创建和销毁进程非常快 2&#xff0c;进程间发送消息非常快 3&#xff0c;在所有的操作系统间进程行为一致 4&#xff0c;可以有大量的进程 5&#xff0c;进程不共享内存并且完全独立 6&#xff0c;与进程交互的唯一途径是发送消息Concurrency Primiti…