NFun 1.1.0

dotnet add package NFun --version 1.1.0
                    
NuGet\Install-Package NFun -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NFun" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NFun" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="NFun" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NFun --version 1.1.0
                    
#r "nuget: NFun, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NFun@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NFun&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=NFun&version=1.1.0
                    
Install as a Cake Tool

NFun — Expression Evaluator for .NET

Embeddable expression language with rich type system, absolute type inference, and LINQ-like collections.

PM> Install-Package NFun

Quick Start

// Simple evaluation
double d = Funny.Calc<double>("2 * 10 + 1"); // 21
bool b = Funny.Calc<bool>("false and (2 > 1)"); // false

// With input model
string alias = Funny.Calc<User, string>(
    "if(age < 18) name else 'Mr. {name}'", user);

// Multiple inputs and outputs
var person = new Person(birthYear: 2000);
Funny.CalcContext(@"
    age = 2022 - birthYear
    cars = [
        { name = 'lada',   cost = 1200, power = 102 },
        { name = 'camaro', cost = 5000, power = 275 }
    ]", person);

// Low-level API
var runtime = Funny.Hardcore.Build("y = 2x + 1");
runtime["x"].Value = 42;
runtime.Run();
var result = runtime["y"].Value; // 85

Key Features

Operators & Arithmetic

y1 = 2*(x//2 + 1) / (x % 3 - 1)**0.5 + 3x   # arithmetic, implicit multiplication
y2 = (x | y & 0xF0FF << 2) ^ 0x1234            # bitwise
y3 = x and false or not (y > 0)                  # logical

If-expressions

y = if(age > 18)
        if(weight > 100) 'heavy'
        if(weight > 50)  'normal'
        else 'light'
    if(age > 16) 'teen'
    else 'child'

Collections & Higher-Order Functions

out = [1,2,3,4,5]
    .filter(rule it > 2)
    .map(rule it * 10)
    .reverse()                  # [50, 40, 30]

Structs & Named Types

type point = {x: int, y: int}
p: point = {x = 3, y = 4}
dist = (p.x**2 + p.y**2)**0.5

Optional Types & Type Narrowing

user:{name: text, age: int}? = none
greeting = if(user == none) 'Guest'
           if(user.age > 18) 'Hello, {user.name}'
           else 'Hi, {user.name}'

Strict Type System with Full Inference

y = 2x                              # x and y inferred as Int32
z:int = y * x                       # explicit annotation
m:real[] = [1,2,3].map(rule it/2)   # [0.5, 1.0, 1.5]

Dialect Customization

var runtime = Funny.Hardcore
    .WithDialect(
        integerPreferredType: IntegerPreferredType.I64,
        integerOverflow: IntegerOverflow.Unchecked,
        optionalTypesSupport: OptionalTypesSupport.Enabled,
        namedTypesSupport: NamedTypesSupport.Enabled)
    .Build("y = 2x + 1");

Documentation

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

v1.1.0: Optional types (T?, none, ??, ?., ?[, !), named types, type narrowing, row polymorphism, format specifiers, try-catch, char literals, 150+ new built-in tests.