Can you define methods to call during runtime of a module? #159
-
Describe your question in detail.Asked by
What error, if any, are you getting?No response What have you tried or looked at? Or how can we reproduce the error?Code given. Which operating system are you using?N/A Which SDK or tool are you using? (if any)N/A Describe your environment or tooling in detailNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, this is not possible. Aptos Move uses static dispatch, as of April 23rd, 2024. You'll receive errors from the Aptos CLI when attempting to compile the code, like:
Notice that the error originated from Static vs Dynamic DispatchStatic dispatch determines which operations, or logic implementations, to perform during the compilation step. Applied to your exampleThe values of
To support your given concept, the dispatch steps would need to be performed during run time, when the values of the above variables are available. You might ask, "How do DEXs/{other tech} work, then?"While Aptos Move doesn't have the ability to determine the implementation of a function during runtime, it doesn't mean that we can't pass dynamic data. For example, type arguments are commonly used to describe the type of the Coins being swapped on DEXs. This is valid since the function implementation isn't changing between different types, but rather the instance of the pre-defined type. |
Beta Was this translation helpful? Give feedback.
No, this is not possible. Aptos Move uses static dispatch, as of April 23rd, 2024.
You'll receive errors from the Aptos CLI when attempting to compile the code, like: