Group Abstract Group Abstract

Message Boards Message Boards

Mathematica Tetris

POSTED BY: Boris Faleichik
6 Replies
Posted 10 years ago

Tetris, so classical game! Yeasterday I saw a kid was playing Tetris 3D. It might be also be developed by Wolfram Language one day.

https://en.wikipedia.org/wiki/3D_Tetris enter image description here

POSTED BY: Frederick Wu
Posted 10 years ago

Nice, let me just point out something,

"Private`" vs "`Private`"

unless you really intend to do so, Begin["Private`"] should have an accent before Private - Begin["`Private`"].

Without it all those symbols are going to be created in Private` context instead of Tetris`Private` context. And you don't probably want this since it will happen for all packages which will then share symbols in Private`.

Take a look

BeginPackage["Tetris`"];

Begin["Private`"];
testSymbol`
End[];

Begin["`Private`"]; (* "correctly" *)
testSymbol2
End[]; 

EndPackage[];

Names["*`testSymbol*"]
 {"Private`testSymbol1", "Tetris`Private`testSymbol2", ...}

Why is this a problem?

Let's create two packages:

BeginPackage["MyPackage`"];    
showString;    
Begin["Private`"];

temp = "MyPackage";
showString[] := temp;

End[];    
EndPackage[];


BeginPackage["YourPackage`"];    
whatever;    
Begin["Private`"];

temp = "YourPackage";
whatever[] := "doesNotMatter";

End[];
EndPackage[];

showString[]

YourPackage (while expected is MyPackage, isn't it?)

POSTED BY: Kuba Podkalicki

Kuba, thank you for pointing out this mistake. And I really appreciate your nice explanation :)

POSTED BY: Boris Faleichik

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the top of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: EDITORIAL BOARD

WoW! great job! excellent!

First time I see someone that has ; at the start of a line! It looks a bit strange!

POSTED BY: Sander Huisman

Thank you, Sander. I agree this code formatting looks unusual, but quite recently I've found that it is convenient and more readable, especially for If[] statements with "Else" section.

POSTED BY: Boris Faleichik
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard