From: Claes W. <kl...@ta...> - 2006-06-13 18:29:36
|
Yariv Sadan wrote: > Hi, > > I think there's a bug in the code below, as it will combine all > leading minus signs, e.g. "--3" will be 3 and "---3" will be -3. > > scan_number([]) -> {more, []}; > scan_number(eof) -> {done, {error, incomplete_number}, []}; > scan_number([$- | Ds] = Input) -> > case scan_number(Ds) of > {more, _Cont} -> {more, Input}; > {done, {ok, N}, CharList} -> {done, {ok, -1 * N}, CharList}; > {done, Other, Chars} -> {done, Other, Chars} > end; > scan_number([D | Ds] = Input) when D >= $0, D =< $9 -> > scan_number(Ds, D - $0, Input). > > > I think adding the line > > scan_number([$-, $- | Ds) -> {done, {error, invalid_number}, []}; > > under the second line would fix it. > > I'm new to Erlang, so I might be wrong :) > Looks correct, added - thanks /klacke -- Claes Wikstrom -- Caps lock is nowhere and http://www.tail-f.com -- everything is under control cellphone: +46 70 2097763 |