Skip to main content

Command Palette

Search for a command to run...

Currying and Partial Application with BrightScript

Updated
1 min read

BrightScript by definition is not a Functional Programming Language but it does offer a few features which encourage FP-style programming.

Here is an example for Currying with BrightScript, using Eval() which makes it impossible.

' Run this sample code from the BrightSign shell
' BrightSign> script roReadFile.brs

sub main()

' Curried adder()
' The adder() function takes an a and returns a function that takes b

    adder = function ( a )
        eval( "fnRet = function ( b ) : return b + " + a.toStr() + " : end function" )
        return fnRet 
    end function

' Example: Create an increment() function
' Returns incremented integer

    increment = adder(1)

    print "Increment 11 = "; increment(11)

    print "Adding 1 + 9 = "; adder(1)(9)

    print "or"

    add1 = adder(1)

    print "add1(9) = "; add1(9)


end sub

More Functional Programming examples with BrightScript can be found in our FP repo.