NullOps

This forum is for any questions about the language Tutorial D or the Rel implementation of it.
Post Reply
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

NullOps

Post by Chris Walton » Sun Feb 16, 2014 8:27 pm

What syntax should be used to say "do nothing". Both the following fragments of code generate errors:

Code: Select all

OPERATOR TestOps ( T RELATION SAME_HEADING_AS ( red.Tree ) ) RETURNS RELATION SAME_HEADING_AS ( red.Tree );
  BEGIN;
    VAR i INTEGER INIT ( 0 );
    FOR UNION { EXTEND T : { parent := i } } ORDER ( ASC parent );
      BEGIN;
        CASE;
          WHEN THE_d# ( node ) = 1 THEN i := THE_s# ( node);
          WHEN THE_d# ( node ) = 0 THEN;
          WHEN THE_d# ( node ) < 0 THEN i := i + THE_d# ( node );
        ELSE i := 0;
        END CASE;
      END;
    END FOR;
    RETURN T;
  END;

Code: Select all

OPERATOR TestOps ( T RELATION SAME_HEADING_AS ( red.Tree ) ) RETURNS RELATION SAME_HEADING_AS ( red.Tree );
  BEGIN;
    VAR i INTEGER INIT ( 0 );
    FOR UNION { EXTEND T : { parent := i } } ORDER ( ASC parent );
      BEGIN;
        CASE;
          WHEN THE_d# ( node ) = 1 THEN i := THE_s# ( node);
          WHEN THE_d# ( node ) > 1 THEN i := 0;
          WHEN THE_d# ( node ) < 0 THEN i := i + THE_d# ( node );
        ELSE ;
        END CASE;
      END;
    END FOR;
    RETURN T;
  END;
So I have to do one of the following (neither of which is exactly what I am trying to say):

Code: Select all

OPERATOR TestOps ( T RELATION SAME_HEADING_AS ( red.Tree ) ) RETURNS RELATION SAME_HEADING_AS ( red.Tree );
  BEGIN;
    VAR i INTEGER INIT ( 0 );
      FOR UNION { EXTEND T : { parent := i } } ORDER ( ASC parent );
      BEGIN;
        CASE;
          WHEN THE_d# ( node ) = 1 THEN i := THE_s# ( node);
          WHEN THE_d# ( node ) = 0 THEN i := i;
          WHEN THE_d# ( node ) < 0 THEN i := i + THE_d# ( node );
        ELSE i := 0;
        END CASE;
      END;
    END FOR;
    RETURN T;
  END;
END OPERATOR;

Code: Select all

OPERATOR TestOps ( T RELATION SAME_HEADING_AS ( red.Tree ) ) RETURNS RELATION SAME_HEADING_AS ( red.Tree );
  BEGIN;
    VAR i INTEGER INIT ( 0 );
      FOR UNION { EXTEND T : { parent := i } } ORDER ( ASC parent );
      BEGIN;
        CASE;
          WHEN THE_d# ( node ) = 1 THEN i := THE_s# ( node);
          WHEN THE_d# ( node ) > 1 THEN i := 0;
          WHEN THE_d# ( node ) < 0 THEN i := i + THE_d# ( node );
        END CASE;
      END;
    END FOR;
    RETURN T;
  END;
END OPERATOR;
[/size]

Dave
Site Admin
Posts: 364
Joined: Sun Nov 27, 2005 7:19 pm

Re: NullOps

Post by Dave » Fri Feb 28, 2014 12:40 pm

Sorry for my slow response!

I would alter the first example as follows:

Code: Select all

OPERATOR TestOps ( T RELATION SAME_HEADING_AS ( red.Tree ) ) RETURNS RELATION SAME_HEADING_AS ( red.Tree );
  BEGIN;
    VAR i INTEGER INIT ( 0 );
    FOR UNION { EXTEND T : { parent := i } } ORDER ( ASC parent );
      BEGIN;
        CASE;
          WHEN THE_d# ( node ) = 1 THEN i := THE_s# ( node);
          WHEN THE_d# ( node ) < 0 THEN i := i + THE_d# ( node );
          ELSE i := 0;
        END CASE;
      END;
    END FOR;
    RETURN T;
  END;
[/size]
There is no such thing as an empty statement.

Post Reply