Complexity Shock Horror II: the Sequel (was Re: MD5 in erlang
Raimo Niskanen
raimo.niskanen@REDACTED
Mon Mar 31 14:31:45 CEST 2003
Some comments and some problems. Since Erlang supports the Base#Integer
syntax i think that Base in:
integer_to_list(Integer, Base)
should be 2..16, not atoms.
The same for:
list_to_integer(List, Base)
But what should happen if you call list_to_integer("16#1f", 8), and how
should you specify any base. I guess the answers are: badarg on the
first and list_to_integer("16#1f", undefined) on the second question.
And to add the prefix in the Right(tm) way is a bit awkward:
List = case integer_to_list(Integer, 16) of
[$-|L] -> "-16#"++L;
L -> "16#"++L
end
/ Raimo
Tony Rogvall wrote:
> Raimo Niskanen wrote:
>
>>
>> I am about to add your requested functionality to io_lib:format, so I
>> thought about adding these BIFs too, but it turned out that it was
>> hard to decide what they should do, exactly: Erlang-style prefix or
>> not, lowercase or UPPERCASE or selectable and how to select, how to
>> select any-base for list_to_integer/2, etc.
>>
>> It started to seem that an option list was needed with quite some
>> options, and then they suddenly did seem too complicated to be BIFs.
>>
> Here is one suggestion for R9C
>
> integer_to_list(Integer, Base)
>
> where integer(Integer) and Base = bin | oct | hex or dec
>
> - The prefix is not needed sice it is a constant op to cons "16#" or
> whatever as a prefix.
>
> - The case is not very important for hex numbers since most "readers"
> can read both upper an lower case, correct me I you ever seen any
> software (not your own:-) that care about case in hex numbers! . I vote
> for uppercase, since that what is what I have seen most. If it should be
> a problem then we can add 'heX' as uppercase option.
>
> I wonder how many times I have written integer_to_hex? I am sure it must
> be 100 times...
>
> When we are at it, why not do the same thing for list_to_integer?
> I suggest:
> list_to_integer(List, Base) (base = bin | oct | hex | dec )
>
> possibly allowing base spec in the list_to_integer/1 i.e
> list_to_integer("16#1234")
>
>
> Raimo you can give me a call, I will be glad to help you :-)
>
>> So I hope it will do to use something like
>> lists:flatten(io_lib:format("~16b", [Integer])).
>>
>> If it is necessary for performance reasons, we might add these BIFs
>> later.
>>
>
> Why wait ? I do not think we can talk us out of this one :-)
>
> /Tony
More information about the erlang-questions
mailing list