Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Now show the same tree for a ruby block, a Java inner class, a C# lambda and how they're all the same.

Except they're not.

Only the simplest ASTs are directly translatable. Language semantics differ wildly when you get into higher level constructs. Not even Lisp is able to help you, as that just changes the problem from one of syntactic representation into one of library implementation.



Language semantics differ, full stop. Say you have x = 2147483647:

    x + 1 => -2147483648 (Java)
    x + 1 => Undefined behaviour (C, assuming int32_t and various things about the implementation)
    (1+ x) => 2147483648.0 (Emacs Lisp)
    (1+ x) => 2147483648 (Common Lisp)
    x + 1 => x + 1 (Prolog, using some interpretive license)


That's for syntax. Also, for semantics, how do you translate C's pointer arithmetic in Java?


All programming languages deal with pointers at some point or another, so it's just a matter of finding the GCD.

At least that's what I think this is about, and Lisp is a good GCD.


That's not really a critique of the author's main point, I think. Of course you can't directly translate between semantically different features, but the OP's point was about semantically identical programs, and how different syntaxes distract from that.

That said, I think it's possible to invent a language in which all the things you mention can be expressed and at least compared. I'll do my best to do it myself if no one beats me to it. Any language with closures is close. Java inner classes and (AFAIK) C# lambdas practically are clsoures. If the only thing ruby blocks add is that returns and similar statements affect the block-creating function, that can be simulated with exceptions.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: