Jump to content

Add a variable to a class instance at runtime: Difference between revisions

no edit summary
No edit summary
Line 767:
<lang lua>empty = {}
empty.foo = 1</lang>
 
=={{header|M2000 Interpreter}}==
Adding y member to an object with a x member which made by a class alfa (a global function). We can make m as a copy of this new group (which is in a container, in a(3)). We can make a pointer to A(3) and handle the new member.
 
<lang M2000 Interpreter>
Module checkit {
class alfa {
x=5
}
\\ a class is a global function which return a group
Dim a(5)=alfa()
Print a(3).x=5
For a(3) {
group anyname { y=10}
\\ merge anyname to this (a(3))
this=anyname
}
Print a(3).y=10
Print Valid(a(2).y)=false
\\ make a copy of a(3) to m
m=a(3)
m.y*=2
Print m.y=20, a(3).y=10
\\ make a pointer to a(3) in n
n->a(3)
Print n=>y=10
n=>y+=20
Print a(3).y=30
\\ now n points to a(2)
n->a(2)
Print Valid(n=>y)=false ' y not exist in a(2)
Print n is a(2) ' true
\\ we don't have types for groups
Print valid(@n as m)=false ' n haven't all members of m
Print valid(@m as n)=true ' m have all members of n
}
checkit
</lang>
 
=={{header|Mathematica}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.