Announcement

Collapse
No announcement yet.

MAT statements and user defined types

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MAT statements and user defined types

    I've just discovered that MAT statements don't work with arrays within user defined types.

    For example, given a UDT
    Code:
     
    TYPE Population
      State(1 to 3) as EXT
      Transition(1 to 3,1 to 3) as EXT
    END TYPE
    And
    Code:
     
    LOCAL P as Population
    I can access P.State() and P.Transition() as arrays in the normal way, but I can't do assignments such as
    Code:
     
    MAT P.State()=AnotherVector()
    MAT P.State()=ZER
    MAT P.Transition()=IDN
    These result in compile time error 526: Period not allowed. Of course it's not a big deal to do matrix operations the long way round, but it would be good to have the convenience of MAT statements with UDTs sometimes. A New Feature Suggestion has been lodged with those nice people at [email protected]...

  • #2
    I've just discovered that MAT statements don't work with arrays within user defined types
    No "ARRAY" statements work with "Arrays within types".

    "Arrays within types" are not "Arrays" [cap A] as used elsewhere in the documentation.

    "Arrays within types" are in fact "arrays" [small A], but that's too easily confused with "Arrays" [caps again] so I just call them "tables." [case not signficant]

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Would DIM...AT provide a workaround here?

      DIM an array AT the memory location of the UDT's pseudo-array, and use the MAT statement on the "overlay" array?

      -- Eric
      "Not my circus, not my monkeys."

      Comment


      • #4
        Michael M: I take your point. Still, as a minor convenience, I'd like to be able to do the same things to arrays as Arrays. Not of huge importance, but something I'd use if it was available.

        Eric: Thanks - out of interest I tried it (DIM V() AS EXT AT VARPTR(P.State()), then MAT operations on V()). Didn't seem to work, but I could easily have done it wrong as that's the first time I'd even heard of DIM AT. In practice I'd just do the assignment long-hand.

        Comment


        • #5
          out of interest I tried it (DIM V() AS EXT AT VARPTR(P.State()), then MAT operations on V()). Didn't seem to work,
          That should not even compile.
          Code:
          REDIM V(2  [ or "1 to 3"] ) AS EXT AS VARPTR(p.State(1))
          ... should both compile and work.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Yes - that works, thanks! I mistyped my original effort in my last post, but I still missed that varptr should be to P.State(1) rather than P.State().

            So...
            Code:
              DIM V(1 TO 3) AS EXT AT VARPTR(P.State(1))
              MAT V()=V2()
            works exactly as if I had done the MAT statement on P.State() directly.

            Lots to learn...

            Comment

            Working...
            X