ChatGPT helped me design a brand new programming language

thumbnail

Since we all know by now that ChatGPT is capable of some crazy stuff, let’s just cut to the chase.

I forced ChatGPT to be my assistant in designing a brand-new programming language. Along the way, I made obscure language syntax and semantic choices to see if it can handle it.

Note, since ChatGPT often answers very verbosely — even if you ask it not to — I have removed any extraneous explanations it produced. The core of the conversation remains unaltered.

Alright, we’ve got something! Wasn’t expecting this to work but it seems promising.

It got something wrong though, the strings are delimited by double quotes – not what I asked for. Also, I would like object keys not to be wrapped in quotes at all. Let’s fix that.

So far so good. ChatGPT implicitly created a variable construct. I’d like variables to look a bit less python-ish though.

It understood what I was looking for perfectly. Let’s pretend I’m stuck, where do we go from here?

Nice! We’ve got a JavaScript-style lambda in our language now. I’d like it to look a bit different though.

Now I like this a lot better, but maybe I can nudge ChatGPT in the direction of something more akin to \x, y -> x + y, to remove even more characters.

This is interesting. I haven’t even considered this syntax, but it surprisingly works! Let’s keep going and add some more nontypical features.

The provided code sample isn’t a very useful one, but it does demonstrate that the AI understands the concept it just designed. squared is returned from the block and thus from the lambda.

It looks a bit too easy though since so, so many languages use this syntax already.

Not a particularly exciting example once again, but technically correct. ChatGPT also goes on about the actual code, explaining what each line does, further cementing the idea that it does actually know what it’s doing — at least so far.

Every language needs some form of conditional execution. Let’s add that next.

What’s interesting is that the AI now combines multiple constructs that I defined and fine-tuned. It still remembers that the strings in my language are delimited by `.

Also, don’t mind that according to the AI, 0 is negative.

One problem from a design standpoint is that the : operator can show up in both the ternary operator and the lambda expression. This time, I will tell ChatGPT directly what needs to change and how.

Very easy. Since we have conditional execution now, I can ask the AI to write a non-trivial program in my language.

Isn’t this something! Let’s go further. It’s pretty embarrassing for a language not to have a looping construct.

Novel approach! Ignoring a typical for function, like I asked it to. It’s not very ergonomic though, so maybe we could dial it back a little.

I have to say I was stumped at how easy it was to convey what I meant. Now to write a traditional for loop,

for (int i = from; i < to; i += step)

we’re gonna need something that plays well with the map statement.

As far as my limited knowledge goes, this particular syntax isn’t especially popular. I did have to press Try Again a couple of times first though.

The AI was a bit hesitant on whether the range was inclusive or exclusive later on, but overall it was impressive.

Let’s see if it can implement the Fibonacci sequence once again, using the newly learned constructs.

The AI impressively inlined the map callback instead of defining it as a separate variable, for the first time.

There is also some redundant code, but we can let it slide.

At that point, the AI started losing it. It would frequently forget what constructs I have defined even if I stressed that it must not use any constructs from other languages.

I had to remind it exactly which construct to use. It also forgot that my language used then else instead of ? :.

What’s crazy is that it has actually transformed the code so that the logic for numbers higher than 0 is contained in the else part of the ternary operator.

Anyway, it started losing coherence after this point. As one last effort, I asked it to evaluate and explain a custom function I wrote in the language.

Given a number, the function creates an array of subsequent integers up to that number and then returns an array which represents a simple integration of that array.

Folks, we are .


Thanks for reading.

Subscribe to my newsletter

infrequent, high quality emails, opt out anytime
Thank you!

HI, YOU’VE REACHED
jude hunter
OPEN TO WORK
An advocate of free-as-in-freedom software and an active social progressivist in dire need of building empowering solutions.
LEAVE A MESSAGE AT THE TONE
Avatar photo of the blog post author Jude Hunter