Re: "Real" Differences Between Python & Ruby
by Adam Shelly other posts by this author
May 9 2008 12:39PM messages near this date
Re: "Real" Differences Between Python & Ruby
|
Re: "Real" Differences Between Python & Ruby
On 5/9/08, Max Cantor <maxcantor@[...].com> wrote:
> On Fri, May 9, 2008 at 1:29 PM, Avdi Grimm <avdi@[...].org> wrote:
> > On Fri, May 9, 2008 at 1:13 PM, Max Cantor <maxcantor@[...].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
Thread:
Max Cantor
Avdi Grimm
Globalrev
Marc Heiler
Max Cantor
Michael T. Richter
M. Edward Borasky
Michael T. Richter
M. Edward Borasky
Eleanor McHugh
Michael T. Richter
Steven Parkes
Avdi Grimm
Max Cantor
Adam Shelly
Robert Dober
David A. Black
Robert Dober
Phillip Gawlowski
Martin DeMello
|