Message Boards Message Boards

0
|
4277 Views
|
7 Replies
|
5 Total Likes
View groups...
Share
Share this post:

[?] Understand sequence behaviour?

Posted 7 years ago

Mathematica 11.0.1.0, Windows 64 bit

Can somebody explain why in the first example "Sequence" behaves as expected, whereas in the second we have an error:

First example:

m = {{1, 2}, {3, 4}};
m[[All, 2]] = Sequence[];
mm[[2]] = Sequence[];

Second example:

m = {{1, 2}, {3, 4}};
m[[2]] = Sequence[];
m[[All, 2]] = Sequence[];
POSTED BY: Daniel Huber
7 Replies

Interesting! So Sequence[] is basically equivalent to Nothing ?!?

POSTED BY: Henrik Schachner
notHere[Sequence[], Nothing]

Nothing only vanishes from Lists and is not affected by e.g. SequenceHold.

POSTED BY: Kuba Podkalicki

Here is an extended discussion:

POSTED BY: Kuba Podkalicki

It is an artifact of how Sequence is implemented.

m = {{1, 2}, {3, 4}};                                                      
m[[2]] = Sequence[];                                                       

In[12]:= ??m                                                                        
(*Global`m

m = {{1, 2}, Sequence[]} *)

Resetting m (e.g. m=m as @Sander showed)forces the Sequence[] to disappear.

POSTED BY: Daniel Lichtblau

I was trying to show this using Hold(All)(Complete), SequenceHold or HoldForm et cetera, but couldn't... didn't think of using Definition...

POSTED BY: Sander Huisman

FYI, OwnValues[ m ] would do too.

POSTED BY: Kuba Podkalicki

Strange indeed! However,

m = {{1, 2}, {3, 4}, {5, 6}};
m
m[[2]] = Sequence[];
m = m
m[[All, 2]] = Sequence[];
m

does work! It think it is due to that m is stored like:

{{1,2},Sequence[]}

Such that there is no second element in the second element. by doing m = m you 'evaluate' the Sequence. Might be the intended behavior or not, I almost never use Sequence in this way...

I would suggest using Drop, which is intended to remove elements, columns, rows, et cetera...

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract