>From what I gather, procedure variables can indeed be referenced and passed around, etc.<br><br>However, procedures do not return anything, so it's hard to chain them. In functional languages, it's handy to do several nested map(map(map f ... calls.<br clear="all">
<div><br></div>Cheers,<div><br></div><div>Andrew Pennebaker</div><div><a href="http://www.yellosoft.us" target="_blank">www.yellosoft.us</a></div><br><div class="gmail_quote">On Wed, Oct 19, 2011 at 2:30 PM, Florian Klämpfl <span dir="ltr"><<a href="mailto:florian@freepascal.org">florian@freepascal.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Am 19.10.2011 20:23, schrieb Andrew Pennebaker:<br>
<div class="im">> Practical uses for referencable anonymous functions:<br>
<br>
</div>For such applications one uses procedure variables in pascal.<br>
<div class="im"><br>
><br>
> (map f collection)<br>
><br>
> This is the prototypical way to run a function over each element in a<br>
> collection, returning the results.<br>
><br>
> Example:<br>
><br>
> (map (lambda (x) (+ x 1)) '(1 2 3))<br>
><br>
> -> (2 3 4)<br>
><br>
> (sort compare collection)<br>
><br>
> When dealing with complex data types, the user may want to implement a<br>
> custom compare function.<br>
><br>
> (sort (lambda (x y) (- y:employee-id x:employeeid)) (list emp1 emp2 emp3))<br>
><br>
> -> (emp3 emp1 emp2)<br>
><br>
> (zip f collection1 collection2)<br>
><br>
> Similar to map, zip runs a 2-input function over the elements of the<br>
> collections, returning the results.<br>
><br>
> (zip (lamba (x y) (+ x y)) '(1 2 3) '(4 5 6))<br>
><br>
> -> (5 7 9)<br>
><br>
> At first glance, each of these examples may seem pointless. Can't we<br>
> implement the same behavior without referencing anonymous functions?<br>
> Yes, we can, but only for a specific function. If you want your database<br>
> library to allow users to customize sorting, you'll need referencable<br>
> anonymous functions.<br>
<br>
</div>I still don't see why this cannot be done by procedure variables: one<br>
can easily pass a procedure reference to a compare function to any sort<br>
library call. The example is far from explaining why it is needed to be<br>
able to return a reference to an anonymous method to the outside of the<br>
enclosing function.<br>
<div><div></div><div class="h5">_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br>