Category:M2000 Interpreter: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 82: | Line 82: | ||
For small programs, for learning algorithms there is no need to use types, except the major types, Numeric and String, plus one more: Integer. Integers can be number types like Long and Integer types, or can be any numeric type using without decimal part. So Integer variables are variables with % at the end of their name. String Variable need a $ at the end of name. |
For small programs, for learning algorithms there is no need to use types, except the major types, Numeric and String, plus one more: Integer. Integers can be number types like Long and Integer types, or can be any numeric type using without decimal part. So Integer variables are variables with % at the end of their name. String Variable need a $ at the end of name. |
||
For Expressions before execution automatic check by names if the result can be for strings names, or for numeric names. A string name has $ at the end of name. Maybe a string name isn't a string, because with same name we can define groups which get or and return strings values. A statement Input Alfa$ can input characters for a string or for object typed group with that name. Interpreter implicitly use the appropriate method. If name has no $ at the end then this can be an object or a numeric value. A Input Beta may return error if Beta has no numeric value to set. |
|||
Types are strong for values with a name (variables, constants), but weak for items in containers. In a container (Array, Inventory and Stack) we can place anything including other containers. We can bypass the "strong" capability but this isn't a practice for good programming. Internal or variables are of type of Variant, so we can make a reference of A to A$ and we can save a string "1212" and read from A the number 1212. |
|||
<lang > |
|||
Module AKindOfMess { |
|||
a=10@ |
|||
Print Type$(a)="Decimal" |
|||
\\ a and a$ reference same variant type |
|||
Link a to a$ |
|||
Print a$ |
|||
Let a$=str$(500.12, "") |
|||
Rem : a++ ' error can't aply ++ to a string type |
|||
Print type$(a)="String" ' true |
|||
' Error a=a+a |
|||
Print len(a$) |
|||
Print a=500.12 ' true |
|||
a$+=a$ |
|||
Print len(a$) |
|||
Print a$, a=0 |
|||
a$=Left$(a$, len(a$)/2) |
|||
Print a$ |
|||
Print a=500.12 |
|||
let a=100@ |
|||
Print Type$(a)="Double" |
|||
Print a$="100" ' true |
|||
For This { |
|||
M=23451234512345123451234512345@ |
|||
swap M, a |
|||
} |
|||
Print Valid(M)=false ' M not exist now |
|||
Print Type$(a)="Decimal" ' true |
|||
Print a$="23451234512345123451234512345" ' true |
|||
} |
|||
AKindOfMess |
|||
Print Valid(a)=false ' not exist |
|||
Print Valid(a$<>"")=false ' not exist |
|||
Print Valid(12/0)=false ' evaluate expression and return true if is ok (errors trapped always) |
|||
Print Error$="" |
|||
</lang> |
|||
So check this for proper use of types. |
|||
<lang >Module CheckInt { |
<lang >Module CheckInt { |