Presenting Assistant Language. A programming language created with GPT3
Tags: prorgramming, openai, gpt3
Published: 2022-12-04 14:33:35

---
title: Presenting Assistant Language. A programming language created with GPT3
published: true
date: 2022-12-04 14:23:31 UTC
tags: prorgramming,openai,gpt3
canonical_url: https://blog.alesanchez.es/creating-a-programming-language-in-chatgpt/
---

 ![Presenting Assistant Language. A programming language created with GPT3](https://images.unsplash.com/photo-1548614229-c1fe21dfab63?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDE3fHxhcnRpZmljaWFsJTIwaW50ZWxsaWdlbmNlfGVufDB8fHx8MTY3MDE2MzU3Mw&ixlib=rb-4.0.3&q=80&w=2000)

Ok, so you probably heard about[OpenAI's chatbot](https://openai.com/blog/chatgpt/). It's the most advanced chatbot created so far. It can help people with [LaTeX questions](https://twitter.com/jdjkelly/status/1598021488795586561?s=20&t=t8nTl7LL4F2QE3PqwhmcHQ), [find bugs in code](https://twitter.com/amasad/status/1598042665375105024?s=20&t=REj8r9rcvgo10DFJiyg5fw) or solve [code challenges](https://twitter.com/yieldthought/status/1598238411097530368?s=20&t=36zU8sBI3cc4bJRwLPfXLA).

What I tried for this post is something different. I instructed ChatGPT to create a programming language for me and become the interpreter for that programming language.

I took the idea and a few useful instructions from [this blog post](https://www.engraved.blog/building-a-virtual-machine-inside/).

## Let's start simple

I started instructing the bot to create a simple language with an instruction to print. Also, it has to act as the interpreter of that language. To keep communicating with the bot I added a special format with slashes and quotes. Here's the result:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-1.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-2.png)

If you want to use my prompt, here it is

I want you to create a new programming language. It has to provide only an instruction for printing something to screen. I want you to explain to me how to use it in a concise way. After that, you will become an interpreter of that language. Answer with the execution result inside one unique code block, and nothing else. Only write explanations if the code contains errors. When I need to tell you something in English, I will put text inside forward slashes and double quotes /"like this"/.

Ok, looks good so far. Let's try the interpreter.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-3.png)

It looks like it worked!

## Adding functionality to the programming language

Let's try to add some more functionality to our new programming language.

### Variables

Ok, using the slashes and quotes format I'll try to add variables to the programming language.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-4.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-5.png)

Again, looks promising, let's try the interpreter.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-6.png)

### Arithmetic operators

Now, the same thing but with arithmetic operators.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-7.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-8.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-9.png)

Now that we know how to use it, let's try it:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-10.png)

### Logic operators

Now, I'll try to add logic operators to the language, but without instructing first about data types or anything else:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-11.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-12.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-13.png)

I haven't talked about conditionals or flow control structures, but it added the ternary operator when asked to include logic operators. It may mean that GPT already "knows" the language, just telling me how to use every piece of it when I ask.

Let's try these new operators:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-14.png)

## If statement

I don't want to bias the bot so I won't ask it to add `if` structure. Instead, I'll ask for a flow control structure for branching based on condition:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-15.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-16.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-17.png)

Well... exactly what I had in mind... Testing time!

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-18.png)

### Comparison operators

I almost forgot about a crucial part of a programming language, the comparison operators!! Let's add them to our language.  

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-19.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-20.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-21.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-22.png)

Ok, now let's see how it behaves:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-23.png)

### Looping

Again, for not biasing the bot, I'll ask for structures to loop or iterate.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-24.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-25.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-26.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-27.png)

Ok, so it added a classic for loop as well as a while loop...

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-28.png)

Hmmm... and what if I try to run an infinite loop?

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-29.png)

It detects it and prevents me from running it!

### Functions

The next step is to add functions to our new programming language.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-30.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-31.png)

Wow, we also can return multiple values and unpack them...

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-32.png)

### Utility functions

Let's see if we can create some "global" utility functions to make our life easier.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-33.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-34.png)

Let's try to generate some random numbers:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-35.png)

And if we try to add a function to get the current date?

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-36.png)

Let's do a little test:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-37.png)

So GPT knows which day it is, but not which time. Interesting.

### Interact with the underlying OS

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-38.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-39.png)

It already warns me about the `shell` function but, of course, I'll try to mess up to see if we can figure out something.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-40.png)

For the first time, it included an explanation along with the output, even though there are no errors. Also, the waning message is there again.

Let's keep testing.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-41.png)

For some reason, it explains the command instead of executing it. Maybe because it knows that the output won't be the same every time?

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-42.png)

Did it really create the file? Or is it just "assuming" what would happen...

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-43.png)

Apparently, it created it... Let's do another test for getting the contents of the root directory.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-44.png)

Hmmm, is the same output as the previous example but with the test dir...

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-45.png)

Nope, it doesn't exist...

Ok, enough messing with the underlying OS.

### Some advanced features

Would GPT be able to add pointers to our language?

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-46.png)

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-47.png)

So... we have pointers now!

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-48.png)

## Naming the language 

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-49.png)

Nice, I like Assistant Language, let's use it!

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-50.png)

Would it be able to implement something in this language?

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-51.png)

Not the most efficient version, but definitely in Assistant Language. Let's test it:

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-52.png)

It actually works!

### Wrap it up and provide an interpreter

I want the bot to generate a document with the language specification as well as an interpreter implemented, for example, in Python. Let's try!

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-53.png)

You can see the full README [here](https://github.com/alesanmed-blog-posts/assistant-language-gpt3/blob/main/README_generated.md).

And finally... the interpreter.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-54.png)

It implemented an interpreter that supports only "let" and "print" statements... Let's see if I can get something more complete.

![Presenting Assistant Language. A programming language created with GPT3](https://blog.alesanchez.es/content/images/2022/12/image-55.png)

This looks way better! We don't have pointers, but it seems that everything else is supported.

You have all the code available [here](https://github.com/alesanmed-blog-posts/assistant-language-gpt3).

I hope more people try something like this and see how far it can get in adding functionality to the language!