SeedV / SeedLang

An embeddable and visualizable scripting engine for .Net and Unity.
https://seedv.github.io/SeedLang/
Apache License 2.0
9 stars 1 forks source link

The order of getting V-tag parameter values in bubble sort algoirthm #192

Closed wixette closed 2 years ago

wixette commented 2 years ago

After https://github.com/SeedV/SeedLang/pull/191 was merged, the order of V-tag notifications for a bubble sort algorithm look like the following output:

Code:

a = [8, 1, 0]
for i in range(len(a)):
    for j in range(len(a) - i - 1):
        # [[ Compare(j, j+1) ]]
        if a[j] > a[j + 1]:
            # [[ Swap(j, j+1) ]]
            a[j], a[j + 1] = a[j + 1], a[j]

The output of SeedLang:

dotnet run --project src/SeedLang.Shell -- -v VTagEntered,VTagExited -f test.py
SeedLang.Shell 0.2.1-preview20220509143517
Copyright 2021-2022 The SeedV Lab.

Enabled Visualizers: VTagEntered, VTagExited

---------- Source ----------
1     a = [8, 1, 0]
2     for i in range(len(a)):
3         for j in range(len(a) - i - 1):
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]

---------- Run ----------
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Compare(j,j+1)
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Swap(j,j+1)
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Swap(0,1)
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Compare(0,1)
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Compare(j,j+1)
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Swap(j,j+1)
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Swap(1,2)
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Compare(1,2)
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Compare(j,j+1)
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagEntered: Swap(j,j+1)
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Swap(0,1)
4             # [[ Compare(j, j+1) ]]
5             if a[j] > a[j + 1]:
6                 # [[ Swap(j, j+1) ]]
7                 a[j], a[j + 1] = a[j + 1], a[j]
VTagExited: Compare(0,1)

The order of the VTagEntered/VTagExited events are very interesting:

The Swap's events are embedded in between the VTagEntered/VTagExited events of Compare.

Since the client code should play the animation of Compare firstly, and play the Swap animation secondly, how can the client code play the two animations in correct order given the parameter values of Swap arrive first via VTagExited: Swap(0,1) and the parameter values of Compare arrive secondly via VTagExited: Compare(0,1)?

  1. Can the V-tag parameter values be evaluated when VTagEntered event is sent out?
  2. Or, can the client code evaluate the values of j and j+1 when VTagEntered event is received?
  3. Any other better solutions?