Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just to further Randall's post, it is possible, but the reason it goes against the static paradigm is that it's beyond "dynamic dispatch". Dynamic dispatch happily lets you dispatch to a function that is dynamically bound to a known static piece of code. i.e. the compiler sets up the dispatch that is deterministically executed at runtime, from its perspective.</p> <p>What the <code>method_missing</code> call does, is essentially make a "catch all" where you decide what to do based on the method name using a switch statement, or something equivalent (which I'm sure you know). Thus, the compiler has no idea what's going to happen here. Let's say the compiler did something like:</p> <pre><code>if (function is known at compile time) { provide static call or dynamic call to "some" derivation } else { bind the function call to obj.method_missing(...) and pass in the "details" } </code></pre> <p>Then you have to provide <code>method_missing</code> like this:</p> <pre><code>def method_missing(intendedFunctionName, arguments) { if (intendedFunctionName is "X") { X may not need arguments, so just do something } else if (intendedFunctionName is "Y") { Y expects 5 arguments of varying types Throw exception if there isn't the right number or types } ... etc ... } </code></pre> <p>Asking the compiler to send you "arbitrary" (i.e. not known at compile time) arguments of arbitrary types, with an <code>intendedFunctionName</code> that you may not be accounting for... well, it's not very safe, and Scala is intended to be a statically safe language.</p> <p>Yes, it's doable but not in the spirit of a static language. If you really want that type of flexibility, polyglot programming is probably your friend.</p> <p>Note: Objective-C is not strictly statically typed. There is a runtime engine on which the code executes and the dynamic typing system does not allow code to be stripped or inlined like C/C++.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload