On Wednesday, January 25, 2012 9:26:57 PM UTC+1, Ian (LastCalc author) wrote:
Yes, that does make sense.
How much does it matter to be limited to, say, binary, octal, decimal, and hex?
Those four are by a very long way the most common, so I say that the best approach would be to include the format for those hard in the syntax in some form (ie like google and many languages before them: "0x.., 0o.., 0b.."). The gain in having additional syntax for representing numbers in arbitrary radix, I think, is very small.
Google relies on the various syntaxes like 0x… and 0o… and others to indicate that a number is in a non-decimal format (as does Java for that matter). I'm wondering if this is the best approach, as opposed to specifying the type more explicitly. There is a tension with LastCalc between what is familiar to programmers, and the desire to keep it accessible to non-programmers. I guess if you're dealing with non-base-10 radices then you're probably a programmer though.
It seems like the best approach internally would be to create a radix "wrapper" class for LargeIntegers, that the various math functions understand how to unwrap and re-wrap (if both a and be are of a particular radix then the result should be the same radix, however if they are different radices then the result should probably be decimal, I think).
I'd say a common pattern for doing this is to parse the values up front before the entered string is evaluated and extract the values into some internal format, forgetting everything about the concrete syntax (like radix etc.) (or perhaps referencing it somehow). This creates a nice separation of the the concrete syntax (the actual characters of the string) from the abstract syntax (the structure of the statement) and the evaluation thereof.
But that is all up to you :)
/Tobias