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
- if %userId% is empty then
- show error "You don't have permission"
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%", }
At some point in future, the service changes and requires us to provide email, it will return an error message such as this:
{"error":"You need to provide Email (%email%)"}
.
Now, let's bind an event to all errors 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%
...
Here, we've instructed the LLM to fix the Plang code. If we ask the current Plang assistant to handle this scenario, it would give you an updated code
CreateUserAsExample
- post https://example.org/api/createuser
{name:"%name%", email:%email%}
Now, plang can save the new code to its path, build and run the code.
- write %code% to %!error.Goal.RelativePath%
- run terminal plang build
- retry step
The full code for the event is then
Events
- on error on any step, call SelfCorrect
SelfCorrect
- [llm] system: fix this plang code...
user:%!error.Message%
write to %code%
- write %code% to %!error.Goal.RelativePath%
- run terminal plang build
- retry step
Self correcting software in few lines of code. Plang is just awesome!
But What if the Email is Still Empty?
Yes, the %email% field might still be empty, because the email might be coming from some user interface.
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.
Part 2
Read up on part 2 here
More Information
If Plang is interesting to you, you should dig a bit deeper:
Simple Todo example is a good start
Check out the GitHub repo
Meet up on Discord to discuss or get help
Chat with the Plang Assistant