Well, another try Re: while c = f.read(1)

Paul Rubin http
Sun Aug 21 04:53:38 CEST 2005

James Sungjin Kim <kimsj at mobile.snu.ac.kr> writes:
> Now I realized that Command 'lambda' is a similar to Command 'inline'
> in C++. In addition, Command 'iter' is something new but not much new
> to c engineers, since it is related to 'for loops', e.g.,

Actually not related at all.  Nothing like lambda or iter exist in
C++.  They are a bit complicated to explain to newbies (unless you've
programmed in Lisp or in functional-programming languages), thus the
suggestion of looking in the docs.  That's also the reason that
suggesting using lambda and iter that way was considered a bad answer
to "how do you write something like 'while c = f.read(1)'". 

Anyway, quick explanation of lambda: it's a way of creating functions
without having to give then names.  Example:

  lambda x: x*x 

is a function that computes the square of x.  So you could say

   n = (lambda x: x*x)(3)

which sets n = 9.

There is a faction on clpy which says lambda is bad and all functions
should have their own names.  Others say they're useful for things
like callbacks, and requiring all functions to be named makes no more
sense than requiring all intermediate results in infix expressions to
be named.

You unfortunately happened to trip into a slightly contentious topic
on clpy and got flamed a bit as a result.

I won't explain iter here, since it's more complex than lambda.

More information about the Python-list mailing list