A fuzzy-logic language embedded in Scala 3, with fuzzy sets, logic gates, scoped variables, classes and partial evaluation.
The assignment was to model fuzzy logic as language constructs, so programs reason with degrees of truth instead of booleans. The interesting part is evaluating an expression when some of its inputs aren't known yet: the language should simplify what it can and leave the rest as an expression.
Fuzzy sets
Union (max), intersection (min), complement, addition, multiplication, XOR and alpha-cuts.
Gates and assignment
A gate evaluates its inputs when they're known, and returns a partial result when one is still unresolved.
Scopes
Immutable maps chained to a parent, so lookups walk outward through enclosing scopes.
Partial evaluation
Constant folding over addition and multiplication, leaving unresolved parts as expressions.
Classes
Classes with inheritance, nested classes and method dispatch.
Tests
31 ScalaTest cases covering the operators, scoping and classes.
Either[FuzzySet, String] for values. A value is either a resolved fuzzy set or the name of something not bound yet, so every operation has to handle the unresolved case explicitly.It's an embedded language, so programs are built as Scala case-class trees. There's no text parser, and the optimizer is constant folding. The grader also pointed out that partial evaluation of conditionals still needed values for variables that should have stayed symbolic. If I came back to it, that's the first thing I'd fix, and then I'd add a parser.
Next project
MTProto 2.0 ChatA chat app with MTProto 2.0-style message encryption on the server and an end-to-end encrypted secret chat in the browser.