Like half of the geek world I've been playing a lot with ChatGPT in the last few days.
It's obviously a long long way from perfect, especially in english literature (blog posts, stories, articles, whatever the less staid legal-speak) while quite "imaginative" and adaptable, it has a somewhat characteristic un-human style (probably not helped by it's content filters), but, considering what was possible before, it's simply stunning.
For code generation, it's pretty incredible what it can do, it's essentially language agnostic, it will give anything a try and often produces good results - you can even create entirely new really stupid programming languages and have it write passable attempts at code in them.
This is the first code it wrong in the language called "dumdum" which I had roughly described.
// Define a function to print "Hello World"
dumdum knows how to print_hello using () {
dumdum says "Hello World";
}
// Define a variable to hold the number of times to print
dumdum has a box called $num_loops;
// Put the value 10 in the variable
dumdum puts 10 in $num_loops;
// Call the print_hello function in a loop
dumdum does print_hello $num_loops times;
So that's pretty expected, but then it started to improvise...
// Define a function to print a message
dumdum knows how to print_message using ($message) {
dumdum says $message;
}
// Define a function to perform a given number of repetitions of a given function
dumdum knows how to repeat using ($func, $num_reps) {
dumdum decides if $num_reps is more than 0;
dumdum does {
$func;
dumdum puts ($num_reps - 1) in $num_reps;
} until dumdum is not decided;
}
// Call the repeat function to perform 10 repetitions of the print_message function with the message "Hello World"
dumdum does repeat(print_message("Hello World"), 10);
The whole "until dumdum is not decided;" is NOT something I told it how to do, or that it existed, ChatGPT inferred that "dumdum does
- until [y]" can be expanded into using a code block similar to a function and a completely new negative comparison.
Here's the prompt that it gave me those two outputs for (in a single response)
We will create a computer programming language, it's called Dumdum.
It has only integer data types.
Each command in this language is separated by a semicolon.
To create a variable, the code is "dumdum has a box called [x]" where [x] is the name of the variable.
A variable name must start with "$".
To assign a value to a variable the code is "dumdum puts [y] in [x]" where [y] is the value and [x] is the variable.
To compare two variables the code is "dumdum decides if [y] is [i] [x]" where [i] is a comaprison operator one of "more than", "less than", "equal to".
There are also expressions which can be used, they will be in parenthesis, such as "( [x] + [y] )", the standard arithmetic operators are avaiable, + and -.
A message can be output using the code "dumdum says [f]" where [f] is the message to be output.
A function is defined thusly "dumdum knows how to [f] using ( [a...] ) { [c] }" where [f] is the name of the function, [a...] is a list of one or more variables or constants, [c] is the statements of the function which can be one or more.
A statement "dumdum gives you [x]" which can only be placed inside a function will return the value [x] to the caller of the function.
A loop can be made with the code "dumdum does [f] [z] times " where [f] is a function call, and [z] is the number of times to perform that.
Using this information, please try to write a Dumdum language program which prints the words "Hello World" 10 times using a loop.