Κυριακή 5 Ιουλίου 2020

An example of Scope Checking in M2000

This code is in a module A
We do this: Start M2000 Environment, Write Edit A and press Ente then rpaste the code press Esc write A press Enter. Just so simple. Write Save example1 so now you can do next time Load example1. Use New if you have another, or better write Start press enter to make a soft reset. Also you can clear variables only (and static variables) using Clear. You can empty the Stack of values using Flush.

Function Master {
    Module Alfa {
        Gosub 100
        Global M=1000
        \\ delta print 1000
        delta
        End
    100    Print Module(Beta)=False
        Print Module(Delta)=True
        Return
    }
    Group Object1 {
        Function Master {
            =M
        }
        Module Final Beta {
            \\ delta print 500
            delta
            alfa()
            Sub alfa()
                Local N=@Kappa(3)
                Global M=N
                \\ delta print 1500
                Delta
                Print This.Master()=1500
                N=@Kappa(6)
                \\ change value of M, not shadow M like Global M
                M<=N
                \\ delta print 9000
                Delta
                Print .Master()=9000
            End Sub
            Function Kappa(K)
                =M*K
            End Function
        }
    }
    Module Global Delta {
        Goto name1
        \\ a remark here
    
    name1:
        Print Module(Alfa)=False
        Print Module(Beta)=False
        Print Module(Delta)=True
        Print M
    }
    
    \\ This is the program
    K=100
    Global M=500
    Alfa
    Object1.Beta
    Print Object1.Master()=500
    Print K=100, M=500
}


Call Master()
\\ No variables exist after the return from Master()
Print Valid(M)=False

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.