Erlang 笔试题 1

原创文章,转载请注明: 转载自http://blog.csdn.net/genesislive
本文链接地址: Erlang 笔试题 1


1、写一个函数,功能如下:

    0 返回 white

    1 返回 green

    2 返回 blue

   其他 返回 yellow

   分别用function clause, case clause, if clause 实现

 

color1(0) ->
    white;
color1(1) ->
    green;
color1(2) ->
    blue;
color1(_) ->
    yellow.

color2(C) ->
    case C of
	0 -> white;
	1 -> green;
	2 -> blue;
	_ -> yellow
    end.

color3(C) ->
    if
	C =:= 0 ->
	    white;
	C =:= 1 ->
	    green;
	C =:= 2 ->
	    blue;
	true ->
	    yellow
    end.


2、尾递归实现 1+2+3+……+100

sum(Stop, Stop, _Step, Acc) ->
    Stop + Acc;
sum(Start, Stop, Step, Acc) ->
    sum(Start + Step, Stop, Step, Acc + Start).


3、Erlang VM 有哪些原因可能会crashdump

  • "<A>: Cannot allocate <N> bytes of memory (of type "<T>")." - The system has run out of memory. <A> is the allocator that failed to allocate memory, <N> is the number of bytes that <A> tried to allocate, and <T> is the memory block type that the memory was needed for. The most common case is that a process stores huge amounts of data. In this case <T> is most often heapold_heap,heap_frag, or binary. For more information on allocators see erts_alloc(3).
  • "<A>: Cannot reallocate <N> bytes of memory (of type "<T>")." - Same as above with the exception that memory was being reallocated instead of being allocated when the system ran out of memory.
  • "Unexpected op code N" - Error in compiled code, beam file damaged or error in the compiler.
  • "Module Name undefined" | "Function Name undefined" | "No function Name:Name/1" | "No function Name:start/2" - The kernel/stdlib applications are damaged or the start script is damaged.
  • "Driver_select called with too large file descriptor N" - The number of file descriptors for sockets exceed 1024 (Unix only). The limit on file-descriptors in some Unix flavors can be set to over 1024, but only 1024 sockets/pipes can be used simultaneously by Erlang (due to limitations in the Unix select call). The number of open regular files is not affected by this.
  • "Received SIGUSR1" - The SIGUSR1 signal was sent to the Erlang machine (Unix only).
  • "Kernel pid terminated (Who) (Exit-reason)" - The kernel supervisor has detected a failure, usually that theapplication_controller has shut down (Who = application_controllerWhy = shutdown). The application controller may have shut down for a number of reasons, the most usual being that the node name of the distributed Erlang node is already in use. A complete supervisor tree "crash" (i.e., the top supervisors have exited) will give about the same result. This message comes from the Erlang code and not from the virtual machine itself. It is always due to some kind of failure in an application, either within OTP or a "user-written" one. Looking at the error log for your application is probably the first step to take.
  • "Init terminating in do_boot ()" - The primitive Erlang boot sequence was terminated, most probably because the boot script has errors or cannot be read. This is usually a configuration error - the system may have been started with a faulty -boot parameter or with a boot script from the wrong version of OTP.
  • "Could not start kernel pid (Who) ()" - One of the kernel processes could not start. This is probably due to faulty arguments (like errors in a -config argument) or faulty configuration files. Check that all files are in their correct location and that the configuration files (if any) are not damaged. Usually there are also messages written to the controlling terminal and/or the error log explaining what's wrong.

 详见:http://www.erlang.org/doc/apps/erts/crash_dump.html

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值