Domanda

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.

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top