1
$\begingroup$

Spelunking the Export function, I stumbled upon the following definition:

Export[channel_File, expr_, format_List, opts___?OptionQ] := 
  Block[{}, 
    Message[Export::chtype, channel];
    $Failed
  ]

What is the point of using the Block with an empty list of bindings? How is it different from just writing the body of the Block directly?

$\endgroup$
  • 1
    $\begingroup$ possible duplicate: Why modules with no variables? and links therein. $\endgroup$ – AccidentalFourierTransform Aug 13 '18 at 17:53
  • $\begingroup$ @AccidentalFourierTransform: possibly, thanks. Not sure if Block has some subtleties though. $\endgroup$ – kkm Aug 13 '18 at 17:58
  • 1
    $\begingroup$ Would the downvoter care to explain the downvote please? This has been a very user friendly community... I have been using MMA for years, and do not believe this question is so obviously unwarranted as to not even explain why it is a wrong question to ask, really. $\endgroup$ – kkm Aug 13 '18 at 18:00
  • 1
    $\begingroup$ Well, the difference between lexical and dynamic scoping only matters if you have local variables, and the point here is that you don't. There is no difference between Block[{}, body] and Module[{}, body] because of this, they both return body. Also, I would think that a user like Leonid Shifrin, who answered the other question, and who if anybody would know, would have mentioned if there were uses cases for Block[{}, body] in his answer, he wouldn't just have skipped it. I think the author of Export simply prefers Block to Module with or without variables. It's his "default". $\endgroup$ – C. E. Aug 13 '18 at 18:34
  • 1
    $\begingroup$ @C.E. Thanks, I agree, this is an entirely convincing case of an acceptable ad verecundiam Leonidi! :) I'm accepting my question as a duplicate (there is a new button for that, never seen it before). $\endgroup$ – kkm Aug 13 '18 at 18:47