Message Boards Message Boards

0
|
5929 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Mystery regarding use of Sequence function ...

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}

True

This doesn't work ...

Or[Sequence @@ {False, True}]

(out) Sequence[False, True]

This works ...

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

True

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

Thank you.

Attachments:
POSTED BY: Mark Tuttle
2 Replies

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

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