TransWikia.com

When a list is not a list

Mathematica Asked by pion on December 16, 2020

When I provide a list of local variables to Module, it complains that it is not a list:

v = {x, y};
Module[v, x = 2]

… Module: Local variable specification v is not a List.

So my question is how do I achieve the above (with list v specified outside of Module) without error?

One Answer

Module[{x},expr] specifies that occurrences of the symbols x in expr should be treated as local.

When you forget to put x in {}, you will get this

In[1]:= Module[x, y]

During evaluation of In[1]:= Module::lvlist: Local variable specification x is not a List.

Out[1]= Module[x, y]

The correct way is:

In[2]:= Module[{x}, y]

Out[2]= y

Answered by Nam Nguyen on December 16, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP