[erlang-questions] Why can't I use array:size in a guard in a method?

Yves S. Garret yoursurrogategod@REDACTED
Sat Jul 27 20:22:26 CEST 2013


The code:

printArray(Array, Size, IndexToStartWith)
    when array:size(Array) > IndexToStartWith ->
  io:format("~w~n", [array:get(IndexToStartWith, Array)]),
  printArray(Array, Size, IndexToStartWith + 1).

The error:

> c(arrays_example).
arrays_example.erl:23: illegal guard expression
error

Why not?  I could pass the size of the array along (hence the Size
variable), but why not procure
the length in the guard on the fly?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130727/15410ca2/attachment.htm>


More information about the erlang-questions mailing list