Skip to main content
Notice removed Reward existing answer by CommunityBot
Bounty Ended with jVincent's answer chosen by CommunityBot
Notice added Reward existing answer by user1602
Bounty Started worth 200 reputation by CommunityBot
Tweeted twitter.com/#!/StackMma/status/225041400490758144
deleted 70 characters in body; edited tags
Source Link
rm -rf
  • 89.8k
  • 21
  • 303
  • 498

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":

(These have nothing to do with Mathematica;Mathematica; they're posted mainly to demonstrateddemonstrate what is meant by "destructuring")

Note

If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.

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 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

Is there someway to do something like destructuring in Mathematica?

Thanks!

Edit:

What I have in mind for "destructuring"

(These have nothing to do with Mathematica; they're posted mainly to demonstrated what is meant by "destructuring")

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]] 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

Is there someway to do something like "destructuring" in Mathematica?

 

The following links convey what I mean by "destructuring":

(These have nothing to do with Mathematica; they're posted mainly to demonstrate what is meant by "destructuring")

added 342 characters in body
Source Link
user1602
user1602

Note

If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.

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 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

Is there someway to do something like destructuring in Mathematica?

Thanks!

Edit:

What I have in mind for "destructuring"

(These have nothing to do with Mathematica; they're posted mainly to demonstrated what is meant by "destructuring")

Note

If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.

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 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

Is there someway to do something like destructuring in Mathematica?

Thanks!

Note

If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.

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 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

Is there someway to do something like destructuring in Mathematica?

Thanks!

Edit:

What I have in mind for "destructuring"

(These have nothing to do with Mathematica; they're posted mainly to demonstrated what is meant by "destructuring")

added 126 characters in body
Source Link
user1602
user1602

Note

If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.

Context

I'm writing a function that look something like:

triDiagonalQ[mat_] := MapIndexed[ ...#1 #2[[1]]== #2[[2]]0 || Abs[#2[[1]]-#2[[2]]] <= 1 &, lstmat, {2}] // Flatten // And @@ # & 

Now, things like #2[[1]], #2[[2]] is somewhat hard to read. I'd prefer to do something like:

triDiagonalQ[mat_] := MapIndexed[ ...#1 i== ..0 j|| Abs[i-j] <= 1 &, lstmat, {2}] // Flatten // And @@ # & (* with a {i, j} <- #2 somewhere *) 

Question

Is there someway to do something like destructuring in Mathematica?

Thanks!

Note

If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.

Context

I'm writing a function that look something like:

MapIndexed[ ... #2[[1]] #2[[2]] , lst, {2}] 

Now, things like #2[[1]], #2[[2]] is somewhat hard to read. I'd prefer to do something like:

MapIndexed[ ... i .. j , lst, {2}] (* with a {i,j} <- #2 somewhere *) 

Question

Is there someway to do something like destructuring in Mathematica?

Thanks!

Note

If my style is wrong (i.e. not Mathematica way), please let me know. I'm happy to adjust.

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 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

Is there someway to do something like destructuring in Mathematica?

Thanks!

Source Link
user1602
user1602
Loading