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

I'm usually looking for two kinds of switching, most implementations support one of them. Switching on a list of conditions in priority order like CL's COND, and switching on a value.

Simply making the value optional and injecting it in specified conditions if present would allow using the same construct for both.

Note that this may well be possible in P6, most things are; but I have yet to come across and example of COND-behavior, they're all switching on values from what I can see.



Behold:

    switch (true) {
        case a > b: ...
        case isFullMoon(): ...
    }


Thanks, I have yet to come across anything that P6 doesn't have a feature for. The languages [0] I've designed so far don't even come close in complexity, and I'm still balancing the edge of my abilities to keep track of everything. If they manage to make that monster run reasonably correct and fast, I'm seriously impressed.

[0] https://github.com/codr7/g-fu/tree/master/v1


Well, that's not specifically Perl above―it should work in most languages with `switch`. It's also highly questionable to my taste, as I don't see why `if` wouldn't do. I've chastised a dude many a time for its use, but that was only one of his dubious choices in life, so...




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

Search: