A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-April/052840.html below:

[Python-Dev] anonymous blocks

[Python-Dev] anonymous blocksGreg Ewing greg.ewing at canterbury.ac.nz
Fri Apr 22 08:19:45 CEST 2005
Ka-Ping Yee wrote:

> Can you explain what you meant by currying here?  I know what
> the word "curry" means, but i am having a hard time seeing how
> it applies to your example.

It's currying in the sense that instead of one function
which takes all the args at once, you have a function
that takes some of them (all except the thunk) and
returns another one that takes the rest (the thunk).

>  Could you make up an example that uses more arguments?

   def with_file(filename, mode):
     def func(block):
       f = open(filename, mode)
       try:
         block(f)
       finally:
         f.close()
     return func

Usage example:

   with_file("foo.txt", "w") as f:
     f.write("My hovercraft is full of parrots.")

Does that help?

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4