Good question. Let's try it. Here is some Lisp code I know cannot be duplicated as-is in C:
(defun num-atoms(list)
(cond
((null list) 0)
((atom list) 1)
(t (+ (num-atoms (car list)) (num-atoms (cdr list))))))
And here's the C code that ChatGPT created from it.
#include <stdio.h>
#include <stdlib.h>
typedef struct list_node {
int data;
struct list_node *next;
} list_node;
int num_atoms(list_node *list) {
if (list == NULL) {
return 0;
} else if (list->next == NULL) {
return 1;
} else {
return num_atoms(list->next) + num_atoms(list->next->next);
}
}
int main() {
list_node \*list = NULL;
printf("%d\n", num_atoms(list));
return 0;
}
ChatGPT provided great writeup about what it's supposedly doing, and quite brilliantly states the following:
"Note that this implementation of the num_atoms function is not equivalent to the original Lisp function, as it does not correctly handle the (atom list) case. In C, it is not possible to directly check whether a value is an atom, as atoms are not a fundamental concept in C. To properly implement the num_atoms function in C, a more detailed specification of what is meant by an "atom" would be needed."
I then asked ChatGPT: "Make a function in C that duplicates (atom list) from Lisp" since that was the recommendation.
I like to think it got impatient with me badgering it about this subject, because the response starts with "As mentioned earlier, atoms are not a fundamental concept in C, so it is not possible to directly implement a function that duplicates the behavior of (atom list) in Lisp." But it then followed up with C code that approximates it (by simply checking if something is a list or not), and then explains why it is still not exactly the same as Lisp's implementation, and that it won't work correctly in every case as it would under Lisp.
It then ended with "The definition of an atom and the way it is identified may vary depending on the specific requirements of the problem being solved."
This could be quite educational. I really expected it to "make shit up," but it was pretty spot on.