Posts Tagged ‘ erlang

我的erlang的makefile模板

目前还不支持文件夹的遍历,只能一个一个写上去。

.SUFFIXES: .erl .beam

.erl.beam:
    erlc ${ERLC_FLAGS} $<

SOURCES = ${wildcard src/api/twitter/*.erl} ${wildcard src/ui/*.erl}
BINS = bin
INCLUDES = include
ERLC_FLAGS = -W -I ${INCLUDES} -o ${BINS}

all: compile

compile:  initDirs ${SOURCES:%.erl=%.beam}

initDirs:
    mkdir -p bin

test: compile
    erl -noshell -pa $(BINS) -s client test -s init stop

emacs支持erlang

home目录下配置.emacs文件:

;; setup erlang mode
;; add the location of the elisp files to the load-path
(setq load-path (cons "/usr/lib/erlang/lib/tools-2.5.5/emacs" load-path))
;; set the location of the man page hierarchy
(setq erlang-root-dir "/usr/lib/erlang")
;; add the home of the erlang binaries to the exec-path
(setq exec-path (cons "/usr/lib/bin" exec-path))
;; load and eval the erlang-start package to set up
;; everything else
(require 'erlang-start)

hello new world

今天开启了一个新project,主要是学习Erlang,想用Erlang做一个软件,实现twitter的客户端功能,当然还有很多隐藏功能,全部灵感来自于索爱的新手机X10,所以项目名字叫做Erscape。学习语言的最好方法还是实践,趁自己最近有时间,抓紧训练。项目使用google code托管,有兴趣的可以关注 http://code.google.com/p/erscape/ ,当然现在还是什么也没有,下午先弄个0.1版的。。。

《Erlang程序设计》第8章习题2

编写一个环形基准测试,在一个环中创建N个进程,然后沿着环发送一条消息M次,最后总共发送M*N条消息。在N和M的不同取值下测试整个过程消耗时间。

-module(ex2).
-export([start/2]).

start(N,M)->
    statistics(runtime),
    statistics(wall_clock),
    L=create(N),
    post(L,M),
    {_,Time1} = statistics(runtime),
    {_,Time2} = statistics(wall_clock),
    io:format("total time: ~p(~p)ms~n",[Time1,Time2]).




create(N)->
    create(N,[]).

create(0,L)->
    L;
create(N,L)->
    Pid=spawn(fun loop/0),
    create(N-1,[Pid|L]).



loop()->
    receive
    cancel->
        void
end.





post(_,0)->
    void;
post(L,M) ->
    [A ! canel ||A<-L],
    post(L,M-1).

ubuntu9.04+ErlangR13b成功

弄了一天,终于成功了。

先是冒雨去三好街弄个4g kingston闪存,然后在windows下拷进来,弄进我的8.04用disk image writer烧进U盘,启动,ext4分区,安装,进入系统后被感动,netbook版本带了个桌面,非常酷,不过这个桌面不支持多个桌面和特效,令笔者痛心疾首。然后开始选择源(tw那个),更新,安装中文语言包,firefox插件,然后是compiz 桌面特效(控制面板里的安装与删除里有),终于见到了传说中的3D桌面,原来真是dell 自带的那个不好用。然后不小心开了个特效,桌面崩溃了,插入U盘,重新安装。。。。。。

再次回到之前的状态后开始安装Java,Eclipse,RealPlayer,各种命令应接不暇 ,发现大学时候背的都己不住咯,最后折腾完夜已深。今天一早继续开始折腾。Erlang上次安装就失败了,这次心有余悸,战战兢兢打开百度。。。。。。
终端:
sudo apt-get install build-essential
sudo apt-get install libncurses5-dev
sudo apt-get install m4
sudo apt-get install libssl-dev
新立得:
libc6
unixodbc
gcj
源文件解压后:
sudo ./configure –prefix=/otp/erlang
sudo make
sudo make install
添加环境变量:
sudo gedit /etc/profile
文本编辑器里:
export PATH=/otp/erlang/bin:$PATH
alias ls=’ls -color=auto’
alias ll=’ll -lht’
终端里:
source /etc/profile
成功了,试试:
终端里输入:erl

kmlzkma@kmlzkma-mini9:/otp/erlang/bin$ erl
Erlang R13B (erts-5.7.1) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.1 (abort with ^G)
1> 1+1.
2
终于安上了erlang了,还差一个ide就完活。。。

Eclipse 3.4 : Help → Software Updates → Available software : choose Add site… and enter http://erlide.sourceforge.net/update