Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is an exceedingly nice method for performing recursion in language constructs that don't explicitly support recursion called a <em>fixed point combinator</em>. The most well known is the <a href="http://en.wikipedia.org/wiki/Fixed_point_combinator" rel="nofollow noreferrer">Y-Combinator</a>.</p> <p><a href="http://www.cs.cityu.edu.hk/~hwchun/31337/blog/2005/09/y-combinator-in-javascript.php" rel="nofollow noreferrer">Here is the Y combinator for a function of one parameter in Javascript</a>:</p> <pre><code>function Y(le, a) { return function (f) { return f(f); }(function (f) { return le(function (x) { return f(f)(x); }, a); }); } </code></pre> <p>This looks a little scary but you only have to write that once. Using it is actually pretty simple. Basically, you take your original lambda of one parameter, and you turn it into a new function of two parameters - the first parameter is now the actual lambda expression that you can do the recursive call on, the second parameter is the original first parameter (<code>point</code>) that you want to use.</p> <p>This is how you might use it in your example. Note that I am using <code>mapstrings</code> as a list of strings to look up and the pop function would destructively remove an element from the head.</p> <pre><code>geocoder.getLatLng(pop(mapstrings), Y( function(getLatLongCallback, point) { if (!point) { if (length(mapstrings) &gt; 0) geocoder.getLatLng(pop(mapstrings), getLatLongCallback); return; } map.setCenter(point, 13); map.setZoom(7); map.addOverlay(new GMarker(point)); }); </code></pre>
 

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