This example has an old style, the use of lables/numbers, plus a modern one, call modules from Groups, like calling members of objects.
We have two examples:
The simple example without objects. Statement Goto jump to a line number (is a numeric label not actual the line number at editor), or a named label. Statement Gosub call code and expect a Return statement. Statement Return with parameters is a different statement from simple Return, and used to return items to specific data containers/tables of databases.
The module.name$ is the name of the current module, but not the actual inner name (which we can find it using module$, and is a compact string of the name space of current scope).
Module UseOfLineNumbers {
Print module.name$
Goto 10
Print "You can't see this..."
// we can use line numbers, like numeric labels
10 A=5
20 Gosub 1000
30 A--
40 If A>0 then 20
50 End
1000 Print "Code at line number 1000", A : return
}
Module UseOfLineLabels {
Print module.name$
Goto StartLine
Print "You can't see this..."
// we can use line numbers, like numeric labels
StartLine:
10 A=5
again:
20 Gosub mysubroutine
30 A--
40 If A>0 then goto again
50 End
mysubroutine: // only comments in same line with label
1000 Print "Code at line number 1000", A : return
}
Module UseOfLineLabels2 {
Print module.name$
Goto StartLine
Print "You can't see this..."
// we can use line numbers, like numeric labels
StartLine:
A=5
again:
Gosub mysubroutine
A--
If A>0 then goto again
End
mysubroutine: // only comments in same line with label
Print "Code at line number 1000", A : return
}
UseOfLineNumbers
UseOfLineLabels
UseOfLineLabels2
The advanced example with objects. We have the Beta object, as a Group in the current module. The modules of Group Beta ara modules of the current module (they have .beta. between the current module name and the calling module's name. The modules of Delta exist in a closed area, and for use them we have to attach the object temporary, then call, then deattach it. We can use For object { } block and do the attach once, then we call any number of modules, then at the exit of this block the deattach perform. The attach means that the inner lists of interpreter knows the modules,, by installing like those of Beta, and deattach means that the modules erased and the inner lists restored before th For object {}.
Also we see the deconstructor of a group, which automatic executed when the object lost the last pointer to it. Also we see that the Beta, the group without a usable pointer (has a hidden one), erased at a Clear or at the exit of Module/Function etc, without call the constructor, unless we use Clear Beta as tbe last statement for Beta,
Class Alfa {
Module UseOfLineNumbers {
Print module.name$
Goto 10
Print "You can't see this..."
// we can use line numbers, like numeric labels
10 A=5
20 Gosub 1000
30 A--
40 If A>0 then 20
50 End
1000 Print "Code at line number 1000", A : return
}
Module UseOfLineLabels {
Print module.name$
Goto StartLine
Print "You can't see this..."
// we can use line numbers, like numeric labels
StartLine:
10 A=5
again:
20 Gosub mysubroutine
30 A--
40 If A>0 then goto again
50 End
mysubroutine: // only comments in same line with label
1000 Print "Code at line number 1000", A : return
}
Module UseOfLineLabels2 {
Print module.name$
Goto StartLine
Print "You can't see this..."
// we can use line numbers, like numeric labels
StartLine:
A=5
again:
Gosub mysubroutine
A--
If A>0 then goto again
End
mysubroutine: // only comments in same line with label
Print "Code at line number 1000", A : return
}
remove {
Print "I am an Alfa, and I just deleted"
}
}
// Beta is a Group Object
// All named members exist on interpreter lists.
// this object deleted at the end of scope
Beta=Alfa()
For Beta {
.UseOfLineNumbers
.UseOfLineLabels
// .UseOfLineLabels2
}
Beta.UseOfLineLabels2
// Delta is a pointer to an object of type of Group
// This object deleted when no pointer point to it.
Delta->Alfa()
For Delta {
// at this point the object attach as Group, like Beta, but using a hidden name
.UseOfLineNumbers
.UseOfLineLabels
}
// Now object deattach from interpreter lists (for modules/variables)
// No use of . but => for pointers
// yhis call do attach/call/deattacb in one go
Delta=>UseOfLineLabels2
Print Delta is type Alfa
// Pointer() return the Null object (is an object of type Null)
Delta=Pointer()
// The previous object deleted but call the remove module (if exist any)
Print Delta is type Null
// Now Delta point to Beta, which is a Group
Delta=Pointer(Beta)
Print Delta is type Alfa
// Interpreter just change Delta=> with Beta
// So now we don't have attach/call/deattach but only call
Delta=>UseOfLineNumbers
Delta=>UseOfLineLabels
Delta=>UseOfLineLabels2
// now we erase all variables
REM :
Clear
// Beta group can't call the remove module
// We can call it using Clear Beta (but has to be the last statement for Beta)
REM : Clear Beta // hide the Clear statement above, unhide this line (press enter after :)
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.