feat: engram-lang — new programming language, quantum-sealed prod target, spreading activation types
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// activate.el — The `activate` construct: spreading activation over the type graph.
|
||||
//
|
||||
// The `activate` keyword is the most novel feature of the Engram language.
|
||||
// Instead of querying a database with SQL or a key lookup, you query the
|
||||
// *type graph* using a natural language description. The result is
|
||||
// statically typed — the compiler knows you get [User] back, not Any.
|
||||
//
|
||||
// How it works:
|
||||
//
|
||||
// 1. At compile time, the type checker verifies that `User` is a registered
|
||||
// type with a corresponding Engram node mapping.
|
||||
//
|
||||
// 2. At runtime, the Engram runtime performs spreading activation over
|
||||
// the knowledge graph, starting from the User node, propagating to
|
||||
// semantically related nodes with co-activation energy proportional
|
||||
// to edge weights and node salience.
|
||||
//
|
||||
// 3. The query string "customer who purchased recently" is embedded
|
||||
// and used as a semantic filter: only nodes whose embeddings are
|
||||
// within cosine-similarity threshold of the query embedding are returned.
|
||||
//
|
||||
// 4. The result is type-safe: [User]. You don't get back Any or a JSON blob.
|
||||
// The type checker enforces this at compile time.
|
||||
|
||||
type User {
|
||||
id: Uuid
|
||||
name: String
|
||||
email: String
|
||||
}
|
||||
|
||||
type Order {
|
||||
id: Uuid
|
||||
user_id: Uuid
|
||||
amount: Float
|
||||
status: String
|
||||
}
|
||||
|
||||
// Query: find all users who are semantically related to "customer who purchased recently"
|
||||
// The result type is [User] — an array of User nodes from the knowledge graph.
|
||||
let recent_buyers: [User] = activate User where "customer who purchased recently"
|
||||
|
||||
// You can also activate on other types:
|
||||
let pending_orders: [Order] = activate Order where "order awaiting fulfillment"
|
||||
|
||||
// Spreading activation respects the type graph edges.
|
||||
// If User and Customer share an Engram node type (e.g. "Entity"),
|
||||
// they are semantically compatible — the type checker allows
|
||||
// treating one as the other when they map to the same Engram node class.
|
||||
|
||||
fn process_buyers(users: [User]) -> String {
|
||||
return "processing users"
|
||||
}
|
||||
|
||||
let result: String = process_buyers(recent_buyers)
|
||||
@@ -0,0 +1,8 @@
|
||||
// hello.el — The simplest Engram program.
|
||||
// Run with: el run hello.el
|
||||
|
||||
fn greet(name: String) -> String {
|
||||
return "Hello, " + name
|
||||
}
|
||||
|
||||
let message: String = greet("World")
|
||||
@@ -0,0 +1,40 @@
|
||||
// types.el — Type definitions and pattern matching.
|
||||
//
|
||||
// Demonstrates:
|
||||
// - type (struct) definitions
|
||||
// - enum definitions with payloads
|
||||
// - match expressions with enum patterns
|
||||
|
||||
// A user-defined struct type.
|
||||
// Every field is typed; the type name maps to an Engram graph node.
|
||||
type User {
|
||||
id: Uuid
|
||||
name: String
|
||||
email: String
|
||||
}
|
||||
|
||||
// An enum with a payload variant.
|
||||
enum Status {
|
||||
Active
|
||||
Inactive
|
||||
Pending(String)
|
||||
}
|
||||
|
||||
// A function that takes a Status and returns a human-readable string.
|
||||
fn describe_status(s: Status) -> String {
|
||||
return match s {
|
||||
Status::Active => "user is active"
|
||||
Status::Inactive => "user is inactive"
|
||||
Status::Pending(reason) => "pending: " + reason
|
||||
}
|
||||
}
|
||||
|
||||
// Sealed blocks protect sensitive values even in debug builds.
|
||||
// The runtime enforces that values in sealed blocks are never
|
||||
// observable through a debugger or memory dump.
|
||||
sealed {
|
||||
let api_key: String = "sk-prod-12345"
|
||||
}
|
||||
|
||||
let status: Status = Status::Pending("email not verified")
|
||||
let description: String = describe_status(status)
|
||||
Reference in New Issue
Block a user