'Goto' in Oxgene fails, but not in Hydrogene or Mercury

I know it’s frowned upon to use or abuse the ‘goto’ statement, but for special use cases … :shushing_face: This Oxygene test case essentially comes from the documentation, but fails to compile:

/* Gary Chike   testing 'goto' statement in Oxygene    08/29/2022 */

namespace Goto_Oxy;

var x : Integer := 5;
begin
  writeLn('Hello');

  if x > 5 then
    goto Here;

  writeLn('x is five or less');

  Here: writeLn('World');

end.

So I ran a test case in Hydrogene and it succeeded (oops, looks like the Hydrogene name has been dropped for RemObjects C#?)

And I ran a test case in Mercury and it succeeded to compile as well

Thanks for taking a look :nerd_face:

Logged as bugs://E26122.

1 Like

While we think of a solution, this works:

namespace Goto_Oxy;

var x : Integer := 5;
begin
  writeLn('Hello');

  if x > 5 then
    goto Here;

  writeLn('x is five or less');

  Here:; writeLn('World');

end.

The issue is that here:writeLn() is seen as the C# equivalent of here?:writeLn()

1 Like

bugs://E26122 was closed as won’t fix.

@ck Thank you Carlo for taking a look. I see the issue now - the colon : operator in Oxygene is essentially the equivalent of C#'s null-conditional operator ?. also known by a variety of names in other languages (eg. safe navigation operator, etc…) unless you really meant the ternary operator ?: :upside_down_face: I know, C# is a little different in its nomenclature:

Fortunately, it appears that post-fixing a semi-colon, essentially truncating the label to its own statement, appears to be a very easy ‘workaround’ or could easily be the ‘fix’. There are variety of variations of the goto label in other languages, that it would not seem out of place by simply adding a semi-colon. Some Pascal dialects require the declaration of a label and I’m not sure if label is keyword in Oxygene. Could adding the declaration of a label help? Maybe it’s not necessary. The code below is written in a spiritual cousin of Oxygene (PascalABC.Net) demonstrating the label declaration. But interestingly enough, it works with a semi-colon post-fixed to the label. :nerd_face:

var x : Integer := 5;
label Here;

begin
  writeLn('Hello');

  if x > 5 then
    goto Here;

  writeLn('x is five or less');

  Here:;  // works with or without semi-colon 
  writeLn('World');

end.

works too, and IMHO feels less awkward than the semicolon.

1 Like

Yes, I believe that works nicely as well Marc. The code snippet below is the beginning of an old-school interactive console game loop and your suggestion works as expected. :rocket: Should it be decided that this will not be ‘fixed’ as a bug, perhaps the workaround (or solution) should be mentioned in the documentation? Lest someone else gets tripped up. Just a thought … :nerd_face:

namespace huwGameLoop_Goto_Oxy;

uses System.Threading;

begin
  var userInput : nullable String;

  writeLn("Press <q> to exit..");
  repeat
    Start:begin   // Per Marc Hoffman's suggestion 
    write("> ");
    end;
    userInput := readLn;
    if String.IsNullOrWhiteSpace(userInput) then goto Start;
      writeLn($"You wrote '{userInput}'");
  until userInput.ToLower() = "q";
writeLn("Goodbye!");
Thread.Sleep(2000);
end.
1 Like

Interestingly enough, I was reading over the documentation on the use of label on the freepascal wiki site and it appears the semi-colon ; is actually used with the label in special cases:

Pascal imposes further restrictions on labels: Labels have to be associated with statements: Putting a label right before an end is not allowed. To bypass that, you can insert an empty instruction ; right after the label definition.

@mh you fixed the documentation with Here: begin end; … cool :fist_right: :fist_left:

1 Like