Code block literals

John Roth newsgroups at jhrothjr.com
Mon Oct 13 12:31:51 EDT 2003


"Sean Ross" <sross at connectmail.carleton.ca> wrote in message
news:lqzib.4539$cT6.106958 at news20.bellglobal.com...
> "John Roth" <newsgroups at jhrothjr.com> wrote in message
> news:vol02ieh5inade at news.supernews.com...
> >
>
>
> Anyway. I was thinking that the foobar example would look cleaner if the
> block did not have to be included directly as an argument to the function
> call, but could instead be associated with the function call, tacked onto
> the end, like so
>
>  foobar = map(list1, list2, list3) with x, y, z:
>         astatement
>         anotherstatement
>
> or maybe
>
>  foobar = map(list1, list2, list3) { (x, y, z):
>         astatement
>         anotherstatement
> }
>
> or, if we want to be explicit:
>
>  foobar = map(&thunk, list1, list2, list3) with x, y, z:
>         astatement
>         anotherstatement
>
> so that we know where the thunk is being fed to as an argument. But, this
> would probably limit the number of blocks you could pass to a function.

That's the basic problem with the Rubyesque syntaxes: it limits you to
one block per function, and it makes it an implicit parameter. I don't
know that that's bad per se - people who like Ruby don't seem to feel
it's a huge limitation. However, it simply doesn't slide into Python well.
That's why I used map() as my example: it's a function that almost has to
take another function to do anything useful, and that function is a specific
parameter.

John Roth

> Sean







More information about the Python-list mailing list