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

    Feedback wanted: conditional GCode without indentation

    Scheduled Pinned Locked Moved
    Future Direction
    28
    54
    3.9k
    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.
    • fcwiltundefined
      fcwilt @bot
      last edited by

      @bot said in Feedback wanted: conditional GCode without indentation:

      I don't see the need for a begin keyword. If is the keyword that starts the block.

      Perhaps if a keyword is required at the beginning, we could borrow some LUA parlance and use THEN, so that the parser knows when the conditional is over.

      Well in Delphi if you only have one statement after the condition you don't need the begin/end pair. You use them when you have more than one statement.

      I always thought that NOT always requiring begin/end even for one statement was a mistake.

      Frederick

      Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

      1 Reply Last reply Reply Quote 2
      • dbruce.ae05undefined
        dbruce.ae05 @fcwilt
        last edited by

        @fcwilt 🙃

        1 Reply Last reply Reply Quote 0
        • lord binkyundefined
          lord binky @DaveA
          last edited by

          @DaveA As a C & C++ programmer from around 1976 I'd love to see the Kernighan and Ritchie style with { } syntax. I hate Python indention style.
          Just my opinion since you asked.

          What? But python style works great in editors like EMACS! Fancy IDE's highlighting { } groupings is for schmucks right? 😄

          1 Reply Last reply Reply Quote 0
          • wilrikerundefined
            wilriker
            last edited by

            My opinion: use a keyword to end blocks (end is fine for me, but honestly I don't care).

            Do not allow mixing styles, use block end keywords exclusively (but allow indentation for style purposes).

            Manuel
            Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
            with probably always latest firmware/DWC (incl. betas or self-compiled)
            My Tool Collection

            fcwiltundefined garethkyundefined 2 Replies Last reply Reply Quote 1
            • fcwiltundefined
              fcwilt @wilriker
              last edited by

              @wilriker said in Feedback wanted: conditional GCode without indentation:

              My opinion: use a keyword to end blocks (end is fine for me, but honestly I don't care).

              So you would be ok with "ruvineckerned" or "footguratunnie"?

              Just checking to be sure.

              😉

              Frederick

              Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

              1 Reply Last reply Reply Quote 1
              • garethkyundefined
                garethky @wilriker
                last edited by

                @wilriker +1

                The target audience for this language is not skilled programmers. Its designers & makers that are trying to solve some problem with their printer. There is going to be a LOT of copy/paste code that mixes indentation types (tabs, spaces, number of spaces). Begin/end constructs survive this kind of abuse better than Python style strict indentation. Having just 1-way-to-do-it makes its safer/easier for newbies copying code.

                The few of us that are writing most of the code can use whatever construct you come up with.

                1 Reply Last reply Reply Quote 7
                • DanS79undefined
                  DanS79
                  last edited by

                  I think php might be a good example here as it allows two types of syntax.

                  For pure php

                  <?php
                  if ($a > $b) {
                      // do somehting
                  } else {
                   // do somehting else
                  }
                  ?>
                  

                  For php mixed with large chunks of something else like html, JS etc.

                  <?php if ($a > $b) : ?>
                      // do somehting
                  <?php else: ?>
                   // do somehting else
                  <?php endif; ?>
                  

                  All standard control structures have the second alternative syntax.

                  The parser knows php is only contained between the opening and closing tags

                  <?php  // some code here ?>
                  

                  The alternate control structures lets the parser know that logic spans multiple sets of opening and closing tags.

                  Each control structure has it's own unique opening and closing tags.
                  here is a quick little tutorial with examples.
                  https://riptutorial.com/php/topic/1199/alternative-syntax-for-control-structures

                  1 Reply Last reply Reply Quote 0
                  • OwenDundefined
                    OwenD
                    last edited by

                    One thought I guess as is how any start/end construct might be interpreted by common slicers if used in start gcode etc
                    Prusa slicer uses if-endif so is definitely going to try to post process that. Whether it causes any issues probably depends on how PS handles things it doesn't understand

                    1 Reply Last reply Reply Quote 0
                    • garyd9undefined
                      garyd9
                      last edited by

                      I agree that styles shouldn't be mixed and that RRF should either support one thing or another (and not both.) However, RRF 3 is a released product, so any change could be breaking a LOT of code, macros, etc.

                      Even the initial "conditional gcode" stuff in RRF3 was done in such a way to not break any existing gcode.

                      For that reason, I still think there are ways to solve the actual problem without breaking changes to the language. One idea I proposed above, though I don't know if that would actually work. Immediately after, someone else proposed something else that wouldn't break any existing gcode.

                      Breaking an existing programming language for single special cases isn't a good practice. Even large functional changes should be careful to not break existing code. I still have old K&R style C code that still compiles with a modern C/C++ compiler!

                      "I'm not saying that you are wrong - I'm just trying to fit it into my real world simulated experience."

                      1 Reply Last reply Reply Quote 0
                      • OwenDundefined
                        OwenD @dc42
                        last edited by OwenD

                        @dc42

                        Suppose you generate a GCode file using a slicer. But you have a belt printer and you want to print it 10 times, with a belt movement between each iteration.

                        For this particular case, could it not be solved using a loop Gcode as in CNC or plasma cutting? In the case of Hypertherm controllers they use G97 & G98 to define the loop.
                        In my day job I sell CNC plasma systems and the nesting program would output thusly if you used step and repeat.
                        I would have thought that instead of stepping on Y, you'd just do Z?

                        %
                        G21
                        G91
                        G97 T10; loop 10 times
                        N1
                        M00
                        G00X0.Y45.278
                        (Seq 1 - square)
                        G41
                        M07 ; torch on
                        G01Y4.722
                        G01X50.
                        G01Y-50.
                        G01X-50.
                        G01Y45.278
                        M08 ; torch off
                        G40
                        G00X0.Y104.722 ; move to be ready for next part
                        G98 ; Repeat at G97 point
                        M30 ; end of program
                        %
                        
                        deckingmanundefined 1 Reply Last reply Reply Quote 0
                        • deckingmanundefined
                          deckingman @OwenD
                          last edited by

                          @OwenD I'd have thought, for that particular use case, one would simply advance the belt, reset the Y position using G92, then start the next print. To expand on that, when a print finishes, move the belt (say) 200mm. At that point the Y position would be (say) -250. So simply use G92 Y50 to reset it to 50, then start the next print. It's a little more complicated because the starting Y position, before the 200mm move would differ with each print, but it wouldn't be beyond the wit of man to subtract (say) 200mm from whatever the end point becomes.

                          Ian
                          https://somei3deas.wordpress.com/
                          https://www.youtube.com/@deckingman

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

                            @dc42 I'd like to see indentation not have semantic meaning, mainly because the way it is now, I can't have a macro write a macro that writes a macro with conditionals in it. Believe it or not, I have a use for that. and this won't work:

                            M560 P"/macros/Outer"
                            M28 "/macros/Inner"
                            if condition
                            ; stuff
                            M29
                            <!-- **EoF ** -->

                            (Ironically, the forum software eats my leading spaces and won't let me put in a tab! So ; stuff is supposed to be indented.)

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

                              @donstauffer put your code in a block starting and ending with triple back ticks ( ```) on a single line each to retain spaces.

                              <>RatRig V-Minion Fly Super5Pro RRF<> V-Core 3.1 IDEX k*****r <> RatRig V-Minion SKR 2 Marlin<>

                              1 Reply Last reply Reply Quote 0
                              • o_lampeundefined
                                o_lampe
                                last edited by

                                I haven't read all the replies so here's my 2 cent.

                                I like to keep indentation (with TAB) for readability.

                                There's already the break keyword for IF/ELIF constructs, why not use this generally to end IF statements?
                                Then end would be exclusively for WHILE-loops.

                                Putting while loops in start/end code of a slicer could lead to conflicts when a print was cancelled.

                                1 Reply Last reply Reply Quote 0
                                • GuruSMIundefined
                                  GuruSMI
                                  last edited by

                                  This post is deleted!
                                  1 Reply Last reply Reply Quote 0
                                  • HebigTundefined HebigT referenced this topic
                                  • First post
                                    Last post
                                  Unless otherwise noted, all forum content is licensed under CC-BY-SA