# Interpreter for Quantities without magnitude

When using a quantity interpreter on a unit without magnitude, the interpreter fails, but works fine on quantities with magnitudes.

Ex:

Interpreter["Quantity"]["meter"]


Out: ERROR

Interpreter["Quantity"]["1 meter"]


Out: 1m, as expected.

What I expect:

Interpreter["Quantity"]["meter"]


Out: m

I don't see why the interpreter won't do this. The only solution I can find for when I have a LIST of magnitude-less quantities is

table={"Meter","Feet","Second",etc.}
Interpreter["Quantity"][StringJoin["1 ", #] & /@ table]


But that's a silly workaround, and then I can't remove the 1.

Summary:

What I want: Given a list of (string) units, returns a list of those units in a computational format.

The problem: Using Interpreter["Quantity"]["Unit"] FAILS, while Interpreter["Quantity"]["1 Unit"] works. However, I just want to return "Unit", not "1 Unit".

P.S For anyone interested in my application, I need a list of all units in WL for a CompatibleUnit program I'm making.

So I have

table = Keys[QuantityUnitsPrivate\$UnitReplacementRules]
Interpreter["Quantity"][table]

• I am not sure that I understand, however, would Quantity["meter"] do what you want? Its FullForm is Quantity[None, "Meters"]. Notice however that "meter" is NOT present as a string in the table you generate at the end of your post; "Meters" can be found in there instead. – MarcoB Apr 27 '18 at 21:05
• Not sure if I understand either, so not sure if this does what you want, but Interpreter[Quantity["meter"]][[1, 2]] gives Meters, and the latter is in a computational format. E.g., if you set ans = Interpreter[Quantity["meter"]][[1, 2]] , then evaluate UnitConvert[ans, "Feet"], you'll get 1250/381 ft – theorist Apr 27 '18 at 21:28
• @MarcoB, it's not quite what I want, because I want to be able to extend it to when the user doesn't input the exactly correct name; that's why I want to use interpreter. Note that Interpreter["Quantity"]["meter"] fails. I don't mind what the FullForm output is. I just want `Interpreter["Quantity"]["Unit"] to return unit. However, it fails – Max Coplan Apr 28 '18 at 15:06