Message Boards Message Boards


Mystery regarding use of Sequence function ...

Posted 9 years ago
2 Replies
1 Total Likes

Because some Boolean functions work on Lists and others on argument lists only, I need to better understand the Sequence command for converting the former to the latter.

For example, why ... ?

I want to give Or a list of boolean literals.

This works ...

Or @@ {False, True}


This doesn't work ...

Or[Sequence @@ {False, True}]

(out) Sequence[False, True]

This works ...

Or[False, Sequence @@ {False, True}]


Why does the 3rd expression work when the 2nd does not?

Thank you.

POSTED BY: Mark Tuttle
2 Replies

Thank you!

As you imply, I need to learn much more about the "evaluation process."

For example, thanks to your advice re Trace I can see differences between what works and what doesn't, but still don't understand why.

I'll save that question and related exploration for another day.

-- Mark

POSTED BY: Mark Tuttle

The evaluation process can be tricky and is best studied with Trace.

In[2]:= Or[Sequence@@{False,True}]//Trace

Out[2]= {Or[Sequence@@{False,True}],{Sequence@@{False,True},HoldForm[False,True]},HoldForm[False,True]}

In[5]:= Or[False,Sequence@@{False,True}]//Trace

Out[5]= {False||Sequence@@{False,True},{Sequence@@{False,True},HoldForm[False,True]},Or[Sequence[False,True]],False||True,True}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract