Convert Code to Another Language
Line-by-line translation gives you code that looks foreign in the new language. This prompt asks for idiomatic code and lists where the two languages behave differently.
Works with Claude, ChatGPT and Gemini3 fields
Convert this Python code to idiomatic Go:
```
def chunks(xs, n):
return [xs[i:i+n] for i in range(0, len(xs), n)]
```
Keep the behaviour identical. Use Go conventions for naming, errors and types rather than copying Python style.
After the code, list any place where the two languages behave differently (integer division, nil/None, slicing, errors) and how you handled it.
Everything you type stays in your browser. Remove passwords, keys and personal data before pasting anything into an AI tool.
Why this prompt is written this way
- Idiomatic, not literal. Code that follows the target language's style is easier to maintain.
- Behaviour stays. The same results matter more than the same shape.
- Differences listed. Edge cases like slicing past the end behave differently between languages.
Example answer
Illustrative and shortened, to show the shape of a good answer. Real answers vary by model.
func Chunks[T any](xs []T, n int) [][]T { ... }
Difference: Python slicing past the end is safe; in Go the end index is clamped with min(i+n, len(xs)).
Tips
- Say which version of the target language you use.
- Ask for tests in the target language to check the translation.
How to use it
- Replace the example values with your own. The prompt on the right updates as you type.
- Press Copy prompt and paste it into any AI chat, or open it straight in Claude or ChatGPT.
- Save it as prompt.md if you want to reuse it.