Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Here are interesting functions to use symbols like objects. (I originally posted these thoughts in What is in your Mathematica tool bag?What is in your Mathematica tool bag?).

You can access the list of keys (or properties) of a symbol using these functions based on what dreeves once submittedsubmitted (I was quite lucky to have found his post early in my Mathematica learning curve, because it allowed me to work on functions working with lots of different arguments, as you can pass the symbol containing the stored properties to a function and see which keys this symbol contains using Keys):

Properties are stored as DownValues and methods as delayed Upvalues (except for the [ ] redefinition also stored as DownValues) in the symbol created by Module that is returned. I found the syntax for function2 that is the usual OO-syntax for functions in Tree data structure in MathematicaTree data structure in Mathematica.

Here are interesting functions to use symbols like objects. (I originally posted these thoughts in What is in your Mathematica tool bag?).

You can access the list of keys (or properties) of a symbol using these functions based on what dreeves once submitted (I was quite lucky to have found his post early in my Mathematica learning curve, because it allowed me to work on functions working with lots of different arguments, as you can pass the symbol containing the stored properties to a function and see which keys this symbol contains using Keys):

Properties are stored as DownValues and methods as delayed Upvalues (except for the [ ] redefinition also stored as DownValues) in the symbol created by Module that is returned. I found the syntax for function2 that is the usual OO-syntax for functions in Tree data structure in Mathematica.

Here are interesting functions to use symbols like objects. (I originally posted these thoughts in What is in your Mathematica tool bag?).

You can access the list of keys (or properties) of a symbol using these functions based on what dreeves once submitted (I was quite lucky to have found his post early in my Mathematica learning curve, because it allowed me to work on functions working with lots of different arguments, as you can pass the symbol containing the stored properties to a function and see which keys this symbol contains using Keys):

Properties are stored as DownValues and methods as delayed Upvalues (except for the [ ] redefinition also stored as DownValues) in the symbol created by Module that is returned. I found the syntax for function2 that is the usual OO-syntax for functions in Tree data structure in Mathematica.

replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Interestingly some answers to this post How to Set parts of indexed lists?How to Set parts of indexed lists? deal with this issue in a O(1) way (compared to the O(n) complexity of ReplacePart where a new list is created to modify it afterwards).

If you wanted to DumpSave newObject you could know which aPrivate$xxx variable to also save by using the depends function of Leonid Shifrin described in the post Automatically generating a dependency graph of an arbitrary Mathematica function?Automatically generating a dependency graph of an arbitrary Mathematica function?.

You can automate ObjectSet by overloading Set in a dynamic environment for example. See this post for more details Alternative to overloading SetAlternative to overloading Set

Interestingly some answers to this post How to Set parts of indexed lists? deal with this issue in a O(1) way (compared to the O(n) complexity of ReplacePart where a new list is created to modify it afterwards).

If you wanted to DumpSave newObject you could know which aPrivate$xxx variable to also save by using the depends function of Leonid Shifrin described in the post Automatically generating a dependency graph of an arbitrary Mathematica function?.

You can automate ObjectSet by overloading Set in a dynamic environment for example. See this post for more details Alternative to overloading Set

Interestingly some answers to this post How to Set parts of indexed lists? deal with this issue in a O(1) way (compared to the O(n) complexity of ReplacePart where a new list is created to modify it afterwards).

If you wanted to DumpSave newObject you could know which aPrivate$xxx variable to also save by using the depends function of Leonid Shifrin described in the post Automatically generating a dependency graph of an arbitrary Mathematica function?.

You can automate ObjectSet by overloading Set in a dynamic environment for example. See this post for more details Alternative to overloading Set

added 209 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131

Edit: The ideas below have led to a package called MTools. Instructions on how to install and use it are here: MTools tutorial.

Edit: The ideas below have led to a package called MTools. Instructions on how to install and use it are here: MTools tutorial.

added 198 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 101 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
deleted 391 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
deleted 3 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 103 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 152 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 200 characters in body; deleted 1 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 227 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 807 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 279 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 3 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 230 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 12 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 65 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 113 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 188 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 10 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
deleted 1 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 7 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 161 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading
added 554 characters in body
Source Link
faysou
  • 11k
  • 3
  • 50
  • 131
Loading