Embedded Software

Embedded Software

Topics related to SCADE Suite, SCADE Display, SCADE One and more.

Correct usage of “mapfoldw” iterator.

    • fdtsaid
      Subscriber

      In Scade Language Reference 8.5 Operator Application and Higher-Order Patterns, it illustrated that the usage of foldw:
       

      idx, acc = (foldw op << size >> if cond0)(acc0, A1,...,An)
       
      is equivalent to particular form of mapfoldw:
       
      idx, _, acc = (mapfoldw 1 op << size >> if cond0)(acc0, A1, ..., An)
       
      Should it be the following form instead?
      idx, _, acc = (mapfoldw 1 op << size >> if cond0 default ())(acc0, A1, ..., An)
       
      Because the syntax definition of mapfoldw is 
      operator ::= (iterator_mw operator << size >> if expr default expr)
      iterator_mw ::= mapfoldw [[ INTEGER ]]
    • Benjamin Descorps
      Ansys Employee

      Hello,

      You're correct. The right syntax is

      idx, _, acc = (mapfoldw 1 op <> if cond0 default ()) (acc0, A1,…,An)

      Let's have the following example:

      const n : uint8 = 10;
      function Op (c,d: bool) returns (cond_o, s: bool)
      let 
      s = c or d;
      cond_o = not s;
      tel 
       
      function disjunction(B: bool^n) returns (exist: bool; i: bool)
      i, exist = (foldw Op <> if true) (false, B);
       
      The foldw could be replaced by the mapfoldw in the following way:
      i, _, exist = (mapfoldw 1 Op <> if true default ())(false, B);
       
      Regards,
       
      Benjamin
Viewing 1 reply thread
  • You must be logged in to reply to this topic.