2

I try to become familiar with the Modules and struggle :-(

I wrote a very very pretty example but got an exception:

Analyse [data_, name_] :=
 Module [{};
  Text[Row[{"data is:", data}]];
  Text[Row[{"name is:" , name}]];
  ]

call for:

Analyse [1, "Paul"]

Result:

Module::argmu: Module called with 1 argument; 2 or more arguments are expected. >>

Module[{}; Text[
 Row[{"data is:", 1}]]; Text[
  Row[{"name is:", "Paul"}]];]

So what is missing. I dont see the 1(!) argument, I have two. But there must be an issue for

thx

gwr
  • 13,452
  • 2
  • 47
  • 78

2 Answers2

3

To understand the issue, remember that everything in Mathematica is an expression:

head[ e1, e2, ... ]

The ; is a shortcut for CompoundExpression:

CompoundExpression[ expr1, expr2] === (expr1; expr2)

(* True *)

You can see what is happening by using FullForm:

Analyse [data_, name_] := Module [{};
  Text[Row[{"data is:", data}]];
  Text[Row[{"name is:" , name}]];
] // FullForm

Testing your function again reveals an error message and a full form display of the specific DownValue for Analyse[] (which I have commented and reformatted for clarity):

Analyse[ 1, "Paul" ]

Module::argmu: Module called with 1 argument; 2 or more arguments are expected.

Module[
  (* argument 1 *) 
  CompoundExpression[
     List[],
     Text[Row[List["data is:",1]]],
     Text[Row[List["name is:","Paul"]]],
     Null
   ]

   (* slot for missing argmument 2 *)

]

So, your two arguments have been well taken, but the Moduleis only having one argument, which is the CompoundExpression. Module does take two arguments:

Module[ {vars}, body ]

So simply drop the last semicolon (because you do not want Null being the last expression in a compound expression and thus have no output) and replace all other semicolons by , as shown by e.doroskevic.

gwr
  • 13,452
  • 2
  • 47
  • 78
  • @MelanieGerster By now it should be clear why you will need ; for the body part of Module: Module only takes two arguments thus a whole bunch of expressions need to be given as one CompoundExpression. – gwr Aug 18 '16 at 09:01
  • 1
    Since OP is not familiar with the proper usage of Module and seems to be using it without any local variables only as a grouping construct, perhaps worth mentioning as well that simply replacing Module with CompoundExpression for this application is probably the easiest fix. – Oleksandr R. Aug 18 '16 at 10:09
1

Description

The issue you've experienced is due to semantics applied. Please see a working example below. Also, see reference provided.

Example

Analyse[data_, name_] := Module[
  {},
  {Text[Row[{"data is:", data}]],Text[Row[{"name is:", name}]]}
]

If you want to wrap the above into a column structure, simply add Column to the List containing the Row data. Like below

...
Column @ {Text[Row[{"data is:", data}]],Text[Row[{"name is:", name}]]}
...

Reference

Module

e.doroskevic
  • 5,959
  • 1
  • 13
  • 32