-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMathObject.m
625 lines (482 loc) · 21.7 KB
/
MathObject.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
(* ::Package:: *)
(* :Title: MathObject *)
(* :Context: MathObject` *)
(* :Summary: Object oriented programming infrastructure *)
(* :Author: Mark A. Caprio, Department of Physics, University of Notre Dame *)
(* :Copyright: Copyright 2011-2021, Mark A. Caprio *)
(* :Package Version: 1.0.1 *)
(* :Mathematica Version: 12.1 *)
(* :History:
May 2011. Initiated. [Version 1.0]
June 23, 2021. Rename ObjectExistsQ to MathObjectExistsQ, as minimal patch to API
to avoid conflict with new System`ObjectExistsQ (Mathematica 12.1). [Version 1.0.1]
*)
(* :Discussion:
To use the package, the contexts "MathObject`", "MathObject`Methods`", and
"MathObject`InstanceData`" should all be in the $ContextPath.
For interactive use: It always suffices to evaluate Get["MathObject`"], though
this will cause the package to be reloaded unnecessarily if already loaded. It
normally suffices to evaluate Needs["MathObject`"], but this will fail to add
the subcontexts to the $ContextPath if the package has already been loaded, say,
privately to another package. The completely proper way to load the package is
through
Needs["MathObject`"];
Needs[""MathObject`Methods`"];
Needs["MathObject`InstanceData`"];
For internal use by a package: These Needs calls should be evaluated after
BeginPackage.
For both internal use by a package *and* for subsequent external use outside the
package: It is necessary to evaluate
BeginPackage["...",{MathObject`","MathObject`Methods`","MathObject`InstanceData`",...}]
Major limitation: Method names are in globally accessible namespace and
therefore can easily be hidden, e.g., by a local symbol of the same name within
a Module. For example:
Module[
{x},
x=27;
Object@x[]; (* FAILS *)
];
Future reimplementation: With the introduction of a dictionary-like data type
(Association) in Mathematica 10.0, it might be more robust and/or efficient to
reimplement this object oriented programming framework in terms of
associations, both to hold the global object space (and, in fact, allow
multiple independent object spaces) and to store the members for each object
instance, as in the Pythonic implementation of objects.
API history:
Mathematica 12.1 introduced a new symbol ObjectExistsQ in the System context,
which overloaded the corresponding symbol in the MathObject V1.0 API.
MathObject Version X.X thus introduces an overhauled API, with the general
principle that "Object" becomes "MathObject", and "Class" becomes "MathClass".
Here is an explicit mapping:
Object => MathObject
DeclareClass => DeclareMathClass
Destroy => DestroyMathObject
SetObjectData => SetMathObjectData
ObjectExistsQ => MathObjectExistsQ
ObjectClass => MathObjectClass
ObjectName => MathObjectName
ShowObject => ShowMathObject
ClassAncestry => MathClassAncestry
ClassPattern => MathClassPattern
ObjectPattern => MathObjectPattern
ObjectNamePattern => MathObjectNamePattern
ScopeObjects => ScopeMathObjects
ClearObjects => ClearMathObjects
ConstructorWrapper => MathClassConstructorWrapper (make private)
*)
(*Begin package*)
(*Package context definition*)
BeginPackage[
"MathObject`",
{"MathObject`Methods`","MathObject`InstanceData`"}
];
Unprotect[Evaluate[$Context<>"*"]];
(*Usage messages*)
Object::usage="Object[name] signifies an object of the given name.";
DeclareClass::usage="DeclareClass[class,[parent,]{data1,data2,...},{method1,method2,...}] declares a class of objects, with given members.";
Destroy::usage="Destroy[object] destroys object. Destruction is carried out by executing a generic destruction function, which in turn invokes the user-defined destructor as one step in the process.";
SetObjectData::usage="SetObjectData[o2,o1] populates all data fields in o2 with the values assigned for o1. The object o1 must be of the same class as o2 or a daughter class, so insure that all these fields are present.";
MathObjectExistsQ::usage="MathObjectExistsQ[object] returns True if object is defined, i.e., has been created and not subsequently destroyed.";
ObjectClass::usage="ObjectClass[object] returns the class type of object.";
ObjectName::usage="ObjectName[object] returns the name of object. (This is an expression, not necessarily a string.)";
ShowObject::usage="ShowObject[object] displays diagnostic information for object.";
ClassAncestry::usage="ClassAncestry[class] returns a list {...,grandparent,parent,class} of the class and its ancestors.";
ClassPattern::usage="ClassPattern[class] matches the class name of the given class or any descended class.";
ObjectPattern::usage="ObjectPattern[class] matches any object of the given class or any descended class.";
ObjectNamePattern::usage="ObjectNamePattern[class] matches the *name* of any object of the given class or any descended class.";
ScopeObjects::usage="ScopeObjects[body] evaluates body, and afterwards destroys all new objects remaining from the evaluation of body.";
ClearObjects::usage="ClearObjects[] removes all object instance data and clears the list of registered objects, without calling destructors.";
ConstructorWrapper::usage="MathObject internal implementation function. External access is only needed in special circumstances for defining nonstandard syntaxes for calling the constructor.";
$ObjectClass::usage="Global storage for Object (not intended for direct access by user but visible for diagnostic purposes).";
$ObjectInstanceIdentifier::usage="Global storage for Object (not intended for direct access by user but visible for diagnostic purposes).";
$ObjectReference::usage="Global storage for Object (not intended for direct access by user but visible for diagnostic purposes).";
$ObjectRegistry::usage="Global registry of created objects (not intended for direct access by user but visible for diagnostic purposes).";
(*Global data*)
$ObjectMethodContext="MathObject`Methods`";
$ObjectInstanceContext="MathObject`InstanceData`";
$ObjectRegistry={};
(*Begin private context*)
Begin["`Private`"];
(*Dependencies*)
(*Error message utility*)
(*Conversion of argument list to string*)
ListToString[l_List]:=StringJoin@@Riffle[ToString/@l,","];
(*Class definition*)
(*Class declaration function*)
(*Declaration for class serves to:*)
(* Define the special constructor access syntax for the class.*)
(* Define mutator and accessor methods (SetXXXX[] and GetXXXX[]) for all the data member, declared so that they appear in the present context.*)
(* Declare all other method symbols, so that they appear in the present context.*)
(* Record the full set of method symbols, so that method calls can later be validated against them.*)
(* Record the data member and method names in string form, for possible later inheritance by other classes.*)
(* Record the parent class (or None), just in case that information is ever useful (it is not presently).*)
(* Record clobbering permission for this class.*)
(*Class data:*)
(* ClassDataMemberNames[class] -- list of data member name strings (needed for inheritance)*)
(* ClassMethodNames[class] -- list of the method name strings (needed for inheritance)*)
(* These are only the names given explicitly as the argument of DeclareClass, therefore excluding mutators/accessors (and the constructor/destuctor)*)
(* ClassMethods[class] -- list of method symbols allowed for valid method calls (for method call validation)*)
(* These therefore include both the explicitly named methods and the autogenerated mutators/accessors. *)
(* However, the list excludes the constructor/destuctor, since these are invoked with a special syntax rather than the usual method call syntax.*)
(* ClassParent[class] -- parent class name or None (recorded for possible future use, though not presently needed)*)
(* ClassAllowClobber[class] -- if an attempt is made to construct a new object (of any class) with the same name as a member of the present class, whether the constructor should be allowed to destroy (clobber) the existing object of the present class, or else fail with a call to the creation failure hook*)
Options[DeclareClass]={Replace->False};
DeclareClass[Class_Symbol,Parent_Symbol:None,DataMemberNamesP:{___String},MethodNamesP:{___String},OptionsPattern[]]:=
Module[
{s,DataMemberNames,MethodNames,MutatorAccessorMethods,ExplicitMethods},
(* inherit data member and method names if applicable *)
DataMemberNames=
Join[
DataMemberNamesP,
If[Parent===None,{},ClassDataMemberNames[Parent]]
];
MethodNames=
Join[
MethodNamesP,
If[Parent===None,{},ClassMethodNames[Parent]]
];
(* constructor invocation syntax *)
(* no name -- Class[args] *)
Class/:HoldPattern[Class[Args___]]:=
ConstructorWrapper[Class,Object[None]][Args];
(* name -- Class[[name]][args], or case of no name accepted as Class[[]][args] *)
(* Note: Intermediate reference to ConstructorWrapper[] without [Args] necessary since the definition
Class/:HoldPattern[Class[[n_:None]][Args___]]:=ConstructorWrapper[Class,Object[n]][Args];
places Class at too deep a level to be matched. *)
Class/:HoldPattern[Class[[n_:None]]]:=ConstructorWrapper[Class,Object[n]];
(* define data member mutators and accessors *)
MutatorAccessorMethods=
Table[
With[
{
SetMethod=ToExpression[$ObjectMethodContext<>"Set"<>s],
GetMethod=ToExpression[$ObjectMethodContext<>"Get"<>s],
MemberIdentifier=ToExpression[$ObjectMethodContext<>ToString[Class]<>"$"<>s]
},
SetMethod[Class,Self_Object][Value_]:=($ObjectInstanceIdentifier[Self][MemberIdentifier]=Value;Null);
GetMethod[Class,Self_Object][]:=($ObjectInstanceIdentifier[Self][MemberIdentifier]);
{SetMethod,GetMethod}
],
{s,DataMemberNames}
];
(* define symbols for explicit methods *)
ExplicitMethods=
Table[
ToExpression[$ObjectMethodContext<>s],
{s,MethodNames}
];
(* save data member and method lists *)
ClassDataMemberNames[Class]=DataMemberNames;
ClassMethodNames[Class]=MethodNames;
ClassMethods[Class]=Flatten[{MutatorAccessorMethods,ExplicitMethods}];
ClassParent[Class]=Parent;
(* record clobbering permission for this class *)
ClassAllowClobber[Class]=OptionValue[Replace];
(* return Null *)
Null
];
(*Method access*)
(*Constructor wrapper function*)
(*Tasks:*)
(* Checks for existing object of same name -- if present, clobbers or fails as appropriate.*)
(* Registers object for scoping.*)
(* Sets object metadata (identifier).*)
(* Calls Constructor hook.*)
(* If Constructor hook fails to evaluate (i.e., wrong argument sequence):*)
(* Displays error message.*)
(* Calls destructor wrapper to remove metadata. (CAVEAT: User destructor should therefore not assume constructor has run.)*)
(* Calls hook function OnCreationFailure[Class,Self][], which, e.g., might be defined to throw an Abort[].*)
(* Returns $Failed.*)
(*Return value is Self (or $Failed).*)
General::objdupl="Cannot create object `1`[[`2`]], since an object named \"`2`\" already exists (as an instance of class `3`).";
General::objsyntax="Missing or unexpected arguments in `1``2`[`3`]. (The given arguments do not match any of the definitions for the constructor for class `1`.)";
UniqueObjectBaseName=$ObjectInstanceContext<>"Object$";
ConstructorWrapper[Class_Symbol,AlmostSelf:Object[AlmostName_]][Args___]:=
Module[
{Self,Name,NameArgumentString,Result,Aborted},
(* obtain object name if given as None *)
Name=If[
AlmostName===None,
Unique[UniqueObjectBaseName],
AlmostName
];
Self=Object[Name];
(* check for duplicate creation *)
If[
MathObjectExistsQ[Self],
If[
ClassAllowClobber[ObjectClass[Self]],
(* if clobbering is allowed for class of *previously-existing* instance, destroy existing instance *)
Destroy[Self],
(* else fail at creation *)
Message[Class::objdupl,Class,Name,ObjectClass[Self]];
OnCreationFailure[Class,Self][Args];
Return[$Failed]
]
];
(* define instance metadata *)
$ObjectClass[Self]=Class;
$ObjectInstanceIdentifier[Self]=Unique[$ObjectInstanceContext<>"Instance$"];
$ObjectReference[$ObjectInstanceIdentifier[Self]]=Self;
(* do constructor body *)
(* evaluate body *)
Aborted=False;
CheckAbort[
Result=Constructor[Class,Self][Args],
Aborted=True
];
(* check for creation failure due to no constructor match *)
If[
MatchQ[Result,Constructor[_,_][___]],
NameArgumentString=Switch[
AlmostName,
None,"",
_,StringJoin["\[LeftDoubleBracket]",ToString[AlmostName],"\[RightDoubleBracket]"]
];
Message[Class::objsyntax,Class,NameArgumentString,ListToString[{Args}]];
ClearObjectData[Class,Self];
OnCreationFailure[Class,Self][];
Return[$Failed]
];
(* check for creation failure due to abort in constructor *)
If[
Aborted,
ClearObjectData[Class,Self];
Abort[];
Return[$Aborted]
];
(* register object *)
$ObjectRegistry=Union[$ObjectRegistry,{Self}];
(* return object *)
Self
];
(*Instance deletion*)
(*For use both in cleanup for failed construction and in normal destruction*)
ClearObjectData[Class_Symbol,Self:Object[n_]]:=
Module[
{},
(* clear member data *)
Clear[Evaluate[$ObjectInstanceIdentifier[Self]]];
(* clear metadata *)
$ObjectReference[$ObjectInstanceIdentifier[Self]]=.;
$ObjectInstanceIdentifier[Self]=.;
$ObjectClass[Self]=.;
];
(*Destructor wrapper function*)
(*General::objdestroy="Attempting to destroy object `1` when this object does not exist.";*)
Destroy[Self:Object[A_]]:=
Module[
{Class},
(* check that object exists in order to be destroyed *)
If[
!MathObjectExistsQ[Self],
(*Message[General::objdestroy,Self];*)
Return[]
];
(* identify class *)
Class=ObjectClass[Self];
(* do destructor body *)
(* Note: If no explicit Destructor is defined, this is simply a no-op. *)
Destructor[Class,Self][];
(* delete all object member data and metadata *)
ClearObjectData[Class,Self];
(* deregister object *)
$ObjectRegistry=Complement[$ObjectRegistry,{Self}];
(* return Null *)
Null
];
(*General method access syntax*)
Object/:HoldPattern[(Self:Object[A_])@((Method_Symbol)[Args___])]:=
MethodWrapper[Self,Method,Args];
(*General method access wrapper*)
Object::objaccess="Cannot complete method call `2`@`3`[`4`] since object does not exist.";
General::objmethod="Cannot complete method call `2`@`3`[`4`] since no method named `3` is defined for class `1`.";
General::objmethodsyntax="Cannot complete method call `2`@`3`[`4`] since given arguments do not match any of the definitions for method `3`.";
MethodWrapper[Self:Object[A_],Method_Symbol,Args___]:=
Module[
{Class,Result,Msg},
(* validate object *)
If[
!MathObjectExistsQ[Self],
Message[Object::objaccess,None,Self,Method,ListToString[{Args}]];
Return[$Failed]
];
Class=ObjectClass[Self];
(* validate method name *)
If[
!MemberQ[ClassMethods[Class],Method],
With[{ClassSymbol=Class},
Message[ClassSymbol::objmethod,Class,Self,Method,ListToString[{Args}]]
]; (* Note: If use Class::objmember directly, message name fails to resolve properly. *)
Return[$Failed]
];
(* invoke method *)
Result=Method[Class,Self][Args];
(* DEBUG: Print[{Method,Context[Method],Class,Context[Class]}];Print[Result]; *)
(* verify method call was matched and evaluated *)
If[
MatchQ[Result,Method[_,_][___]],
With[{ClassSymbol=Class},
Message[ClassSymbol::objmethodsyntax,Class,Self,Method,ListToString[{Args}]]
];
Return[$Failed]
];
(* return result *)
Result
];
(*Object operators*)
(*Memberwise assignment*)
SetObjectData::ancestry="Source object `1` is not of the same class as `2` or of a descendent class thereof.";
SetObjectData[o2_Object,o1_Object]:=
Module[
{},
(* check ancestry of source object *)
If[
!MatchQ[o1,ObjectPattern[ObjectClass[o2]]],
Message[SetObjectData::ancestry,o1,o2];
Return[]
];
(* do copy *)
Do[
With[
{
SetMethod=ToExpression[$ObjectMethodContext<>"Set"<>s],
GetMethod=ToExpression[$ObjectMethodContext<>"Get"<>s]
},
o2@SetMethod[o1@GetMethod[]]
],
{s,ClassDataMemberNames[ObjectClass[o2]]}
];
];
(*Object metadata functions*)
(*Existence function*)
MathObjectExistsQ[Self:Object[A_]]:=(Head[$ObjectClass[Self]]=!=$ObjectClass);
(*Object name extraction*)
ObjectName[Self:Object[A_]]:=A;
(*Object type retrieval function*)
ObjectClass::noclass="Attempting to determine class of object `1` when this object does not exist.";
ObjectClass[Self_Object]:=
Module[
{},
(* check that object created *)
If[
!MathObjectExistsQ[Self],
Message[ObjectClass::noclass,Self];
Return[]
];
(* retrieve class *)
$ObjectClass[Self]
];
(*Object data dump function*)
ShowObject[Self_Object]:=
Module[
{},
Print["Object name: ",ObjectName[Self]];
If[
!MathObjectExistsQ[Self],
Print["Object not defined."];
Return[]
];
Print[" ","Instance identifier: ",$ObjectInstanceIdentifier[Self]];
Print[" ","Class: ",ObjectClass[Self]];
(*Definition[Evaluate[$ObjectInstanceIdentifier[Self]]]*)
Print[" ",InputForm[Replace[
DownValues[Evaluate[$ObjectInstanceIdentifier[Self]]],
{x_:>(x[[1,1,1]]->x[[2]])},
{1}
]]]
];
(*Class ancestry*)
ClassAncestry::noclass="Ancestry requested for undefined class `1`.";
ClassAncestry[Class_Symbol]/;MatchQ[ClassParent[Class],None]:={Class};
ClassAncestry[Class_Symbol]/;MatchQ[ClassParent[Class],Except[None,_Symbol]]:=Append[ClassAncestry[ClassParent[Class]],Class];
ClassAncestry[Class_Symbol]/;MatchQ[ClassParent[Class],Except[_Symbol]]:=(Message[ClassAncestry::noclass,Class];{});
(*Note: Short-circuit && prevents attempt to retrieve ancestry of a symbol which does not represent a defined class name.*)
ClassPattern[Class_Symbol]:=(_Symbol)?(MatchQ[ClassParent[#],_Symbol]&&MemberQ[ClassAncestry[#],Class]&);
(*Object and object name matching patterns*)
ObjectPattern[Class_Symbol]:=(_Object)?(MathObjectExistsQ[#]&&MemberQ[ClassAncestry[ObjectClass[#]],Class]&);
ObjectNamePattern[Class_Symbol]:=_?(MathObjectExistsQ[Object[#]]&&MemberQ[ClassAncestry[ObjectClass[Object[#]]],Class]&);
(*Note: An ostensible alternate pattern would use a named expression (s_Object) combined with Condition. In this case, HoldPattern on RHS needed, or else the else conditios bleed over to the assignment, and any reference to ObjectPattern[a] remains unevaluated. However, even so, this pattern is not suitable for use in argument lists (or Repeated lists and sequences) involving more than one appearance of the pattern, since the use of the same name s in both appearances means that the pattern will match only if all the objects are the *same* instance.*)
(* ::Program::Initialization:: *)
(*ObjectPattern[Class_Symbol] :=*)
(* HoldPattern[*)
(* ((s_Object) /; MathObjectExistsQ[s]) /; MemberQ[ClassAncestry[ObjectClass[s]], Class]*)
(* ];*)
(*ObjectNamePattern[Class_Symbol]:=*)
(* HoldPattern[*)
(*((n_)/;MathObjectExistsQ[Object[n]])/;MemberQ[ClassAncestry[ObjectClass[Object[n]]],Class]*)
(*];*)
(*Scoping*)
(*Scoping of object duration*)
(*Any objects created within ScopeObjects will be destroyed upon exiting ScopeObjects. *)
SetAttributes[ScopeObjects,HoldAll];
ScopeObjects::numargs="ScopeObjects must be called with exactly one argument.";
ScopeObjects[_,__]:=Message[ScopeObjects::numargs];
(*
ScopeObjects[Body_]:=Module[
{
$ObjectRegistry0,Self,
EvaluatedBody,Aborted
},
AbortProtect[
(* record prior object registry *)
$ObjectRegistry0=$ObjectRegistry;
(* evaluate body *)
Aborted=False;
CheckAbort[
EvaluatedBody=Body,
Aborted=True
];
(* destroy any new objects which still exist *)
(* DEBUG: Print["ScopeObject cleanup: ",$ObjectRegistry0,$ObjectRegistry,Complement[$ObjectRegistry,$ObjectRegistry0]];*)
Do[
Destroy[Self],
{Self,Complement[$ObjectRegistry,$ObjectRegistry0]}
];
];
(* return value *)
(* passes through abort, and also explicitly returns $Aborted in case Abort[] is suppressed *)
If[Aborted,Abort[];$Aborted,EvaluatedBody]
];
*)
ScopeObjects[Body_]:=
Module[
{
$ObjectRegistry0,Self,
EvaluatedBody,Aborted
},
Internal`WithLocalSettings[
(* initialization code*)
(* record prior object registry *)
$ObjectRegistry0=$ObjectRegistry,
(* body code*)
Body,
(* cleanup code *)
(* destroy any new objects which still exist *)
(* DEBUG: Print["ScopeObject cleanup: ",$ObjectRegistry0,$ObjectRegistry,Complement[$ObjectRegistry,$ObjectRegistry0]];*)
Do[
Destroy[Self],
{Self,Complement[$ObjectRegistry,$ObjectRegistry0]}
];
]
];
(*Clearing*)
ClearObjects[]:=
Module[
{},
Clear[$ObjectClass];
Clear[$ObjectInstanceIdentifier];
Clear[$ObjectReference];
$ObjectRegistry={};
Quiet[
Remove["MathObject`InstanceData`*"],
{Remove::rmnsm}
]
];
(*End package*)
(*Exit private context*)
End[];
(*Exit package context*)
Protect[Evaluate[$Context<>"*"]];
Unprotect[Evaluate[$Context<>"$*"]];
EndPackage[];