<div dir="ltr">Sorry the example I was looking at when I mentioned that was not really a function reference but it gets the same result. It does so by using ChucK class functionality that in other languages is called polymorphism. It is described in ChucK language documentation.<div>

<br></div><div><a href="http://chuck.cs.princeton.edu/doc/language">http://chuck.cs.princeton.edu/doc/language</a><div><br></div><div>See the example class Xfunc in the inheritence section. What is done is to create a base class with a standard class function (in the example called doSomething().) For each different version of function that is needed a new class is created which inherits the base class and overrides doSomething() with the new code. The "calling  function" is then declared with a base class object as an argument. You can pass it any object that inherits the base class (in this case Xfunc.) When it calls the doSomething() method it invokes the overridden version from the derived class. <br>

</div><div><div><div><br></div></div></div></div><div>The example doesn't create a function to do this but it shows an example of common code calling different functions from different classes. It does this by creating an array containing objects from different classes and then calling the different versions in a loop using the array. Clearly the common code in the loop could have been a function.</div>

<div><br></div><div>I'm away from my ChucK machine at the moment but if anyone is interested I could try to create a simple example which does the inner work (calling a passed in function) in a function. As usual the documentation is vague but I believe the function version of the example would look something like:</div>

<div><br></div><div>fun int callFunc(Xfunc @ in, int a, int b) </div><div>{</div><div>   return in.doSomething(a,b);</div><div>}</div><div><br></div>// loop over the Xfunc<br>for( 0 => int i; i < operators.cap(); i++ )<br>

{<br>    // doSomething, potentially different for each Xfunc<br>    <<< callerFunc(operators[i], 4, 5 ) >>>;<br>}<div><br><div>-steve</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Fri, Dec 27, 2013 at 7:03 PM, Dealga McArdle <span dir="ltr"><<a href="mailto:tetha.z@gmail.com" target="_blank">tetha.z@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">re: </span><span style="font-size:12.727272033691406px;font-family:arial,sans-serif;font-weight:bold;white-space:nowrap">Steve Morris</span></div>



<div><span style="font-size:12.727272033691406px;font-family:arial,sans-serif;font-weight:bold;white-space:nowrap"><br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<span style="font-size:12.727272033691406px;font-family:arial,sans-serif">3) You can pass a reference to a function as an argument to another function.</span></blockquote></div><div><font face="arial, sans-serif"><br></font></div>



<div><font face="arial, sans-serif">how? :) I haven't found how to do that anywhere.<br></font><div class="gmail_extra"><br></div></div></div>
<br>_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br></blockquote></div><br></div>