DEV Community

Ingi
Ingi

Posted on

In Theory: Self-Correcting Software

This article explores Plang, an intent-based programming language designed to interpret natural language. For more information, visit plang.is or take your first steps

In Plang, you can bind events to goals(functions) and steps(line of code), a feature that proves incredibly powerful.

Let's consider a scenario: you want to ensure that a user is logged in before they can call a function in the /admin route.

No problem in Plang:

Events
- before any goal in /admin, call AuthenticateUser

AuthenticateUser
- select id as userId from users where %Identity% and role='admin', return 1 row
- if %userId% is empty then
    - show error "You don't have permission"
Enter fullscreen mode Exit fullscreen mode

And there you have it—authentication is solved in just 4 lines of code.

How does this translate to self-correcting software?

Self-Correcting Software

Let's say I'm making a POST request to a service:

CreateUserAsExample
- post https://example.org/api/createuser
    {name:"%name%", }
Enter fullscreen mode Exit fullscreen mode

Now, let's bind an event to all error that happen in step.

Events
- on error on any step, call SelfCorrect

SelfCorrect
- [llm] system: fix this plang code...
    user:%!error.Message%
    write to %code%
- write to %!error.Goal.RelativePath%
- build plang code
- retry step
Enter fullscreen mode Exit fullscreen mode

Here, we've instructed the LLM to fix the Plang code.

If the /api/createuser service now requires more than just a name, it will return an error message such as "{error:"You need to provide Email (%email%)"}.

Asking the current Plang assistant to handle this scenario would give you an updated response:

CreateUserAsExample
- post https://example.org/api/createuser
    {name:"%name%", email:%email%}
Enter fullscreen mode Exit fullscreen mode

Now, plang code can save the new code to its path, build and run the code.

But What if the Email is Still Empty?

Yes, the %email% field might still be empty.

In this case, you need to traverse up the call stack and fix the previous goal. Once one issue is resolved, the same principle applies to the next one. It's just a matter of engineering.

More Information

If Plang is interesting to you, you should dig a bit deeper:

Top comments (0)