Hacker News new | comments | show | ask | jobs | submit login

Actually, I think defining new operators is impossible to do even this cleanly in Ruby. It's emphatically not well suited to this particular kind of metaprogramming. You can override lots of operators and define methods that read kind of like language keywords, but AFAIK you can't define new infix operators without flat-out hacking the parser in C.



Defining infix operators in Perl6 is very straightforward.

For eg:

    sub infix:<.oO>($name, $thought) {  
        say "$name thinks $thought"
    }

    "szabgab" .oO "Perl 6 is cool";
ref: http://news.ycombinator.com/item?id=1607254




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: