~chaffra/fiat/main

« back to all changes in this revision

Viewing changes to FIAT/curry.py

  • Committer: kirby
  • Date: 2005-05-31 15:03:57 UTC
  • Revision ID: devnull@localhost-20050531150357-n7ka5987yo6ylpaz
[project @ 2005-05-31 15:03:57 by kirby]
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2005 by The University of Chicago
 
2
# Distributed under the LGPL license
 
3
# This work is partially supported by the US Department of Energy
 
4
# under award number DE-FG02-04ER25650
 
5
 
 
6
# Curries a function
 
7
# Given f( x1 , x2 , x3 ), for example,
 
8
# g = curry( f , a , b ) is a function of one argument, x3,
 
9
# so that g( c ) has the same value as f( a , b , c )
 
10
# This class is useful in bypassing the scoping bugs for higher
 
11
# order functions in Python
 
12
class curry:
 
13
    def __init__( self , f , *first_args ):
 
14
        self.f = f
 
15
        self.first_args = first_args[:]    # copy
 
16
    def __call__( self , *xs ):
 
17
        return self.f( *(self.first_args + xs) )
 
18