Skip to content
Li, Xizhi edited this page Dec 28, 2016 · 11 revisions

Meta Programming in NPL

Meta programming allows you to extend NPL syntax using the NPL language itself. For example, following code are valid in NPL.

local a=1;
loop(){  please execute the code 10 times with i
    echo(a+i)
    async(){
        echo("This is from worker thread");
    }
}

Here loop, async are extended NPL syntax defined elsewhere.

The concept is first developed by LISP programming language in 1960s. However, despite the power of LISP, its syntax is hard to read for most programmers nowadays. NPL introduces a similar concept called Function-Expression, which can be mixed very well with the original NPL syntax.

The syntax of NPL's Function-Expression is name(input, ...){ ... }

Files with *.npl extension support Function-Expression syntax by default. For example

NPL.load("(gl)script/tests/helloworld.npl")
NPL.loadstring("-- source code here", "filename_here")

Function-Expression User Guide

TODO for popeye:

def expression

Examples

TODO for popeye:

For more examples, please see our test here

Clone this wiki locally