in reply to Re^2: nested tabular ternary
in thread nested tabular ternary

I don't see the "table" and it looks like you just scattered your code all across the page, as if it were scrambled.

No wait.. it looks like a bad translation of the original lisp into formatted perl. It really does look like lisp indenting conventions were attempting to be followed in your example.

(if (= major-length 4800) 18 (if (= major-length 8552) (if (= val 4) 33 (if (= val 1) 18 (error "not handled"))) (error "not handled")))

Here's a nicer lisp version of the same thing. It's got more in common with what I originally suggested than does what you alleged TheDamian recommended.

(cond ((= major-length 4800) 18) ((= major-length 8552) (cond ((= val 4) 33) ((= val 1) 18) (error "not handled"))) (error "not handled"))

The above is just a more verbose version of the following. This is getting to be seriously terse to the point that there's almost not enough whitespace in there. I'm just following standard indenting rules so this is just stock lisp.

(ecase major-length (4800 18) (8552 (ecase var (4 33) (1 18))))

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^4: nested tabular ternary
by McDarren (Abbot) on Apr 11, 2006 at 02:35 UTC
    I don't see the "table" and it looks like you just scattered your code all across the page, as if it were scrambled.
    hmm... maybe that has something to do with how it renders in your browser vs. mine, although as it's enclosed in code tags I wouldn't have thought so. But anyway, the idea is that the ":" and "?" parts of the ternary line up vertically - producing the table effect - hence the term "tabular ternary". Have you seen the examples in PBP that I referred to?
    Here's a nicer lisp version of the same thing.
    I've never used lisp, so I can't comment on that :)
    It's got more in common with what I originally suggested than does what you alleged TheDamian recommended.
    um, I'm not sure that I alleged anything. All I did was refer to two of the practices that he recommends in his book PBP, namely:
    • "When producing a value, use tabular ternaries" (pp. 121-123), and
    • "Break long expressions before an operator" (pp. 27-29)

    But anyway, as I said - my comments weren't meant as a critisism, but rather a commentary on style.

    Cheers,
    Darren :)

      I copied and pasted your code, making sure that I'd copied over spaces instead of tabs. Nothing in your code lines up. I'm using Firefox on Linux, something I assume is pretty standard. If you meant something that was organized, what you posted wasn't it. Maybe you had tabs on your end that didn't get conveyed to perlmonks.org

      $result = ($major_length == 4800) ? 18 : ($major_length == 8552) ? ($val == 4 ? 33 : $val == 1 + ? 18 : die "not hand +led") : die "not handled";

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