EverSharp Documentation¶
Welcome to the official documentation for EverSharp, a dynamically-typed meta-programming language designed for business rules and calculations.
What is EverSharp?¶
EverSharp is a C#-based interpreted language that provides:
- Dynamic typing with runtime type checking
- Functional programming features (lambdas, array methods)
- Object-oriented constructs (objects, properties)
- C-family syntax familiar to JavaScript/C# developers
- Rich standard library with ~100 native functions
- Business logic focus optimized for calculations and rules
Quick Example¶
// Calculate insurance premium with age-based adjustments
basePremium = 1000;
age = 35;
if (age < 25) {
premium = basePremium * 1.5;
} else if (age > 65) {
premium = basePremium * 1.25;
} else {
premium = basePremium;
}
// Apply discount for multiple policies
discount = 0.1;
finalPremium = premium * (1 - discount);
// Calculate with date-based rules
today = $Today();
policyStart = $AddDays(today, 30);
yearsDifference = $DifferenceInYears(birthDate, today);
Key Features¶
Dynamic Typing¶
Variables have no declared types - types are determined at runtime:
value = 42; // Number
value = "hello"; // Now a string
value = true; // Now a boolean
value = $Now(); // Now a DateTime
Lambda Expressions¶
First-class functions with arrow syntax:
numbers = [1, 2, 3, 4, 5];
// Filter
evens = numbers.Filter((x) => x % 2 == 0);
// Map
doubled = numbers.Map((x) => x * 2);
// Reduce
sum = numbers.ReduceToNum((acc, x) => acc + x, 0);
Rich Array Operations¶
Comprehensive array manipulation methods:
people = [
{ name: "John", age: 30 },
{ name: "Jane", age: 25 },
{ name: "Bob", age: 35 },
];
// Chain operations
adultNames = people
.Filter((p) => p.age >= 18)
.OrderBy((p) => p.age)
.Map((p) => p.name);
Object Literals¶
Create and manipulate objects dynamically:
policy = {
number: "POL-12345",
premium: 1500,
customer: {
name: "Alice",
email: "alice@example.com",
},
};
// Access properties
customerName = policy.customer.name;
// Modify properties
policy.premium = 1600;
Extensive Date/Time Support¶
Built-in functions for date calculations:
now = $Now();
today = $Today();
nextYear = $AddYears(today, 1);
age = $DifferenceInYears(birthDate, today);
startOfDay = $StartOfDay(now);
Documentation Structure¶
Getting Started¶
- Installation - Setup and prerequisites
- Hello World - Your first EverSharp script
- Using EverSharpRunner - C# API basics
Language Guide¶
- Data Types - Numbers, strings, booleans, dates, objects, arrays
- Operators - Arithmetic, comparison, logical, assignment
- Variables and Constants - Declaration, scope, assignment
- Control Flow - if/else, while loops
- Functions - Function declarations and calls
- Lambda Expressions - Arrow functions and closures
- Objects - Object creation and property access
- Arrays - Array creation and manipulation
Native Functions¶
- Overview - All built-in functions by category
- Mathematics - Math operations
- Date/Time - Date and time functions
- Strings - String manipulation
- Arrays - Array operations
- Conversions - Type conversions
- Utilities - Utility functions
Examples¶
- Basic Calculations - Arithmetic and variables
- Working with Dates - Date manipulation
- Array Operations - Filtering, mapping, reducing
- Object Manipulation - Working with objects
- Business Rules - Real-world scenarios
Reference¶
- Grammar - Complete language grammar
- Operator Precedence - Operator precedence table
- Cheat Sheet - Quick reference guide
Integration¶
- EverSharpRunner API - C# integration
- Environment Setup - Passing data in/out
- Extension Functions - Creating custom functions
AI Agent Reference¶
For AI agents working with EverSharp code, see the comprehensive AI Reference Document which includes:
- Complete grammar specification
- All native functions with signatures
- Error patterns and diagnostics
- Integration patterns
- Type system details
Language Characteristics¶
| Feature | Support |
|---|---|
| Typing | Dynamic |
| Paradigm | Multi-paradigm (imperative, functional, object-oriented) |
| Execution | Interpreted |
| Platform | .NET 9.0 |
| Syntax Style | C-family (similar to JavaScript) |
| Type Coercion | Explicit only (no implicit conversions) |
| Scoping | Lexical (block and function scope) |
| Memory Management | Automatic (managed by .NET) |
Common Use Cases¶
Insurance Premium Calculation¶
function calculatePremium(baseAmount, age, coverage) {
rate = 0.01;
// Age adjustment
if (age < 25) {
rate = rate * 1.5;
} else if (age > 65) {
rate = rate * 1.25;
}
// Coverage adjustment
if (coverage > 500000) {
rate = rate * 1.1;
}
return baseAmount * rate;
}
premium = calculatePremium(100000, 35, 250000);
Date-Based Business Rules¶
effectiveDate = $ToDate("2024/01/15");
expiryDate = $AddYears(effectiveDate, 1);
today = $Today();
// Check if policy is active
isActive = today >= effectiveDate && today <= expiryDate;
// Calculate days remaining
daysRemaining = $DifferenceInDays(today, expiryDate);
if (daysRemaining <= 30) {
$Log("Policy expiring soon!");
}
Data Processing¶
// Load and process data
policies = [
{ id: 1, premium: 1200, status: "active" },
{ id: 2, premium: 800, status: "active" },
{ id: 3, premium: 1500, status: "inactive" },
];
// Calculate total active premiums
totalActive = policies
.Filter((p) => p.status == "active")
.ReduceToNum((sum, p) => sum + p.premium, 0);
$Log("Total Active Premiums: {0}", totalActive);
Getting Help¶
- Review the Language Guide for core concepts
- Check Native Functions for built-in functionality
- Explore Examples for practical patterns
- Consult AI Reference for comprehensive technical details
Next Steps¶
- New to EverSharp? Start with Hello World
- Integrating with C#? See EverSharpRunner API
- Need quick reference? Check the Cheat Sheet
- Looking for examples? Browse Examples
EverSharp - Powerful meta-programming for business logic