On 5/9/08, Max Cantor <maxcantor / gmail.com> wrote:
> On Fri, May 9, 2008 at 1:29 PM, Avdi Grimm <avdi / avdi.org> wrote:
> > On Fri, May 9, 2008 at 1:13 PM, Max Cantor <maxcantor / gmail.com> wrote:
> >>  For example: No matter which
> >> way you slice it, "arr.each { |item| item.foo }" and its underlying
> >> implementation is unique to Ruby
> >
> > It is?
>
> Is there another language out there that lets you pass a "literal"
> block of code as a virtual argument so the called method can push
> arguments into the code block specified by | |s?
>
well except for the ||, what about c?  Assuming an 'Object' struct has
been defined:

Object set[N];
/*<fill set>*/
int idSort(void* l, void* r) {      /* Here's my literal block of code */
  return ((Object*)l)->id - ((Object*)r)->id;
}
qsort(set, N, sizeof(Object), &idSort);    /* Which I pass as argument */
                        /* so the called method can push items into it */

What's unique to Ruby (at least in your example) is not that I *can*
do it, just that I can do it in roughly a quarter of the equivalent c
code:
set = []
#fill set
set.sort_by{|o|o.id}


-Adam