[SAL-HELP] need some help in executing loops in SAL

Bruno Dutertre bruno at csl.sri.com
Fri Feb 16 09:55:30 PST 2007


suman kasam wrote:
> Hi,
>    
>      Can some one help me in executing loops in SAL.I have an array the sum of whose elements is 1.Thus if one of the element in the array is '1' I have to make remaining all as 0's.Can I use loop statements in SAL. If yes what is the syntax for its use.Presently iam trying to implement it using recursive function call.But if looping statements can be used it becomes pretty easy.
>    
>   Please help me in this .
>    
>   Thanking you,
>   Regards,
>   Suman Kasam
> 

Hi,

There is no imperative loop in SAL. But there are ways of defining arrays
that do not require defining recursive functions. For example, you can
write

  N: NATURAL = 10;
  ID: TYPE = [1..N];
  A: TYPE = ARRAY ID OF NATURAL;

  set_one(n: ID): A = [[i:ID] IF i=n THEN 1 ELSE 0 ENDIF];

Then set_one(n) is an array with one element 1 and all others 0.
You can also use array updates:

   all_zero: A = [[i:ID] 0];
   set(n:ID): A =  all_zero WITH [n] := 1;


Bruno



More information about the SAL-HELP mailing list