1. error/1 主要是系统用来定义内部错误的: Erlang内建的run time error 一共有10种: function_clause/case_clause/if_clause/badmatch/badarg/undef/badarith/badfun/badarity/system_limit, 比如: 1> erlang:binary_to_list(1). ** exception error: bad argument in function binary_to_list…
背景:gen_fsm 是Erlang的有限状态机behavior,很实用.爱立信的一位TDD大神写了一篇怎样測试gen_fsm,这个fsm是一个交易系统,负责简单的交易员登陆,插入item,删除item等等,翻译例如以下: 1. Start and Stop 先看下最初版本号的tradepost_tests: -module(tradepost_tests). -include_lib("eunit/include/eunit.hrl"). % This is the main poi…
引自:http://cryolite.iteye.com/blog/1547252 1. binary数据是可以在不同进程间共享的 当然这些进程都在同一Erlang节点上. 这与普通term不同,后者作为消息在进程间传递时是要在接收进程中做拷贝的(当然atom数据例外,它们也不会做拷贝).摘一段原文在这里: All data in messages between Erlang processes is copied, with the exception of refc binaries on…
1. 保护式(guard)中如果出错,不会报错,只会返回false! case 1=:1 of true when not erlang:length(t) =:= 1 orelse true -> ok; _ -> error end. Result is: error 保护式中对t (atom) 求length会出错,本应crash掉,但因为在保护式中,默认出错后结束此保护式计算并返回false,这也是为什么保护式不接受复杂的函数,只能用erlang的bif来做的原因之一. 2. tr…