Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Unexpected error with # and ternary operator

    Scheduled Pinned Locked Moved
    Gcode meta commands
    2
    4
    131
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DonStaufferundefined
      DonStauffer
      last edited by DonStauffer

      I've found that to get the size of an array which is element of an array, I have to parenthesize the array expression. That's no problem, and this displays "C=2" as expected:

      var A = {{1,2}, {3,4}}
      ;var B = 0
      var C = (exists(var.B) ? var.B : #(var.A[0]))
      echo "C="^var.C
      

      However, remove the semicolon so that B is defined, and it seems like you should see "C=0", but instead you get:

      Error: in file macro line 3 column 45: meta command: expected object model value or string after '#

      (Incidentally missing the closing apostrophe; also, it seems like it should say "expected object model value, string, or array expression after '#'".)

      Parenthesizing the # expression doesn't help. It seems to be a parsing error. Possibly failing to recognize the : as part of the ternary operator under some circumstances.

      DonStaufferundefined 1 Reply Last reply Reply Quote 0
      • DonStaufferundefined
        DonStauffer @DonStauffer
        last edited by DonStauffer

        @DonStauffer Obvious workaround :

        var A = {{1,2}, {3,4}}
        var B = 0
        var D = #(var.A[0])
        var C = exists(var.B) ? var.B : var.D)
        
        echo "C="^var.C
        
        dc42undefined 2 Replies Last reply Reply Quote 0
        • dc42undefined
          dc42 administrators @DonStauffer
          last edited by

          @DonStauffer which firmware version are you using, and are you using standalone mode or attached SBC? I just tested this, which is the same as your example with the brackets after # removed and it works for me:

          var A = {{1,2}, {3,4}}
          ;var B = 0
          var C = (exists(var.B) ? var.B : #var.A[0])
          echo "C="^var.C
          

          If I remove the semicolon from the second line then it also works. I am running 3.6.0-alpha.1 in standalone mode. The expression parsing code has not changed since 3.5.2. Maybe you are running in SBC mode?

          Duet WiFi hardware designer and firmware engineer
          Please do not ask me for Duet support via PM or email, use the forum
          http://www.escher3d.com, https://miscsolutions.wordpress.com

          1 Reply Last reply Reply Quote 0
          • dc42undefined
            dc42 administrators @DonStauffer
            last edited by

            @DonStauffer I have now reproduced this and created https://github.com/Duet3D/RepRapFirmware/issues/1020 and https://github.com/Duet3D/RepRapFirmware/issues/1021.

            dc42 created this issue in Duet3D/RepRapFirmware

            closed Incorrect processing of # operator when operand is an element of an array of arrays #1020

            dc42 created this issue in Duet3D/RepRapFirmware

            closed Parsing error when using ternary operator #1021

            Duet WiFi hardware designer and firmware engineer
            Please do not ask me for Duet support via PM or email, use the forum
            http://www.escher3d.com, https://miscsolutions.wordpress.com

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Unless otherwise noted, all forum content is licensed under CC-BY-SA