Ludii Forum
A general solution to scope issues? - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Suggestions (https://ludii.games/forums/forumdisplay.php?fid=10)
+--- Forum: Ludii Features / Services (https://ludii.games/forums/forumdisplay.php?fid=11)
+--- Thread: A general solution to scope issues? (/showthread.php?tid=624)



A general solution to scope issues? - Michael - 06-30-2021

I often find my self in the predicament that I want to refer to two different values that has the same variable-name. Here is an example:

I am trying to figure out how to detect a flanked arc (as defined in this thread), and am currently trying to see if I can use (count Steps) to detect a path of enemy pieces between two friendly pieces. In the course of thinking through how to do this, I was stopped by a clash between variable names.
Code:
(move Select
    (from (sites Occupied by:Mover))
    (to
        (sites Occupied by:Mover)
        if:(>
            (count Sites in:(sites Board))
            (count Steps
                (step
                    (to
                        if:(or
                            (= (next) (who at:(to)))
                            (= (to) (to)) //<----- THIS LINE
                        )
                    )
                )
                (from)
                (to)
            )
        )
    )
)
The line I have marked "THIS LINE" is obviously useless. But what I want to do is to differentiate between what (to) refers to in the scope of (step (to if:(…))) and what it refers to in (move Select (to if:(…))) outside of (step (to if:(…))).

Since this shows up so often, I thought it would be worth asking: Could there be implemented a general solution to this?


RE: A general solution to scope issues? - Eric Piette - 07-01-2021

Hi,

No, if the ludemes are using the same variables we can not provide a solution to that. However, when you go outside of the ludeme, the different variables restored their latest values in all our ludemes.
Sometimes you can just store the value you need in a temporary variable in the middle of your description with (do (set Var "TempVar" (to)) next:<YourCodeAboutTheMove>).

But in all the games I did (around 770) I never had to do that, so I suppose for each situation I had to describe another way always existed.
If at some point, I have some time, I will try to describe your arc capture in an example and submitted to the corresponding thread.

Regards,
Eric


RE: A general solution to scope issues? - Michael - 08-15-2021

(07-01-2021, 07:03 AM)Eric Piette Wrote: No, if the ludemes are using the same variables we can not provide a solution to that.
I'm exposing my naivete here, but I have to ask: Can't the ludemes that use iterators such as (site), (to) and (value) have a parameter like renameIterator or labelIterator, and you pass it a string, so that the iterator is either renamed, like (newName), or labeled, like (to "label")? This latter approach is in line with what you did with (var).


RE: A general solution to scope issues? - Eric Piette - 08-17-2021

Hi,

That's in theory possible, yes, and I can see why you would need that. But I am not sure we want that for optimisation reasons. I am keeping that in mind and I come back to you if we are doing something in that sense.

Regards,
Eric


RE: A general solution to scope issues? - Eric Piette - 08-18-2021

Hi,

Ok, I looked at that, and in reality no we can't. The variables are used between different ludemes in entry and by consequent, they can't be named like (var ...) can.
For (var ...) that's a variable used only how wants the designer to compare to these other variables with real meaning for the ludeme using them.
But until now, no game was impossible because of that, so I do not think that's a real problem.

Regards,
Eric