Anonymous user
Add a variable to a class instance at runtime: Difference between revisions
Add a variable to a class instance at runtime (view source)
Revision as of 17:01, 27 December 2011
, 12 years ago→{{header|Icon}} and {{header|Unicon}}: comment on safety
m (→{{header|Icon}} and {{header|Unicon}}: comment on safety) |
|||
Line 273:
=={{header|Icon}} and {{header|Unicon}}==
{{omit from|Icon}}
Unicon implements object environments with records and supporting procedures for creation, initialization, and methods. To modify an instance you must create a new record then copy and amend it. The procedures ''constructor'' and ''fieldnames'' are needed. This example doesn't do error checking. Here ''extend'' takes three arguments, the class instance, a list of new variable names as strings, and an optional list of new values to be assigned. As written this isn't safe from name collisions - aside from local declarations the use of a fixed constructor name uses the global name space.
''Note:'' Unicon can be translated via a command line switch into icon which allows for classes to be shared with Icon code (assuming no other incompatibilities exist).
Line 329:
R_tempconstructor_1.d := 9
R_tempconstructor_1.e := 7</pre>
=={{header|J}}==
|