JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

compile

core-api


    cfunction
    src/core/compile.c on line 1308, column 1

    (compile ast &opt env source lints)

    Compiles an abstract syntax tree `ast` into a function. Returns a 
    new function and does not modify `ast`. If compilation fails, 
    returns an error struct with keys `:line`, `:column`, and `:error`. 
    If a table `env` is given, specifies the environment of the fiber 
    used during compilation. Optional argument `source` is a string or 
    keyword that is a source path for better errors. If a `lints` array 
    is given, linting messages will be appended to the array. Each 
    message will be a tuple of the form `[level line col message]`.


2 examplesSign in to add an example
Loading...
(def ast '(print novar))
(def es (compile ast))
# => @{:column 11 :line 12 :error "unknown symbol novar"} returns struct with error on invalid ast
pepePlayground
(def cc (compile '(print "Janet"))) # => <function _thunk> on success returns function
(cc) # => prints Janet
pepePlayground