As a part of a learning course, i was making a procedure that took lists as parameters and then operated on their contents. It went like this:

proc {myProc A B}
    case B of H|T then
        %do something
        {myProc A T}
    end
end

However, when i have tried executing it, i encountered failures when B is an ampty list (that is, nil). Why is that?

What should i do in order to do nothing if B is nil? As far as i know, adding empty else clause will result in compilation error.

有帮助吗?

解决方案

You need to add a case for nil:

proc {myProc A B}
  case B
  of H|T then
    %do something
    {myProc A T}
  [] nil then
    skip
  end
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top