AI Writes the Code. Why Hasn't the Syntax Changed? · 05
Beyond the Basic Syntax
By Episode 4, I had implemented From Variables to Functions: I Built a Programming Language. Now that the language could parse and run sentences, I had achieved part of my original goal. But once I actually started From Variables to Functions: I Built a Programming Language, basic syntax was no longer enough. I wanted to express relationships between values, process collections of data, split code across files, create objects, and handle work that took time.
This was where the scope of FlowScript changed. What began as an experiment in writing Between Natural Sentences and Precise Syntax became an experiment in using that syntax to describe more complex programs.
The features in this episode are grouped for clarity, not reconstructed in exact chronological order. Throughout development, AI helped with everything from syntax ideas and code generation to tests and debugging. My main contribution was to read the results, understand how they worked, and decide which syntax and architecture to keep.
The JavaScript snippets below are hand-written equivalents for comparing meaning and readability. They are not necessarily the literal JavaScript generated by the FlowScript transpiler.
Reactive Variables
I first needed a different kind of variable from ordinary assignment. Suppose I calculate a total from a product's price and quantity. If the price changes later, the previously calculated total does not change by itself.
Set price to 100
Set quantity to 2
Set snapshot to the result of (price * quantity)
Set total always is the result of (price * quantity)
Set price to 150
Print snapshot.
Print total.
JavaScript (equivalent behavior):
let price = 100;
const quantity = 2;
const snapshot = price * quantity;
const state = {
get total() {
return price * quantity;
}
};
price = 150;
console.log(snapshot); // 200
console.log(state.total); // 300
JavaScript can use a getter to recalculate a property whenever it is read. Likewise, always is describes a calculation relationship rather than copying a value.
In this example, snapshot prints 200, while total prints 300. Set ... to evaluates an expression at assignment time, whereas Set ... always is binds the variable to the expression. More precisely, the expression is reevaluated every time the variable is read. It does not push a new value automatically at the exact moment a dependency changes.
I also had to consider performance and circular references. Recalculating on every read is easy to reason about, but repeated reads can repeat the same work. More fundamentally, if alpha depends on beta while beta depends on alpha, neither value can be resolved. FlowScript detects such cycles and raises an error.
The idea of a computed value is not new—other languages have computed properties and reactive bindings. What interested me was expressing the relationship as a sentence: “this value always is the result of that calculation.”
Collections
I had introduced lists while building loops, but iterating over a list was not enough for working with real data. I also needed to eliminate duplicates, select items that matched a condition, and extract particular fields.
So I added Set collections for unique items, Record values for grouped fields, and where and select for building new lists from existing ones. I also implemented readable collection helpers such as first item of, count of, index of, and contains item.
Create a List called users defined as:
- {Name: "Alice", Age: 25, Active: Yes}
- {Name: "Bob", Age: 17, Active: No}
Create a List called adults from users where Age >= 20.
Create a List called active names from users where Active is Yes select Name.
JavaScript (equivalent behavior):
const users = [
{ Name: "Alice", Age: 25, Active: true },
{ Name: "Bob", Age: 17, Active: false }
];
const adults = users.filter(user => user.Age >= 20);
const activeNames = users
.filter(user => user.Active)
.map(user => user.Name);
One of the most enjoyable additions was the Take ... Then ... pipeline. Instead of chaining function calls, I could describe data processing as a sequence of instructions.
Take raw orders:
Then filter where status is "Delivered"
Then sort by Amount descending
Then take the first 2 items
Then select Email
Then save to vip emails as a list
JavaScript (equivalent behavior, assuming rawOrders is already defined):
const vipEmails = rawOrders
.filter(order => order.status === "Delivered")
.sort((a, b) => b.Amount - a.Amount)
.slice(0, 2)
.map(order => order.Email);
A JavaScript method chain becomes a sequence of Then filter, Then sort, and Then select instructions in FlowScript.
This example keeps delivered orders, sorts them by amount, takes the first two, and saves their email addresses as a list. The repository includes an example in this form. I liked that the steps could be followed almost directly from top to bottom.
Of course, looking like English does not mean that every English sentence is valid syntax. I still had to define which steps were allowed—such as Then filter, Then sort, and Then select—and precisely what each step accepted and returned.
Extending Functions
After implementing functions, I wanted to validate not just what a function did, but also the inputs it received and the results it produced. I added Ensure to express preconditions and Verify to express postconditions.
How to calculate discount using price and tax and returns Number:
Ensure price is greater than or equal to 0.
Ensure tax is greater than or equal to 0.
Set total to the result of round(price * (1 + tax), 2)
Verify total is greater than or equal to 0.
Return total.
JavaScript (equivalent behavior):
function calculateDiscount(price, tax) {
if (price < 0) throw new Error("Invalid price");
if (tax < 0) throw new Error("Invalid tax");
const total = Math.round(price * (1 + tax) * 100) / 100;
if (total < 0) throw new Error("Invalid result");
return total;
}
In JavaScript, similar checks can be written using ordinary conditionals and thrown errors. FlowScript distinguishes input and result checks with Ensure and Verify.
I could have written these validations with regular conditional statements. But Ensure and Verify make the function's promises visible as separate sentences. In the parser and runtime, I still needed to specify where those clauses were allowed and what happened when they failed.
I also added anonymous callables alongside named functions. With do this using ... or the result of this using ..., a function can become a value stored in a variable or passed to another function. Executing a function as a statement is different from treating it as a value, even if both belong to the same general concept. This was another way to extend what the basic function feature could express.
Object-Oriented Programming
Of all the extensions, object-oriented programming was the one I enjoyed most. Just as implementing functions had made me ask “What exactly is a function?”, this time I started with a similar question: What is an object, and how can I make that concept intuitively understandable?
An object combines properties and behavior. What if I described a type like a blueprint, then described creating an object from it?
Define a Type called User:
It has a public Name (Text).
It has Points (Number, default is 0).
It can "Show Name" as public:
Print its Name.
Create a User called sample user:
Name is "Alice"
Ask sample user to "Show Name".
JavaScript (equivalent object definition and invocation):
class User {
Name;
Points = 0;
showName() {
console.log(this.Name);
}
}
const sampleUser = new User();
sampleUser.Name = "Alice";
sampleUser.showName();
It has corresponds to a property declaration, It can to a method definition, and Ask to a method call. This JavaScript example does not implement the same runtime type checking as FlowScript's Text property declaration.
I used Define a Type called to define types, It has for properties, and It can for actions. Instances are created with Create, and methods are called with Ask. Read together, the syntax resembles a description of a program's components.
Inheritance raised another question: what phrase would make that relationship immediately clear? I could have copied extends from other languages, but which is a kind of felt more appropriate for FlowScript.
Define a Type called Admin which is a kind of User:
It has a public Permissions (List of Text).
JavaScript (inheritance relationship only):
class Admin extends User {
Permissions;
}
FlowScript's which is a kind of corresponds to JavaScript's extends. This JavaScript example illustrates the relationship without reproducing FlowScript's List of Text type validation.
The phrase says directly that an Admin is a kind of User. In the implementation, child types inherit the parent's properties and methods. A child can override a method or call its parent using Ask super to .... I also supported public, protected, and private access control, constructors, and methods that return values.
On the surface, this may look like a matter of rewriting a few keywords. Underneath, I had to define object initialization order, member access, and the rules for calling overridden behavior. I enjoyed having to reconsider familiar OOP concepts and express them as English sentences.
Modules
As the language gained features, keeping everything in one file became impractical. I needed a way to use functions and types defined elsewhere. I introduced Share to expose names from a file and Use to import them.
Use formatter and parse user from "./text-tools.flow".
Print the result of parse user using "Alice".
JavaScript (equivalent module use):
import { formatter, parseUser } from "./text-tools.js";
console.log(parseUser("Alice"));
FlowScript's Share / Use serves a similar purpose to JavaScript's export / import. FlowScript permits spaces in function names, whereas the JavaScript example uses the identifier parseUser.
I also allowed importing an entire module under an alias, such as Use "./text-tools.flow" as text tools. The important decision was not just how to concatenate multiple files, but which names should be public and how the files should depend on one another.
The current implementation uses relative .flow paths, runs each module only once, and rejects circular imports. There are concrete execution rules behind the readable Share and Use sentences.
Lifecycle and Action Hooks
Once objects existed, I also wanted to express behavior that runs automatically when an object is created or updated. I added When created: and When updated:, including the ability to receive constructor parameters.
I later added Before and After hooks to run code around a particular object action. For example, a program might validate input before changing an email address and record the change afterward.
Inheritance made the execution order especially important. If both a parent and child type define hooks, which should run first? In the current implementation, inherited Before hooks run from parent to child, while After hooks run from child to parent. Creation and update hooks have their own ordering rules.
In the end, hooks were not simply another pair of syntax forms. They defined when an object should do something, and in what order.
Asynchronous Work and Error Handling
Next I needed to describe work that takes time. Ordinary statements can run in sequence, but a program also needs to wait for results or schedule something to happen later.
Set email job to the background task:
Print "Preparing email".
Wait for email job.
JavaScript (creating a task and waiting for completion):
const emailJob = Promise.resolve().then(() => {
console.log("Preparing email");
});
await emailJob;
Both examples represent a task as a value and then wait for its completion. The internal scheduling of JavaScript Promises and FlowScript's current task model is not identical.
I added forms such as In the background, the background task, After, and Wait for to express starting work and waiting for it. The language also supports Wait for all of (...) when every task must finish, and Wait for any of (...) when one result is enough. Cancellation and wait timeouts extend the same idea.
There is an important limitation here: the current FlowScript runtime is not a general-purpose asynchronous engine with fully realistic parallel execution. Built-in background tasks use a simplified execution model, and delayed tasks use a virtual scheduler so tests can run quickly. It is more accurate to say that FlowScript provides syntax and an execution model for representing asynchronous tasks.
What if a task fails? I added Try this:, If it fails:, and In any case: to handle recovery and cleanup, including cleanup that runs regardless of success or failure. Errors can also expose structured information such as their code, kind, and message.
File Input and Output
Beyond calculations inside the language, I wanted programs to read and write files. I added the standard/files.flow module to support reading, writing, appending, checking existence, and deleting text files.
Use read text from file and write text to file from "./standard/files.flow".
Wait for write text to file using "./notes.txt" and "Hello".
Set contents to the result of wait for read text from file using "./notes.txt"
Print contents.
JavaScript (equivalent file reading and writing in Node.js):
import { writeFile, readFile } from "node:fs/promises";
await writeFile("./notes.txt", "Hello", "utf8");
const contents = await readFile("./notes.txt", "utf8");
console.log(contents);
The FlowScript files.flow module wraps host file operations in sentence-style functions and Wait for. However, the path resolution and permission rules differ.
File operations return tasks, connecting file I/O to the asynchronous syntax described above. FlowScript does not reimplement operating-system file access from scratch. It uses the JavaScript execution environment while defining which functions are available, how callers wait for them, and how errors are handled.
For now, the system supports UTF-8 text files and relative paths within the workspace. Absolute paths and attempts to escape the workspace are rejected. Building file I/O meant deciding not just what the language could do, but what it should be allowed to access.
Implemented Scope and Conclusion
I had now added reactive variables, collection processing, function contracts, anonymous callables, objects, modules, hooks, asynchronous tasks, error handling, and file I/O. FlowScript was no longer just a small experiment that could execute Set and Print. With those features connected, it could describe programs made of multiple components across more than one .flow file.
Of course, this is not yet a complete general-purpose programming language. Sets containing records, set union and intersection, general arithmetic expressions interpolated inside strings, and object deletion with When deleted have not been implemented. The supported syntax still has limits and constraints.
At first, my goal was simply to make programming syntax read more like English. As the scope grew, I realized I was doing something else as well: reconsidering concepts like functions, objects, inheritance, and asynchronous work, then turning those ideas into explicit rules a computer could follow. AI helped throughout development, but reading its output and deciding which design choices to keep remained my responsibility.
Showing what FlowScript can implement today is enough to capture this stage of the project. In the next episode, rather than list more features, I want to look back at what I learned and what I still find unsatisfying.