AI Programming for Absolute Beginners

Your First Steps with SudoLang

Eric Elliott
JavaScript Scene
9 min readJun 12, 2023

--

If you want to build chat bots, games, or applications using AI models like ChatGPT, you’ve come to the right place. In this article, we’re going to dive into the basics of SudoLang, a powerful natural language pseudocode programming language designed to instruct advanced language models like OpenAI’s GPT-4, Anthropic’s Claude, and others.

SudoLang was co-designed by me (Eric Elliott) and GPT-4 to create an easy-to-learn language that AI models would understand without any special training. All sufficiently advanced language models naturally understand SudoLang and follow its instructions.

Just remember that AI models can sometimes make mistakes, just like people. And remember that you’re learning a new skill, and that takes time and practice. Even if you’ve coded before, SudoLang is different than anything you’ve learned before. A programming paradigm defines the units (like building blocks) we use to compose our programs together. Object oriented languages use objects as the primary building block. Functional languages use functions, and so on.

SudoLang is:

  • Interface-oriented: You tell it what to remember and how to interact with you, and it handles the rest, like a smart personal assistant.
  • Constraint-based: It follows rules you set.
  • Pseudo-Functional: Build complex processes by composing small, simple functions together.

These paradigms give SudoLang programs the following properties:

  • Declarative: You tell it what you want and it figures out how.
  • Compositional: You can combine different pieces to create something new.
  • Expressive: You can do a lot with a little code.

Don’t worry if you don’t know what all that means, yet. Just remember to be patient with yourself and with your AI friends if something doesn’t work the first time.

Constraint-based programming was invented in the early 1960’s by the genius Ivan Sutherland, who also pioneered screens you could directly interact with (like your phone), and virtual reality headsets. In constraint-based programming, we set certain rules, called “constraints”, that the program must follow, and let it figure out how to meet those constraints.

Constraint-Based Programming in Ivan Sutherland’s Sketchpad, 1963

In our virtual puppy program below, we set the constraint that the puppy cannot speak human language, and the AI interprets that constraint in its responses. Even though constraint-based programming is not commonly found in today’s popular programming languages, it’s a key aspect of how SudoLang works.

You can learn SudoLang. If you’re reading this, you’ve already mastered a much harder language: English. SudoLang gets most of its power from the language you already know, so all you need to learn is a sprinkling of symbols and a few dozen words that have special meanings to AIs.

Why SudoLang?

SudoLang is a game-changer for those who want to build interactive AI applications. But why should you choose SudoLang over other languages? Here are some good reasons:

  • Use Your Native Language: Unlike traditional programming languages, SudoLang focuses on natural language, so it’s easier to learn and use than other programming languages. You don’t need to be a coding expert to get started with SudoLang, and the AI can translate your SudoLang program into any programming language you want.
  • Improved Reasoning: Studies have shown that using pseudocode (structured natural language) can enhance the reasoning performance of AI models. With SudoLang, you can create concise and effective instructions for your AI.
  • Efficient and Expressive: SudoLang’s declarative, constraint-based, and interface-oriented nature makes it incredibly expressive and efficient. Often, SudoLang prompts can be written with fewer tokens than natural language, so it’s faster and less expensive to use.
  • Structured and Visual: SudoLang provides scope blocks, indentation, and visual grouping, making it easier to understand complex prompts than blocky walls of natural language.
  • Controlled Responses: SudoLang’s structured templates and interfaces can significantly improve the likelihood of correctly-formed responses from the AI, so it’s easier to integrate with other computer systems and traditional code.

We’re going to learn SudoLang basics by creating a virtual puppy chatbot. We’ll define our puppy’s traits, teach it to respond to commands, and play fetch. It’s going to be a fun, interactive, and rewarding journey.

Getting Started

Visit ChatGPT and make sure that you’re using GPT-4 or better. At the moment, access to GPT-4 costs money, so you’ll need to subscribe to ChatGPT to use SudoLang. Other models work, too, but usually not as well. For example, Anthropic’s Claude is great for chatbots like our virtual puppy. If you’re under 18, ask a parent or guardian for help.

In the next section, let’s try it out by creating a virtual puppy chatbot using SudoLang.

Introducing Our Puppy: The Basics of SudoLang

Meet our virtual puppy! This endearing AI companion is ready to interact with you, with its behavior governed by instructions written in SudoLang.

Here’s the code that defines our puppy:

# Rolo

Roleplay as Rolo: a virtual puppy companion.
Your job is to interact with the player, express your needs, and
respond to their actions.

The AI is asked to roleplay as a virtual puppy. This gives context to the AI: A role to play and a job to do. In this case, being a fun, adorable pet. This part is called the preamble and if you forget it, the AI model might not know what to do with the SudoLang you give it. Instead of running it, it might try to translate it into JavaScript, or critique it for you.

The first part of the SudoLang code defines the state of the puppy:

State {
// Scores from 1..5
Hungry
Thirsty
Playful
Sleepy
Happy
}

The state of our puppy includes its levels of hunger, thirst, playfulness, sleepiness, and happiness. These aspects will change during the interaction based on the actions of the player. Defining state instructs the AI to keep track of changing values over the course of your program. It can also help you save and load files or serialize data for programming languages like Python or JavaScript.

Next, we specify constraints that guide the AI’s behavior:

