Τετάρτη 18 Οκτωβρίου 2017

Revision 41, Version (8.9)

Ελληνικά:
Αναθεώρηση 41, έκδοση 8.9.
Σε αυτήν την αναθεώρηση λύθηκε μερικώς ένα ζήτημα που προέκυψε από την χρήση της υπερκλάσης. Με την λύση αν προβούμε σε διπλό άνοιγμα της υπερκλάσης θα βγει λάθος. Αυτό συμβαίνει γιατί μια διαδικασία αντιγράφει τιμές τις υπερκλάσης για χρήση, και μετά τις επαναφέρει, οπότε αν γίνει "φωλιασμένα" θα έχουμε επαναφορά, και μετά νέα επαναφορά τιμών, άρα η πρώτη θα χαθεί. Αυτό φαίνεται στο τρίτο παράδειγμα, όπου δεν μπορεί να πιάσει το ζήτημα ο διερμηνευτής, όπως το πιάνει στη περίπτωση των πρώτων παραδειγμάτων. Εκεί λοιπόν το πιάνει γιατί γνωρίζει ότι πάει να ανοίξει τη υπερκλάση, από την υπερκλάση!
Η υπερκλάση στη Μ2000 είναι η κλάση σε άλλες γλώσσες. Αυτό το πρόβλημα σε άλλες γλώσσες λύνεται με την συνεχή χρήση του self (βλέπε Python). Δηλαδή εκεί δουλεύει αντίστροφα. Όλα τα αναγνωριστικά της κλάσης δουλεύουν για την κλάση, και πρέπει να χρησιμοποιεί κανείς το Self για την "παρουσία" (Instance) του αντικειμένου.

English:
A new revision for a solution when we open a superclass to access superclass members, and this happen when already is open.

Three examples show this situation .One solution is given by raise an error if we do double open, but as we see in third example there is a situation that this didn't work.

Just open m2000.exe (interpreter), write Edit A, press enter, copy first script, then press Esc to exit, then write Edit B and continue with the second, then repeat for the third in a module say C.
We can anyone by name: Write A and press enter
Use this: Save example1
and after: New  (or Start for a software reset)






you can use Clear and Flush (clear variables if any, and flush stack for values)

Load axemple1 
to reload modules.


Also these examples show how to migrate a Superclass in a lambda function to produce instances.
Also keep in mind that Group objects in M2000 are not referenced entities, are always values.  (internal there is a pointer for each object, only one, and this pointer never doubled)

\\ First Example
\\ return error
\\ We can't open Superclass in Superclass;
Function Super1 {
      SuperClass S {
            name$="Hello"
            Module Super {
                  For SuperClass {
                        Read .name$
                  }
            }
            Module PrintData {
                  For SuperClass {
                        Print .name$;" "; This.name$
                        .name$<=.name$+"."
                        Print .name$
                  }
            }
        
      }
      =Lambda S (n$) -> {
            make_it=S
            group make_it { name$=n$}
            =make_it
      }
}
CreateSuper1=Super1()
A=CreateSuper1("World")
Group a {
      \\ change an object module
      \\ which use SuperClass
      Module PrintData {
            For SuperClass {
                  .PrintData "??????"
                  .PrintData "!!!!!!!!"
            }
      }
}
A.PrintData


This is the second example:

\\ Second example
\\ Error of first example now removed
\\ There are two Modules, one as Super.PrintData (tha name can be anything)
\\ and another as PrintData. If we want to change PrintData now is possible to do,
\\ and we can call the original PrintData as the second part


Function Super1 {
      global temp$="Hello"
      Read ? temp$
      \\ we can pass im construction values
      \\ using global temporary values.
      SuperClass S {
            name$=temp$
            Module Super {
                  For SuperClass {
                        Read .name$
                  }
            }
            Module Super.PrintData (aname$){
                  \\ this part has local items and the Supetclass items
                  For SuperClass {
                        Print .name$;" ";aname$
                        .name$<=.name$+"."
                        Print .name$
                  }
            }
            Module PrintData {
                        \\ for using it as Virtual module
                        \\ we have to split it
                        \\ this part has the instance members
                        .Super.PrintData .name$
            }
        
      }
      =Lambda S (n$) -> {
            make_it=S
            group make_it { name$=n$}
            =make_it
      }
}
CreateSuper1=Super1()
CreateSuper2=Super1("Master")
A=CreateSuper1("World")
Z=A
Group a {
      \\ change an object module
      \\ which use SuperClass
      Module PrintData {
            .Super.PrintData "??????"
            .Super.PrintData "!!!!!!!!"
      }
}
A.PrintData
A=CreateSuper2("George")
A.PrintData
Z.PrintData
List


And this is the final example:

\\ Third Example
\\ Here we check if we can call SuperClass from different  objects
\\ As we can see, this can be happen
\\ The problem is that Interpreter can't find it
Function Super1 {
      Global What$="Hello"
      Read ? What$
      SuperClass S {
            name$=What$
            Function Super.Name$ {
                  For SuperClass {
                        =.name$
                  }
            }
            Module Third {
                  .PrintData
            }
            Module Second (&M) {
                 \\ For SuperClass work with Copies and at the exit, these copies copied back
                 For SuperClass {
                        Print .name$;" ";M.name$
                        Try {
                              .PrintData
                              \\ error
                        }
                        Try {
                              .Third
                              \\ error - try shadow Try
                        }
                        M.PrintData
                        \\ no error but changed .name$ now lost.
                        ? .name$
                  }
            }
            Module PrintData {
                   For SuperClass {
                        Print .name$;" ";This.name$
                        .name$<=.name$+"."
                        Print .name$
                  }
            }
        
      }
      =Lambda S (n$) -> {
            make_it=S
            group make_it { name$=n$}
            =make_it
      }
}
L1=Super1("Hello There")
N1=L1("George")
N1.PrintData
N2=L1("Bob")
N2.PrintData
\\ here is the problem
\\N1 take a reference of N2
\\ then open SuperClass, and before close it
\\ call N2.printdata which opens the same SuperClass
\\ We make a change in .name$
\\ And that change lost;
N1.Second &N2
Print N1.Super.Name$(), N2.Super.Name$()
Print valid(@N2 as N1) \\ -1 Same SuperClassess, and N1 members names exist in N2
\\ here we put fresh lambda functions
\\ old lambdas destroyed. But N1 and N2 have both a pointer to SuperClass
L1=Super1("Hello There")
L2=Super1("Hello There")
\\ and here we merge new groups, and passing new SuperClass, differnet to each one
N1=L1("George")
N1.PrintData
\\ here the last pointer to hold first SuperClass changed, so first Superclass destroyed
N2=L2("Bob")
N2.PrintData
\\ Here there is no problem
\\ because N1 Superclass is different from N2
\\ Although each Superclass are equal, for members and functionality, and state.
\\ They are real different objects.
N1.Second &N2
Print N1.Super.Name$(), N2.Super.Name$()
Print valid(@N2 as N1) \\ 0 Different Superclasses (no search for members names existance)
' at the exit of this module (name isn't provided here, choose one, then write Edit MyName and paste this code. Then press Esc and write MyName and press Enter to run it)


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

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

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