Re: functions which take functions

2012-04-13 Thread Antti "Andy" Ylikoski
12.4.2012 18:48, Kiuhnm kirjoitti: On 4/11/2012 16:01, Antti J Ylikoski wrote: On 9.4.2012 21:57, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Thank you. Kiuhnm A f

Re: functions which take functions

2012-04-12 Thread Kiuhnm
On 4/12/2012 19:29, Jan Kuiken wrote: On 4/9/12 20:57 , Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? I don't use it daily but the first argument of list.sort, i.e. t

Re: functions which take functions

2012-04-12 Thread Jan Kuiken
On 4/9/12 20:57 , Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? I don't use it daily but the first argument of list.sort, i.e. the compare function springs to mind. J

Re: functions which take functions

2012-04-12 Thread Kiuhnm
On 4/12/2012 8:07, Tim Roberts wrote: Kiuhnm wrote: That won't do. A good example is when you pass a function to re.sub, for instance. This is an odd request. All shall be revealed :) I often pass functions to functions in order to simulate a C switch statement, such as in a language tr

Re: functions which take functions

2012-04-12 Thread Kiuhnm
On 4/11/2012 16:01, Antti J Ylikoski wrote: On 9.4.2012 21:57, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Thank you. Kiuhnm A function to numerically integrate ano

Re: functions which take functions

2012-04-11 Thread Tim Roberts
Kiuhnm wrote: > >That won't do. A good example is when you pass a function to re.sub, for >instance. This is an odd request. I often pass functions to functions in order to simulate a C switch statement, such as in a language translator: commands = { 'add': doAdd, 'subtract' : doSubt

Re: functions which take functions

2012-04-11 Thread Tim Chase
On 04/10/12 08:36, Kiuhnm wrote: On 4/10/2012 14:29, Ulrich Eckhardt wrote: Am 09.04.2012 20:57, schrieb Kiuhnm: That won't do. A good example is when you pass a function to re.sub, for instance. If that's a good example, then why not use it? I've used it on multiple occasions to do lookups

Re: functions which take functions

2012-04-11 Thread Antti J Ylikoski
On 9.4.2012 21:57, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Thank you. Kiuhnm A function to numerically integrate another function comes as follows:

Re: functions which take functions

2012-04-11 Thread Dave Angel
On 04/11/2012 06:55 AM, Kiuhnm wrote: > On 4/10/2012 23:43, Eelco wrote: >> On Apr 10, 3:36 am, Kiuhnm wrote: >>> On 4/10/2012 14:29, Ulrich Eckhardt wrote: >>> Am 09.04.2012 20:57, schrieb Kiuhnm: > Do you have some real or realistic (but easy and self-contained) > examples when you

Re: functions which take functions

2012-04-11 Thread Kiuhnm
On 4/10/2012 23:43, Eelco wrote: On Apr 10, 3:36 am, Kiuhnm wrote: On 4/10/2012 14:29, Ulrich Eckhardt wrote: Am 09.04.2012 20:57, schrieb Kiuhnm: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to anot

Re: functions which take functions

2012-04-10 Thread Chris Angelico
On Tue, Apr 10, 2012 at 11:36 PM, Kiuhnm wrote: > On 4/10/2012 14:29, Ulrich Eckhardt wrote: >> >> Am 09.04.2012 20:57, schrieb Kiuhnm: >>> >>> Do you have some real or realistic (but easy and self-contained) >>> examples when you had to define a (multi-statement) function and pass it >>> to anoth

Re: functions which take functions

2012-04-10 Thread Eelco
On Apr 10, 3:36 am, Kiuhnm wrote: > On 4/10/2012 14:29, Ulrich Eckhardt wrote: > > > Am 09.04.2012 20:57, schrieb Kiuhnm: > >> Do you have some real or realistic (but easy and self-contained) > >> examples when you had to define a (multi-statement) function and pass it > >> to another function? >

Re: functions which take functions

2012-04-10 Thread Kiuhnm
On 4/10/2012 14:29, Ulrich Eckhardt wrote: Am 09.04.2012 20:57, schrieb Kiuhnm: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Take a look at decorators, they not only take non-trivi

Re: functions which take functions

2012-04-10 Thread Ulrich Eckhardt
Am 09.04.2012 20:57, schrieb Kiuhnm: > Do you have some real or realistic (but easy and self-contained) > examples when you had to define a (multi-statement) function and pass it > to another function? Take a look at decorators, they not only take non-trivial functions but also return them. That s

Re: functions which take functions

2012-04-09 Thread Emile van Sebille
On 4/9/2012 11:57 AM Kiuhnm said... Do you have some real or realistic ... yes (but easy and self-contained) aah, no. examples when you had to define a (multi-statement) function and pass it to another function? This weekend I added functionality to a subsystem that allows users to

Re: functions which take functions

2012-04-09 Thread Terry Reedy
On 4/9/2012 2:57 PM, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? This is so common in Python that it is hardly worth sneezing about. map(f, iterable) filter(f, itera