Note
If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.
Context
Context
I'm writing a function that look something like:
triDiagonalQ[mat_] := MapIndexed[ #1 == 0 || Abs[#2[[1]]-#2[[2]]] <= 1 &, mat, {2}] // Flatten // And @@ # & Now, things like #2[[1]], #2[[2]] is#2[[1]] and #2[[2]] are somewhat hard to read. I'd prefer to do something like:
triDiagonalQ[mat_] := MapIndexed[ #1 == 0 || Abs[i-j] <= 1 &, mat, {2}] // Flatten // And @@ # & (* with a {i, j} <- #2 somewhere *) Question
Question
Is there someway to do something like destructuring"destructuring" in MathematicaMathematica?
Thanks!
Edit:
WhatThe following links convey what I have in mind formean by "destructuring":
- http://clojure.org/special_forms
- http://java.dzone.com/articles/clojure-destructuring
- http://blog.jayfields.com/2010/07/clojure-destructuring.html
(These have nothing to do with Mathematica;Mathematica; they're posted mainly to demonstrateddemonstrate what is meant by "destructuring")