Unable to use function call in function guard

前端 未结 2 916
盖世英雄少女心
盖世英雄少女心 2021-01-12 01:35

I\'m new to Erlang and am trying to program a bounded-buffer problem program. It is almost working, except for making sure the producers don\'t get too far ahead and overwr

相关标签:
2条回答
  • 2021-01-12 02:01

    As Geoff Reedy has mentioned there are only few BIFS that are allowed in guards.

    But the guardian parse transform library can be used to call any function in guards.

    0 讨论(0)
  • 2021-01-12 02:14

    There are only certain functions that can be used in a guard, see Guard Sequences in the Erlang manual. You can easily do what you need as follows:

    buffer(Buf, NextWrite, NextRead) -> buffer(Buf, NextWrite, NextRead, array:size(Buf)).
    
    buffer(Buf, NextWrite, NextRead, _) when NextWrite == NextRead -> 
      ;
    buffer(Buf, NextWrite, NextRead, BufSize) when (NextWrite - NextRead) == BufSize ->
      ;
    buffer(Buf, NextWrite, NextRead, _) ->
      .
    
    0 讨论(0)
提交回复
热议问题