Jump to content

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

Mathematica
m (Fixed lang tags.)
(Mathematica)
Line 146:
<lang lua>empty = {}
empty.foo = 1</lang>
 
=={{header|Mathematica}}==
Mathematica doesn't rally have classes, so it doesn't have class variables. However, many rules can be applied to a single tag, so it has some aspects similar to a class. With that definition, adding a class variable is similar to adding a rule:
<lang Mathematica>
f[a]=1;
f[b]=2;
f[a]=3;
? f</lang>
Global`f
f[a]=3
f[b]=2
 
Here, the two 'variables' can be seen under the single heading 'f'. And of course all of this is done at runtime.
 
=={{header|Perl}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.