(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 3606, 135] NotebookOptionsPosition[ 2950, 107] NotebookOutlinePosition[ 3232, 121] CellTagsIndexPosition[ 3189, 118] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell["Pattern programming in Mathematica", "Section"], Cell[CellGroupData[{ Cell["Debugging", "Title"], Cell["\<\ I like to set up an environment where I can easily debug different elements \ without changing too much code. Therefore my modules look like this:\ \>", "Text"], Cell[BoxData[ RowBox[{ RowBox[{"typicalFunction", "[", RowBox[{"a_", ",", "b_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"debug", "=", RowBox[{"MemberQ", "[", RowBox[{"debugModule", ",", "\"\\""}], "]"}]}], ",", "var1", ",", "var2"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"sample", " ", "code"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"var1", "=", "2"}], ";", RowBox[{"var2", "=", "3"}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"debugging", " ", "info"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"debug", ",", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", "var1"}], "]"}], ";"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"more", " ", "code"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "*", "var1"}], "+", RowBox[{"b", "*", "var2"}]}]}]}], "\[IndentingNewLine]", "]"}]}]], "Input"], Cell["\<\ This enables me to run the function with and without debugging information\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"debugModule", "=", RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"typicalFunction", "[", RowBox[{"1", ",", "2"}], "]"}]}], "Input"], Cell[BoxData["8"], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"debugModule", "=", RowBox[{"{", "\"\\"", "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"typicalFunction", "[", RowBox[{"1", ",", "2"}], "]"}]}], "Input"], Cell[BoxData[ InterpretationBox[ RowBox[{"\<\"var1=\"\>", "\[InvisibleSpace]", "2"}], SequenceForm["var1=", 2], Editable->False]], "Print"], Cell[BoxData["8"], "Output"] }, Open ]], Cell["\<\ So with a single global variable and this programming pattern, I can control \ the debugging display of all my modules.\ \>", "Text"] }, Open ]] }, FrontEndVersion->"6.0 for Microsoft Windows", WindowSize->{615, 750}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[568, 21, 53, 0, 71, "Section"], Cell[CellGroupData[{ Cell[646, 25, 26, 0, 57, "Title"], Cell[675, 27, 170, 4, 65, "Text"], Cell[848, 33, 1143, 31, 202, "Input"], Cell[1994, 66, 98, 2, 29, "Text"], Cell[CellGroupData[{ Cell[2117, 72, 190, 5, 62, "Input"], Cell[2310, 79, 28, 0, 41, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[2375, 84, 220, 6, 62, "Input"], Cell[2598, 92, 146, 4, 23, "Print"], Cell[2747, 98, 28, 0, 41, "Output"] }, Open ]], Cell[2790, 101, 144, 3, 47, "Text"] }, Open ]] } ] *) (* End of internal cache information *)