Skip to main content
2 of 2
added 176 characters in body
Jason B.
  • 72.3k
  • 3
  • 152
  • 317

The symbols getAge and getName aren't exported as package symbols so that is why the definitions don't fire. If you want to use the same syntax you are using then just change the lines

self@getName[] := name; self@getAge[] := age; 

with something like

self[sym_[] /; SymbolName[sym] === "getName"] := name; self[sym_[] /; SymbolName[sym] === "getAge"] := age; 

or, as suggested by Michael E2

self["getName"] := name; self["getAge"] := age; (* more methods here *) self[sym_Symbol[args___]] := self[SymbolName[sym], args]; 

and it will work. I think JLink does something similar but I haven't really verified that.

Personally I find method definitions like

self["getName"] := name; self["getAge"] := age; 

to be much more natural, but the language is versatile enough to support both methods.

Jason B.
  • 72.3k
  • 3
  • 152
  • 317