Skip to content

b33j0r/komrad-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

komrad-lang

komrad is in early preview development

Komrad is a programming language designed for writing concurrent and distributed applications. The runtime is inspired by the actor model, and the language is agentic. It has many features from smalltalk and lisp.

  • Everything is message passing between agents
  • Blocks and channels are first-class values
  • An agent can be spawned from a block containing pattern-matching handlers
  • Agents all the way down (e.g. spawn Bob sends a message to the SpawnAgent)
Bob = {
    [start] {
        Io println "Hello, I'm Bob."
    }

    [message _msg] {
        Io println "Bob received message: '" + msg + "'"
    }
}

bob = spawn Bob

Alice = {
    bob = null

    [start] {
        Io println "Hello, I'm Alice."
        bob message "Hello Bob!"
    }
}

alice = spawn Alice {
    bob: bob
}

Pattern Matching

Komrad's dispatch system is based on pattern matching, allowing for flexible and powerful message handling. Komrad does not have a traditional if statement, but instead uses a pattern matching construct that can be used to achieve similar functionality:

If = {
    [_(true) _{consequent}] {
        *consequent
    }

    [_(false) _{consequent}] {}

    [_(true) _{consequent} else _{alternative}] {
        *consequent
    }

    [_(false) _{consequent} else _{alternative}] {
        *alternative
    }
}

if = spawn If {}

Capture Types

Named Capture

To capture any value in a handler pattern, use the _name syntax.

Alice = {
    [see you at _time] {}
        Io println "Told Alice to meet at " + time
    }
}

Predicate Capture

To capture a value that matches a predicate, use the _(x == 5) syntax:

Alice = {
    [see you at _(x == 5)] {
        Io println "Alice only meets at 5 o'clock"
    }
    
    [see you at _time] {
        Io println "Alice only meets at 5 o'clock, not " + time
    }
}

Block Capture

To capture a block, use the _{block} syntax. Blocks can be executed in another scope using the *block syntax, where * is also called an "expander":

Alice = {
    [I want you to execute _{block}] {
        Io println "Alice received a block to execute"
        *block
    }
}

Websockets Example

cargo run -- repl examples/web/websockets.kom

REPL

Tests

To run the regression tests (golden tests) for the parser, use the following command:

cargo test golden --package komrad-parser -- --show-output

About

A message-passing agent language, embeddable in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published