Contents

Succeed and link expressions

Introduction

These two expressions are designed to make returning from procedures and methods easier and more concise.

succeed

succeed expr

is just the same as

if expr then
   return
else
   fail

For example, consider :-

procedure is_positive(x)
   succeed x > 0
end

This procedure will succeed with &null if x > 0, and fail otherwise. If we were to use return instead of succeed, then the procedure would return 0 instead of &null.

succeed is particulary helpful in classes, which tend to have a lot of is_something methods. It avoids the return of rather arbitrary values, and also the accidental escape of variables to internal members and data structures.

succeed on its own (without an expression) has just the same meaning as return.

From within an instance method

link expr

is just the same as

if expr then
   return self
else
   fail

and from within a static method it is the same as

if expr then
   return EnclosingClass
else
   fail

where EnclosingClass is the class in which the method resides.

link on its own just returns self or EnclosingClass as appropriate.

link is designed to make it easier to take advantage of method chaining. For example, consider the following class :-

class Something()
   public f()
      ...
      link
   end

   public g()
      ...
      link
   end

   public static p()
      ...
      link
   end

   public static q()
      ...
      link
   end
end

We could then use :-

x := Something().
       f().
       g()

y := Something.
       p().
       q()

leaving x as the Something instance, and y as Something.

Contents