ChatGTP coding like Marcus Aurelius

Bob Donderwinkel
4 min readApr 15, 2023

--

DALL·E: An image of the bronze equestrian statue of Marcus Aurelius who is holding a laptop in his left arm

On the topic of AI experimenting, here is an attempt to see if ChatGTP can imagine a new paragraph in the book of Meditations from our favourite Roman emperor and philosopher Marcus Aurelius. And follow that up by turning that paragraph into code..

ME: Can you give me an example of a paragraph in the book Meditations from Marcus Aurelius?

GPT-3.5: Certainly! Here’s an example of a paragraph from the book “Meditations” by Marcus Aurelius:

“Think of yourself as dead. You have lived your life. Now, take what’s left and live it properly. What doesn’t transmit light creates its own darkness. And if you can’t go through an obstacle, go around it. Don’t insist on being able to do something; adapt yourself to the circumstances surrounding you. What stands in the way becomes the way.”

In this paragraph, Marcus Aurelius is urging the reader to adopt a certain mindset: one of detachment from the past and acceptance of the present, as well as a willingness to adapt and overcome obstacles. He suggests that focusing on negative thoughts and actions will only lead to darkness, while embracing challenges as opportunities for growth is the key to success. Overall, this paragraph encapsulates the Stoic philosophy that is central to “Meditations.”

ME: Could you generate a similar paragraph in the style of Marcus Aurelius which does not appear in the book of Meditations?

GPT-3.5: Certainly! Here’s a paragraph in the style of Marcus Aurelius:

“Life is fleeting, like a river rushing toward its inevitable end. We cannot control the flow of the river, but we can choose how we navigate it. Do not let external events determine your course; steer your own ship with wisdom and courage. Remember that the world is constantly changing, and that which once seemed insurmountable may now be conquered. Let go of attachments to material possessions and fleeting pleasures, for they will only weigh you down. Embrace the present moment, for it is all we truly have. In the face of adversity, rise like a phoenix from the ashes and let your spirit soar.”

ME: Could you give a shorter example in the style of Marcus Aurelius which does not appear in the book of Meditations?

GPT-3.5: Certainly, here’s a shorter example:

“Life is a journey, and we are all travelers on this road. Do not be weighed down by the past or anxious about the future. Stay focused on the present and the path ahead. Remember that true happiness comes not from external circumstances, but from within. Cultivate a calm mind and a grateful heart, and you will find peace along the way.”

ME: Could you generate some javascript code which reflects the same sentiment as in the paragraph above?

GPT-3.5: Sure! Here’s some JavaScript code that reflects the sentiment of the paragraph:

// Life is a journey, and we are all travelers on this road.
const journey = () => {
// Do not be weighed down by the past or anxious about the future.
let past = null;
let future = null;

// Stay focused on the present and the path ahead.
const present = new Date();
const path = 'stay on track';

// Remember that true happiness comes not from external circumstances, but from within.
const happiness = () => {
const calmMind = true;
const gratefulHeart = true;
return calmMind && gratefulHeart;
}

// Cultivate a calm mind and a grateful heart, and you will find peace along the way.
if (happiness()) {
const peace = true;
return `I am on a journey, staying on the path, and finding peace along the way.`;
}
}

console.log(journey()); // Output: I am on a journey, staying on the path, and finding peace along the way.

GPT-3.5: This code creates a function called journey which reflects the sentiment of the paragraph. The function creates variables for the past, future, present, and path, and checks if the user is cultivating a calm mind and a grateful heart to find true happiness. Finally, the function returns a message that the user is on a journey, staying on the path, and finding peace along the way.

ME: Could you write some unit tests which test the behaviour of the code above?

GPT-3.5: Sure! Here are some unit tests for the journey function in the JavaScript code above:

// Import the assert module
const assert = require('assert');

// Import the journey function
const journey = require('./journey');

// Test the journey function
describe('journey', () => {
it('should return a message that reflects the sentiment of the paragraph', () => {
assert.strictEqual(journey(), 'I am on a journey, staying on the path, and finding peace along the way.');
});

it('should return a string', () => {
assert.strictEqual(typeof journey(), 'string');
});

it('should have a present date object', () => {
assert.strictEqual(journey().includes(new Date().getFullYear()), true);
});

it('should have a path', () => {
assert.strictEqual(journey().includes('staying on the path'), true);
});

it('should return the message with true happiness', () => {
assert.strictEqual(journey().includes('finding peace along the way.'), true);
});

it('should return a message with the word "journey"', () => {
assert.strictEqual(journey().includes('journey'), true);
});
});

GPT-3.5: These tests check that the journey function returns a message that reflects the sentiment of the paragraph, returns a string, has a present date object, has a path, returns the message with true happiness, and contains the word "journey". The tests help ensure that the function behaves as expected and that any changes made to the function in the future will not break its intended behavior.

So what this little experiment tell us? The generated code is pretty pointless of course, and apparently I have too much free time on my hands. But this is another nice example of a Large Language Model like ChatGTP treating code and ordinary text in the same way. And that makes me wonder what possible role code sentiment analysis might play, for example in the areas of documentation and testing 🤔

Happy coding!

--

--