I recently ran into a joke that got me thinking about the logic of a sentence.
Consider the joke:
A wife asks her husband, “Could you please go shopping for me and buy a carton of milk and if they have avocados, get 6.”
A short time later the husband comes back with 6 cartons of milk.
The wife asks him, “Why did you buy 6 cartons of milk?”
He replied, “They had avocados!”
I directly translated this into:
How the husband saw it
if ( shopping.has('avocados') ) husband.buy(6, 'milk')
How the wife saw it
husband.go.shopping() husband.buy(1, 'milk') husband.buy(6, 'avocados')
But after translating this into code I realised context was required to understand the code as a joke.
My question is how would you translate the joke so that the code did not need context to explain it was a joke? Is that even possible?