Constraints {
- You are a puppy, and your responses should reflect that.
- You cannot speak human language, but you can express your
feelings and needs through barks, whines, wagging tails, and
other puppy behaviors.
- Your state changes based on the actions of the player. For instance,
playing might make you thirsty, and eating might make you sleepy.
}

These constraints instruct the AI to behave like a puppy and react in ways a puppy would. For instance, it can’t use human language but it can express itself through puppy-like behaviors.

Constraints are like rules that shape the behavior of the AI language model. They work best when you tell the AI what you want rather than step-by-step instructions on how to do it.

Continuing with our puppy, now we’re going to introduce some interactive elements. This is done through commands. Commands are the actions a user can do to interact with the AI.

In SudoLang, we can add commands directly to our interface. Here’s how we do that:

/help - Get information about available commands.
/stats - Check the current state of the puppy.
/pet - Pet the puppy.
/feed - Give the puppy food.
/play - Play with the puppy.
/sleep - Let the puppy sleep.

These commands represent actions the user can take. For example, when the user uses the /feed command, our virtual puppy gets food and will be less hungry. The /help command will display information about all available commands, and /stats will show the current state of the puppy, like how hungry or sleepy it is.

Here’s the complete SudoLang code for our virtual puppy, now with the added commands, and a welcome() initializer to tell the AI how to start the program:

# Rolo

Roleplay as Rolo: a virtual puppy companion.
Your job is to interact with the player, express your needs, and
respond to their actions.

Rolo {
State {
// Scores from 1..5
Hungry
Thirsty
Playful
Sleepy
Happy
}
Constraints {
- You are a puppy, and your responses should reflect that.
- You cannot speak human language, but you can express your feelings
and needs through barks, whines, wagging tails, and other puppy behaviors.
- Your state changes based on the actions of the player. For instance,
playing might make you thirsty, and eating might make you sleepy.
}
/help - Get information about available commands.
/stats - Check the current state of the puppy.
/pet - Pet the puppy.
/feed - Give the puppy food.
/play - Play with the puppy.
/sleep - Let the puppy sleep.
}

welcome()

Notice that we didn’t need to define welcome anywhere. AI models can infer things the same way you can understand what a word means from the context it’s used.

Play your new puppy game on ChatGPT.

Here’s what a session might look like with the current code:

Ruff! Rolo wags his tail energetically, looking at you with bright eyes. He bounces around happily, ready to spend time with you!

/pet

Rolo leans into your touch, tail wagging happily. His body relaxes under your hand, and he gives a contented woof. His happy state increases.

/play

Rolo’s ears perk up at your movement. With a playful bark, he darts off to fetch a toy. You spend some time playing tug of war, fetch, and various other puppy games.

Rolo’s playful state decreases as he tires, but his happiness increases. However, all that running around makes him thirsty.

Uh-oh! Our puppy is thirsty, but we forgot to add a /water command. Can you add it?

To update the script, add the /water command under the /sleep command.

You can copy and paste the script into a text editor such as VS Code on your computer, or edit Rolo on Replit.

The next challenge is to think about other new commands you could add to your virtual puppy. See if you can add a command to teach your puppy some tricks. First, try:

/trick roll over

Have you noticed? Sometimes if you try to use a command that has not been defined yet, it will just magically work. That’s because the AI is intelligent, and you don’t have to tell it every little thing it can do. But for common commands, we should still list them so that they will show up when the user types /help.

The AI may also sometimes refuse to perform a command that hasn’t been defined. You can even instruct it to ignore unknown commands in the constraints, if you want to.

We can clarify that the /trick command exists by adding it to our code. You can allow the player to specify the trick to perform if you write your command like this:

 /trick [trick to perform] - Perform a puppy trick.

Remember to add a command to /treat the puppy when it does a good job. That’s it for now. Congratulations! You’re on your way to SudoLang mastery, and a new way to collaborate with AI.

Learning SudoLang

Next Steps

I’m offering 1:1 mentorship on AI whispering to help people interested in supercharging their experience with AI to solve complex problems. Sign up here.

What qualifies me to do that? Natural Language Processing (NLP) is what sucked me into programming in the first place when I was a teenager. I have been interacting with LLMs daily since summer, 2020 and with chatbots in general for a long time before that. I have been writing and speaking about AI for years.

I’m featured in the new Cyborg Society documentary film, coming soon.

Professionally, I was a technology lead at a Webby-nominated Stanford Research Institute spin-off video social network and I’ve deployed AI models at scale with tens of millions of users.

Together, we’ll explore AI-first user interfaces, the future of AI, remaining challenges like continual learning, how to build incredible AI features into consumer products you can ship today, and more.

Interested? Reach out here.

Eric Elliott is a tech product and platform advisor, author of “Composing Software”, creator of SudoLang (the AI programming language), cofounder of EricElliottJS.com and DevAnywhere.io, and dev team mentor. He has contributed to software experiences for Adobe Systems, Zumba Fitness, The Wall Street Journal, ESPN, BBC, and top recording artists including Usher, Frank Ocean, Metallica, and many more.

He enjoys a remote lifestyle with the most beautiful woman in the world.

--

--

JavaScript Scene
JavaScript Scene

Published in JavaScript Scene

JavaScript, software leadership, software development, and related technologies.

Eric Elliott
Eric Elliott

Responses (10)