lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12/20/18, Lorenzo Donati <lorenzodonatibz@tiscali.it> wrote:
>> Up to a point. In Java, the "thousand separator" can only be used in
>> source code; methods to convert strings to numbers do not accept them.
>> I am not sure this would be a good design for a scripting language like Lua.

why not ? java's solution seems quite simple.

>> Binary literals also pose some design questions:
>> - Of course, 'tonumber', 'io.read("n")', and similar functionality
>> should support that format.

can't this be solved by code similar to that used by the lexer for the
same purpose ?
just ignore the '_' separator in any strings passed to those functions
as is also done there.

the read in characters have to be checked in any case one by one since
they could
contain something illegal, i. e. :
  case '_'  : continue // ignore
  case '0', '1' : // ok, handle char
  default : error ( "got illegal binary literal" ) // illegal content
was detected

>> - Shouldn't Lua have a correspondent format to print binary numbers?
>> (To implement a simple '%b' is quite easy; something that handles
>> '%-#080.3b' is not that easy.)

maybe, but not too important (for my uses).

>> - Should Lua also support floating binary literals?

i personally don't need them, if this turns out to be too much effort
just ignore them.

> I wouldn't care about FP /binary/ literals. Probably FP /hex/ literals
> are enough and Lua wouldn't benefit too much from the former.

indeed.

> Integer binary literals are a different beast, IMO.

right.

> Maybe I'm biased because I'm doing lot of works with microcontrollers lately,

an imporatant use case for binary literals, like octal integer literals are for
unix mode integers.

> and writing down bit-patterns in code using hex is not as clear as using binary,
> especially when dealing with lots of MCU registers.

of course one could do so without hex literals at all just by using
default decimal
integer literals ... :-/

> binary notation would help a lot!

indeed.

> Anyway, I do use Lua for toy programs showing what bits operations do in
> practice, but for this I use my own routines to handle binary representation

that shouldn't be necessary as this is a fairly common every day task,
especially
when working with microcontrollers. i am quite sure this poses no problem at all
for micro python and the various java script implementations used in
the hardware field.