1. Fix the Editor and EditBox, from bugs in revision 29 and 28. Also I added extra logic for code coloring for multiple variables assignment.
2. Multiple Variables Assignment
Reading a tutorial about SCALA I found the syntax for multiple assignment easy to code in M2000. The code below is part of Info file in setup file of M2000.
Dim B(10)=0
(A,B$,B(1))=(100, "Yes", 4)
Print A, B$, B(1)
\\ global X, Y
Set (X,Y)=(4, 5)
Print X, Y
\\ global shadow old global
Set (New X, Y)=(5, 6)
Push (A, B(1))
\\ Set exexute in command line, so A and B(1) isn't visible
\\ we have to place values in stack, so the Set statement get the current stack
\\ and array return the array
Set (X, Y)=Array
Print X, Y
List
\\ define a multi return value as array
Function Alfa(){
=100, 200
}
(M, N)=Alfa()
Print M, N
Dim Z()
Z()=(1,2)
(M, N)=Z()
Print M, N
(A,B$,B(1))=(100, "Yes", 4)
Print A, B$, B(1)
\\ global X, Y
Set (X,Y)=(4, 5)
Print X, Y
\\ global shadow old global
Set (New X, Y)=(5, 6)
Push (A, B(1))
\\ Set exexute in command line, so A and B(1) isn't visible
\\ we have to place values in stack, so the Set statement get the current stack
\\ and array return the array
Set (X, Y)=Array
Print X, Y
List
\\ define a multi return value as array
Function Alfa(){
=100, 200
}
(M, N)=Alfa()
Print M, N
Dim Z()
Z()=(1,2)
(M, N)=Z()
Print M, N
Using Set we send the line to command line interpreter where we have global scope, So we can assign values to global variables too.
The left part of assign operator = are the Read parameters and the right part is a tuple (a kind of array) which we get a copy from this to a new stack object from where we read the values.
Because of Read Statement we can use New or/and type definitions
Syntax
(A, B)=(1,2)
is equal to this:
Stack New {Data ! (1, 2) : Read A, B}
Type definitions (for strings the name declare the type, see $). Literal 100 is double type, and 20& is long type. So we get the values with conversion. M2000 interpreter check for overflow and raise error.
(A as currency, B as double, C$)=(100, 20&, "ok")
Print Type$(A)="Currency", Type$(B)="Double"
Print Type$(A)="Currency", Type$(B)="Double"
Function may return values using just comma but the first value must be numeric/object or string, depends from name (a $ as last character means string). To override that we can use a tuple for return values so =("alfa",100, 200) is an object so can be used for numeric expression. All user functions may return a value 0 and an object, or a value and nothing for object, and for enumerations we get value and object together.
Enum Pets {Dog, Cat}
(A,B,C)=(Dog, Cat, Dog)
Print A=1, B=2, C=1 ' true all
Print Eval$(A)="Dog", Type$(A)="Pets" ' true all
N=Dog
N++
(D as Pets, M as array)=(N, (1,2,3))
Print Type$(D)="Pets", Len(M)=3, M#sum()=6 ' all true
(A,B,C)=(Dog, Cat, Dog)
Print A=1, B=2, C=1 ' true all
Print Eval$(A)="Dog", Type$(A)="Pets" ' true all
N=Dog
N++
(D as Pets, M as array)=(N, (1,2,3))
Print Type$(D)="Pets", Len(M)=3, M#sum()=6 ' all true
Enjoy M2000
George Karras
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.