Create an object/Native demonstration: Difference between revisions

no edit summary
m (→‎{{header|Ring}}: Remove vanity tags)
No edit summary
Line 277:
{A=65, B=66, C=67}
</pre>
=={{header|M2000 Interpreter}}==
 
<lang M2000 Interpreter>
Module CheckIt {
Class LockedHash {
Private:
inventory Vars ' no same keys
unlock
module nosuchvariable {
Error "No such value:"+letter$
}
module NoNewItem {
Error "No new item, use unlock method before"
}
module NoRemoveItem {
Error "Can'tremove item, use unlock method before"
}
Public:
module Unlock {
.unlock<=True
}
module Writeln {
m=each( .Vars)
while m {
Print Quote$(Eval$(m, m^));",";Eval(m),
}
Print
}
Value (st$){
st$=Ucase$(st$)
if exist(.Vars, st$) then =Eval(.Vars) : Exit
.nosuchvariable st$
}
Set (st$){
st$=Ucase$(st$)
Read val
if exist(.Vars, st$) then Return .Vars, st$:=val : Exit
If .unlock then { Append .Vars, st$:=val} Else .NoNewItem
}
module Remove (st$) {
if not .unlock then .NoRemoveItem
st$=Ucase$(st$)
Try {
delete .Vars, st$
}
}
module Clear {
Clear .Vars
}
Class: ' this part exist only at construction
module LockedHash {
While match("SN") {
read st$, val
st$=ucase$(st$)
\\ if we append key which exist we get error
Append .Vars, st$:=val
}
}
}
d=LockedHash("a", 1, "b", 2)
d.writeln
d("a")=55 : d("b")=66
d.writeln
d.clear
d.writeln
d.unlock
d("a")=55 : d("b")=66
Print d("a")=55, d("a")/d("b")<1
d.remove "a"
d.writeln
}
Checkit
</lang>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>a[1] = "Do not modify after creation";
Anonymous user