Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a module created which makes what I want, but at the end there are {NULL, NULL, NULL}. Why that? How can I prevent this NULL list?

 modrun = 0;
 myfn[a_, b_, c_, d_] := Module[{},
 Print[a, " : ", b, " : ", c, " : ", d, " @ ", modrun++];
 ];
 myfn @@@ {{1, 2, 3, 4}, {10, 20, 30, 40}, {100, 200, 300, 400}}

 OUTPUT:
 SequenceForm[1, " : ", 2, " : ", 3, " : ", 4, " @ ", 14]
 SequenceForm[10, " : ", 20, " : ", 30, " : ", 40, " @ ", 15]
 SequenceForm[100, " : ", 200, " : ", 300, " : ", 400, " @ ", 16]
 {Null, Null, Null}
share|improve this question
6  
You get the output you report because Print returns Null and Module returns the result of the last expression evaluated in its body. –  m_goldberg Jun 25 '13 at 18:24
    
While Print does return Null, in your code it is followed by a ;. There is no expression after ;, which is interpreted as the expression Null. This is the Null that is returned by Module (and myfn). See this answer for more. So don't use ; on the last expression in a Module (and perhaps don't end with Print). –  Michael E2 Jun 25 '13 at 19:51
    
please see this question and the answer i posted there –  amr Jun 25 '13 at 20:01
add comment

closed as off-topic by m_goldberg, Jens, Michael E2, Yves Klett, rm -rf Jun 27 '13 at 3:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 6 down vote accepted

Of course regardless of what you do with the module , @@@ is going to return a list of something. The answer to the question "How can I prevent this NULL list?" is very simply put a semicolon at the end.

myfn @@@ {{1, 2, 3, 4}, {10, 20, 30, 40}, {100, 200, 300, 400}};
                                                               ^  
share|improve this answer
    
Thanks a lot! NOW I got it –  Walter Schrabmair Jun 25 '13 at 20:30
add comment

The ; separating expressions is transformed into a CompoundExpression. So your Module reads:

modrun = 0;
myfn[a_, b_, c_, d_] := CompoundExpression[
  Module[{},
   CompoundExpression[
    Print[a, " : ", b, " : ", c, " : ", d, " @ ", modrun++], Null]
   ], Null]

Which returns Null every time it is evaluated.

share|improve this answer
    
Note the second ; –  Sjoerd C. de Vries Jun 25 '13 at 21:24
    
@SjoerdC.deVries, thanks, fixed. –  user21 Jun 26 '13 at 6:03
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.