Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

What's This Called?

Name: Anonymous 2011-04-01 2:00

Hey, /porg/, pretty much every language has a way to do this, but I'm not sure what it's called... 

Suppose I write some useful algorithm, like a sort.  And, I'd like to package up that code and make it available for other programs to use.  But I can't just make it a "simple" function call, because I need the caller to supply a little bit of the code -- for example, he might need to provide the comparison function for the elements being sorted.  You could consider the comparison function as just another argument to the function, but it's more than that.  It's a sort of two-way exchange, where I write some of the code and the caller writes some of the code, and the two transfer execution back and forth between each other.

A lot of languages use callbacks or "anonymous" functions for this sort of thing.  What are mechanisms that other languages provide?  Are there any significant advantages?

Name: Anonymous 2011-04-01 2:06

my non existent language uses Forces of Inline for such callback so its AST is actually inlined in sort

pros
fast. no time wasted on call/push/pop/ret

cons
bloated and non-existent

Name: Anonymous 2011-04-01 2:18

Name: Anonymous 2011-04-01 3:02

>>2
>cons
my other car is a python

Name: Anonymous 2011-04-01 3:08

It's called a Visitor Pattern.

Name: Anonymous 2011-04-01 7:29

>>4
My other cat is a python.

Name: Anonymous 2011-04-01 7:42

>>6
My python is meta-circular. It ate itself.

Name: Anonymous 2011-04-01 7:42

>>7
..And Guido was his name. RIP.

Don't change these.
Name: Email:
Entire Thread Thread List