| #------------------------------------------------------------- |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| # |
| #------------------------------------------------------------- |
| |
| add_and_return = function(Int i_old, List[String] l_old) |
| return(Int i, List[String] l) |
| { |
| i = i_old + 1 |
| if (TRUE) |
| l = append(l_old, toString(i)) |
| else |
| l = append(l_old, toString(i)) |
| } |
| |
| # Works! |
| init = function() return(Int i, List[String] l) {i=0; l=list();} |
| [test_i, test_l] = init() |
| |
| [test_i, test_l] = add_and_return(test_i, test_l) |
| [test_i, test_l] = add_and_return(test_i, test_l) |
| [test_i, test_l] = add_and_return(test_i, test_l) |
| |
| #while(FALSE){} # cut |
| |
| # Does not work! |
| test_fail_i = 0 |
| test_fail_l = list() |
| [test_fail_i, test_fail_l] = add_and_return(test_fail_i, test_fail_l) |
| [test_fail_i, test_fail_l] = add_and_return(test_fail_i, test_fail_l) |
| [test_fail_i, test_fail_l] = add_and_return(test_fail_i, test_fail_l) |
| |
| if( test_i != test_fail_i ) |
| print("test_i discrepancy: "+test_i+" vs "+test_fail_i); |
| |
| if( toString(test_l) != toString(test_fail_l) ) |
| print("test_l discrepancy: "+toString(test_l)+" vs "+toString(test_fail_l)); |