From ba383a796028306e90645f38f011070d3c83cb6a Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Sat, 4 May 2024 21:53:18 +0300 Subject: [PATCH] fix(#3163): while logic is fixed --- eo-runtime/src/main/eo/org/eolang/while.eo | 15 +++-------- .../src/test/eo/org/eolang/while-tests.eo | 27 +++++++++++++------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/eo-runtime/src/main/eo/org/eolang/while.eo b/eo-runtime/src/main/eo/org/eolang/while.eo index ec43c8a296..987a3c50d2 100644 --- a/eo-runtime/src/main/eo/org/eolang/while.eo +++ b/eo-runtime/src/main/eo/org/eolang/while.eo @@ -29,22 +29,15 @@ # While. [condition body] > while if. > @ - condition.as-bool - start 0 + (condition 0).as-bool + loop 0 false - # First loop iteration that does not check condition. - [index] > start - seq > @ - * - ^.body index - ^.loop (index.plus 1) - - # Recursive + # Recursive loop. [index] > loop ^.body index > current if. > @ - ^.condition.as-bool + (^.condition (index.plus 1)).as-bool seq * current diff --git a/eo-runtime/src/test/eo/org/eolang/while-tests.eo b/eo-runtime/src/test/eo/org/eolang/while-tests.eo index 542df51713..f5f1060a10 100644 --- a/eo-runtime/src/test/eo/org/eolang/while-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/while-tests.eo @@ -26,11 +26,22 @@ +package org.eolang +version 0.0.0 +# Test. +[] > while-dataizes-only-first-cycle + eq. > @ + 0 + malloc.for + 42 + [m] + while > @ + i.eq 0 > [i] + m.put i > [i] + # Test. [] > simple-while-with-false-first not. > @ while > res - false + false > [i] true > [i] # Test. @@ -40,7 +51,7 @@ true [m] while > @ - m + m > [i] m.put false > [i] false @@ -51,7 +62,7 @@ 0 [m] while > @ - 2.gt m + 2.gt m > [i] m.put (m.as-int.plus 1) > [i] 3 @@ -59,7 +70,7 @@ [] > last-while-dataization-object-with-false-condition not. > @ while - 1.gt 2 + 1.gt 2 > [i] true > [i] # Test. @@ -78,7 +89,7 @@ acc.as-int.plus arr.at 0 while - max.gt iter + max.gt iter > [i] [i] seq > @ * @@ -100,7 +111,7 @@ 0 [iter] while > @ - max.gt iter + max.gt iter > [i] [i] seq > @ * @@ -122,7 +133,7 @@ 0 [iter] while > @ - [] + [i] if. > @ max.gt iter seq @@ -149,7 +160,7 @@ 0 [iter] while > @ - [] + [i] if. > @ max.gt iter seq