Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ruby Block Styling (Homoiconic/Reg Braithewaite) (github.com/raganwald)
13 points by angelbob on Dec 9, 2009 | hide | past | favorite | 2 comments


Ok, I was surprised to see this submitted to HN. In an effort to drag it into something that gratifies my intellectual curiosity, forget what does or doesn't work in Ruby for a moment and ask a question:

Why doesn't this work in every language?

In other words, if you have a construct for sequencing multiple statements (line breaks and semicolons in Ruby), and another construct for altering the order of evaluation (parentheses in Ruby and most languages), why don't they work together seamlessly? The surprising thing here is not that Ruby allows it, but that many other popular languages don't.


You can do it in C:

    #include <stdio.h>
    int main(void) {
        int a, b, c;
        int d = (a = 1, b = 2, c = 3, a + b + c);
        int e = (({int f = 1; e = f;}), e += 1);
    
        printf("d is %d \n", d);
        printf("e is %d \n", e);
    
        return 0;
    }
Edit: I just realized how strange the line e = ... is. I wonder if it yields different results with different compilers.




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

Search: