lua-users home
lua-l archive

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


On Tue, Oct 24, 2006 at 11:57:22AM -0300, Luiz Henrique de Figueiredo wrote:
> > Here's my semi-regular posting about erlang style numbers... this time
> > as an excuse to play with Luiz' token filter. Below is the code to
> > support this interesting (to me at least) extension:
> 
> See, no need for C hacking! :-) And pretty easy to do it in Lua, right?
> (I'm not blowing my own horn here; just remarking that token filters can be
> a better alternative to hacking the Lua core to add more sugar.)

> > -- 2#1001 means base "2" numeric constant "1001" or 9 in decimal

The filters look like a good tool to remove pressure for core
modifications.

Output involves hacking string.format(), or can that be done with a
token filter?

I like the "#" notation. How does Erlang deal with output formatting in
arbitrary bases?

Ruby doesn't support arbitrary bases, just the 3 bases supported by C,
and binary:

literal formatted
  ..    "%d"   decimal, as in C
  0..   "%o"   octal, as in C
  0x..  "%x"   hex, as in C
  0b..  "%b"   binary, not in C

irb(main):001:0> sprintf("%b", 0177)
=> "1111111"
irb(main):002:0> sprintf("%x", 0b10101010)
=> "aa"
irb(main):003:0> sprintf("%o", 0x7f)
=> "177"

There are also the string escapes (\xff, \0377), unfortunately ruby only
allows octal and hex for this.

What does Erlang do?

Sam