Skip to content

Commit ffeb800

Browse files
committed
AutomaticUnits is working in Mathematica 9 again (was broken by M10 compatibility changes).
1 parent 32539a1 commit ffeb800

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

AutomaticUnits/AutomaticUnits.m

+11-7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676

7777
Begin["`private`"];
7878

79+
If[$VersionNumber > 9.,
80+
dispatchify[dispatch_Dispatch]:=Normal[dispatch],
81+
dispatchify[dispatch_Dispatch]:=dispatch[[1]]
82+
];
83+
7984
(*Lists that store the unit coversion rules*)
8085
$ToFundamental={};
8186
$ExactUnitRules={};
@@ -103,7 +108,7 @@
103108
OptionValue[UsageMessage]
104109
];
105110
Which[
106-
Head[$ToFundamental]===Dispatch,existingrules=Normal[$ToFundamental];dispatchedq=True,
111+
Head[$ToFundamental]===Dispatch,existingrules=dispatchify[$ToFundamental];dispatchedq=True,
107112
Head[$ToFundamental]===List,existingrules=$ToFundamental,
108113
True,existingrules={}];
109114
(*If unit name is already decalared, issue warning and over-write definition*)
@@ -122,7 +127,7 @@
122127
(*If relationship is exact, store it explicitely *)
123128
If[Precision[val[[1]]]===Infinity,
124129
Which[
125-
Head[$ExactUnitRules]===Dispatch,existingexactrules=Normal[$ExactUnitRules];dispatchedq=True,
130+
Head[$ExactUnitRules]===Dispatch,existingexactrules=dispatchify[$ExactUnitRules];dispatchedq=True,
126131
Head[$ExactUnitRules]===List,existingexactrules=$ExactUnitRules,
127132
True,existingrules={}
128133
];
@@ -155,9 +160,9 @@
155160
application of Dispatch by doing it just once at the end. This gives much faster package initialization*)
156161
FastGroupDeclareUnit[expr_]:=Block[{$UnitInitialization=True,newfund,newexact,junk},
157162
(*Make sure that the tables are plain lists*)
158-
If[Head[$ToFundamental]===Dispatch,$ToFundamental=Normal[$ToFundamental]];
163+
If[Head[$ToFundamental]===Dispatch,$ToFundamental=dispatchify[$ToFundamental]];
159164
If[Head[$ToFundamental]===List,$ToFundamental={}];
160-
If[Head[$ExactUnitRules]===Dispatch,$ExactUnitRules=Normal[$ExactUnitRules]];
165+
If[Head[$ExactUnitRules]===Dispatch,$ExactUnitRules=dispatchify[$ExactUnitRules]];
161166
If[Head[$ExactUnitRules]===List,$ExactUnitRules={}];
162167

163168
(*expr should be a CompoundExpression of DeclareUnit expressions*)
@@ -1131,15 +1136,14 @@
11311136
NotebookWrite[InputNotebook[], ToBoxes[#,
11321137
If[tradform,TraditionalForm,StandardForm]]],Appearance -> "Palette"],
11331138
TraditionalForm[#]] &
1134-
1139+
11351140
End[];
11361141

1137-
Quiet[
1142+
11381143
DeclareUnit["Molecule"];
11391144
DeclareUnit["Mole",Unit[6.0221415`*^23,"Molecule"]];
11401145
AutomaticUnits`private`SIPrefixify["Mole","Substance amount","mol"];
11411146
UnitSet["SI"]=Join[UnitSet["SI"]/.Meter^3->Liter,{Millimole,Millimole Liter^-1}];
1142-
]
11431147

11441148
EndPackage[]
11451149

0 commit comments

Comments
 (0)