Public API
Evaluation Functions
NickelEval.nickel_eval Function
nickel_eval(code::String) -> AnyEvaluate Nickel code and return a Julia value.
Returns native Julia types: Int64, Float64, Bool, String, nothing, Vector{Any}, Dict{String,Any}, or NickelEnum.
Examples
julia> nickel_eval("1 + 2")
3
julia> nickel_eval("{ a = 1, b = 2 }")
Dict{String, Any}("a" => 1, "b" => 2)
julia> nickel_eval("let x = 5 in x * 2")
10nickel_eval(code::String, ::Type{T}) -> TEvaluate Nickel code and convert to type T. Supports Dict, Vector, and NamedTuple conversions.
Examples
julia> nickel_eval("42", Int)
42
julia> nickel_eval("{ a = 1, b = 2 }", Dict{String, Int})
Dict{String, Int64}("a" => 1, "b" => 2)
julia> nickel_eval("[1, 2, 3]", Vector{Int})
[1, 2, 3]
julia> nickel_eval("{ x = 1.5, y = 2.5 }", @NamedTuple{x::Float64, y::Float64})
(x = 1.5, y = 2.5)NickelEval.nickel_eval_file Function
nickel_eval_file(path::String) -> AnyEvaluate a Nickel file. Supports import statements resolved relative to the file's directory.
Returns native Julia types: Int64, Float64, Bool, String, nothing, Vector{Any}, Dict{String,Any}, or NickelEnum.
Examples
julia> nickel_eval_file("config.ncl")
Dict{String, Any}("host" => "localhost", "port" => 8080)Export Functions
NickelEval.nickel_to_json Function
nickel_to_json(code::String) -> StringEvaluate Nickel code and export to a JSON string.
Examples
julia> nickel_to_json("{ a = 1, b = "hello" }")
"{\"a\": 1,\"b\": \"hello\"}"NickelEval.nickel_to_toml Function
nickel_to_toml(code::String) -> StringEvaluate Nickel code and export to a TOML string.
Examples
julia> nickel_to_toml("{ a = 1 }")
"a = 1\n"NickelEval.nickel_to_yaml Function
nickel_to_yaml(code::String) -> StringEvaluate Nickel code and export to a YAML string.
Examples
julia> nickel_to_yaml("{ a = 1 }")
"a: 1\n"FFI Functions
NickelEval.check_ffi_available Function
check_ffi_available() -> BoolCheck if the Nickel C API library is available.
sourceNickelEval.build_ffi Function
build_ffi()Build the Nickel C API library from source. Requires Rust (cargo). Restarts the FFI after building so you don't need to restart Julia.
sourceString Macro
NickelEval.@ncl_str Macro
@ncl_str -> AnyString macro for inline Nickel evaluation.
Examples
julia> ncl"1 + 1"
2
julia> ncl"{ x = 10 }"["x"]
10Lazy Evaluation
NickelEval.nickel_open Function
nickel_open(f, code::String)
nickel_open(code::String) -> NickelValueEvaluate Nickel code shallowly and return a lazy NickelValue. Sub-expressions are evaluated on demand when accessed via .field or ["field"].
Do-block (preferred)
nickel_open("{ x = 1, y = 2 }") do cfg
cfg.x # => 1 (only evaluates x)
endManual
cfg = nickel_open("{ x = 1, y = 2 }")
cfg.x # => 1
close(cfg)NickelEval.NickelValue Type
NickelValueA lazy reference to a Nickel expression. Accessing fields (.field or ["field"]) evaluates only the requested sub-expression. Use collect to materialize the full subtree into plain Julia types.
Examples
nickel_open("{ x = 1, y = { z = 2 } }") do cfg
cfg.x # => 1
cfg.y.z # => 2
collect(cfg) # => Dict("x" => 1, "y" => Dict("z" => 2))
endNickelEval.NickelSession Type
NickelSessionOwns a Nickel evaluation context for lazy (shallow) evaluation. Tracks all allocated expressions and frees them on close.
Not thread-safe. All access must occur on a single thread.
sourceNickelEval.nickel_kind Function
nickel_kind(v::NickelValue) -> SymbolReturn the kind of a lazy Nickel value without evaluating its children.
Returns one of: :record, :array, :number, :string, :bool, :null, :enum.
Types
NickelEval.NickelEnum Type
NickelEnumRepresents a Nickel enum value.
Fields
tag::Symbol: The enum variant namearg::Any: The argument (nothing for simple enums)
Examples
result = nickel_eval("let x = 'Some 42 in x")
result.tag # => :Some
result.arg # => 42
result == :Some # => true
result = nickel_eval("let x = 'None in x")
result.tag # => :None
result.arg # => nothingNickelEval.NickelError Type
NickelError <: ExceptionException thrown when Nickel evaluation fails.
Fields
message::String: The error message from Nickel
Examples
try
nickel_eval("{ x = }") # syntax error
catch e
if e isa NickelError
println("Nickel error: ", e.message)
end
end