Results 1 to 6 of 6

Thread: short circuit evaluation in Simba

  1. #1
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default short circuit evaluation in Simba

    Last time I'm checking, the pascal that simba uses does not have the keywords and_then or_else that ensures short circuit evaluation is done from left to right. My question is, is short circuit evaluation supported? Or must we use nested Ifs to ensure the results are evaluated in the order we specify?

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Is this what you mean? If it is, then why not just switch the Left = Right ---to--- Right = Left?
    Simba Code:
    Function EvalLR: Boolean;
    var
      X, Y, A, B: Integer;
      J, K: Boolean;
    begin
      X:= 1; Y:= 1; A:= 2; B:= 3;

      L:= (X = Y);
      R:= (A = B);

      //What you want:
      //if ((X = Y)) = ((A = B))
      //In other words..
      //if (L = R)..

      //The way to do this in pascal I guess:

      if (A = B) then
        if(X = Y) then
          Result:= True;

      // OR:
      if (L = R) //or (R = L)

    end;
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Simba Code:
    //Short Circuit eval

    var
        a, b, c, d: integer;
        bA, bB: boolean;
    begin
        a := 0; b := 1; c := 3; d := 3;
        bA := (a = b);
        bB := (c = d);
        // statement should be false after testing bA, and never test bB
        // iirc thats what short circuit evals about
        // I can't remember if its left to right, or right to left
        if (bA and bB) then
            writeln('netanyahoo');
    end;
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  4. #4
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ah that's exactly what I'm looking for. Nevertheless it sucks for me that the language does not have it implemented by default (Sorry I was a lazy java guy)

  5. #5
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Doesn't Lape supports it?
    Let me check.
    It is, if you switch it on, or I don't know what it does by default, but you can definitely switch it on.

    It's on by default, you can switch it off.

    Simba Code:
    program ShortCircuitEvaluationTest;
    //{$B OFF}

    function Bool(i: Integer): Boolean;

    begin
      WriteLn(i);
      Result := i;
    end;

    begin
      if(Bool(0) and Bool(1)) then
        WriteLn('wat');
    end.

    With lape of course. Neat.

    p.s.: I love Lape.
    Last edited by Sabzi; 01-14-2012 at 12:10 PM.

  6. #6
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Sabzi View Post
    Doesn't Lape supports it?
    Let me check.
    It is, if you switch it on, or I don't know what it does by default, but you can definitely switch it on.

    It's on by default, you can switch it off.

    Simba Code:
    program ShortCircuitEvaluationTest;
    //{$B OFF}

    function Bool(i: Integer): Boolean;

    begin
      WriteLn(i);
      Result := i;
    end;

    begin
      if(Bool(0) and Bool(1)) then
        WriteLn('wat');
    end.

    With lape of course. Neat.

    p.s.: I love Lape.
    Thanks loads I don't realize there's a LAPE interpreter option.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •