Add a variable to a class instance at runtime: Difference between revisions
Content added Content deleted
m (→{{header|Icon}} and {{header|Unicon}}: comment on safety) |
|||
Line 273: | Line 273: | ||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
{{omit from|Icon}} |
{{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. |
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). |
''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: | Line 329: | ||
R_tempconstructor_1.d := 9 |
R_tempconstructor_1.d := 9 |
||
R_tempconstructor_1.e := 7</pre> |
R_tempconstructor_1.e := 7</pre> |
||
=={{header|J}}== |
=={{header|J}}== |