Hacker News new | ask | show | jobs
by krcz 2314 days ago
On the other hand most spoken languages use similar underlying concepts (with some exceptions, e.g. translation to language without subjective direction terms like "left" or "right" might be tricky). Programming languages can have completely different execution models, especially when you compare ones between paradigms. Translating imperative for loop into map/filter/fold chain in functional language would have to be very non-local.
1 comments

Yes it would probably produce a lot of unidiomatic code (see for example c2rust [1], which generates semantically equivalent Rust code, but with raw pointers and unsafe everywhere). In the worst case you could even just emulate the origin language in the target language, everything is turing complete after all.

With enough effort and smart transformation passes however, I think you could come pretty close to something resembling "native" code. It might not always be worth it to spend that development time though.

[1] https://c2rust.com/