Skip to content
Prev 180932 / 398506 Next

Functions returning functions

Paulo Grahl wrote:
consider this example:

    foo = function(a, b)
       function(c)
          if (c) a else b

    x = 1
    y = 2
    bar = foo(x, y)

    bar(TRUE)
    # 1
    x = 0
    bar(TRUE)
    # 1, not 0

    y = 0
    bar(FALSE)
    # 0, not 2

vQ