Category:M2000 Interpreter: Difference between revisions

Content added Content deleted
No edit summary
Line 237: Line 237:


We can place a lambda function as closure in a lambda function, and we can build a program as one "top" function, and many lambda as closures, which may have other lambda functions. Closures can be change values from lambda but not from outside unless they are pointers (so we may have same pointers outside of lambda, or in another lambda. A lambda variable can change function and closures in a new assignment. We can store lambda state (if we don't use pointers in closures) in a new variable which take as first value lambda (and then can take only lambda functions)
We can place a lambda function as closure in a lambda function, and we can build a program as one "top" function, and many lambda as closures, which may have other lambda functions. Closures can be change values from lambda but not from outside unless they are pointers (so we may have same pointers outside of lambda, or in another lambda. A lambda variable can change function and closures in a new assignment. We can store lambda state (if we don't use pointers in closures) in a new variable which take as first value lambda (and then can take only lambda functions)


a class define a type too. We can make a class from other classes too. We can make inner classes too.
<lang >
Form 80,50
\\ counters supposed we provide them from a file
global LastCustomerId=100, ReportId=80
\\
class person {
Private:
name$, address$, phone$, id
class:
module person (.name$, .address$, .phone$) {
LastCustomerId++
.id<=LastCustomerId
}
}

class customer as person {
Inventory sales
Class bill {
Private:
day$, time$, id
Public:
\\ read only property (is a group inside group)
Property euro {value}
Function Key$ {
=.day$+"/"+.time$+"#"+str$(.id,"")
}
class:
Module bill (.day$, .time$, .id, .[euro]) {
}
}
Module CustomerData {
ReportId++
Print "Report date:"; Date$(Today)
Print "ReportId:";ReportId
Print "Customer:";.id
Print "Name",.name$
Print "Address",.address$
Print "Phone", .phone$
Print "Transactions:";len(.sales)
m=each(.sales)
sum=0
While m {
bill=eval(m)
sum+=bill.euro
}
Print "Total Euro:";sum
}
Module InsertBill (bill as bill) {
try {
Print "New bill:";bill.key$();" for customer ";.id
Append .sales, bill.key$():=bill
}
}
Class:
Module customer (Where, m as person) {
this<=m
append where, .id:=This
}
}

Inventory Customers
Pen 15 {Print "Adding to Customers"}
For This {
\\ this is a block for temporary definitions
K=Customer(Customers, person("George","Athens","0912399"))
K.CustomerData
\\ after that group K deleted
}
Pen 15 {Print "Using key to customers to add bills"}
For Customers(LastCustomerId) {
.InsertBill .bill("20200522", "18:33", 1023, 100)
.InsertBill .bill("20200526", "09:10", 3129, 150)
.InsertBill .bill("20200530", "13:20", 5418, 25)
.CustomerData
}
Pen 15 {Print "Using Iterator 1 - working at original data"}
M=each(Customers)
While M {
\\ we extract key using eval$(M!)
\\ so we can work from original data
For Customers(eval$(M!)) {
.CustomerData
}
}
Pen 15 {Print "Using Iterator 2 - working at a copy of data"}
M=each(Customers)
While M {
\\ or using a copy of data
K=Eval(M)
For K {
.CustomerData
}
}
</lang>



Until now we see modules/functions/subs for procedural programming, Groups for OOP, Groups as lambda functions and lambda functions for functional programming. We can use events for groups and for COM objects, including GUI objects.
Until now we see modules/functions/subs for procedural programming, Groups for OOP, Groups as lambda functions and lambda functions for functional programming. We can use events for groups and for COM objects, including GUI objects.